我正在尝试将 Envoy 设置为 Java 应用程序的负载均衡器。以下是我要实施的设置。
我按照Envoy 教程获得了一些想法并找到了代码。在那里,他们使用前端特使容器作为单一前端服务,在许多后端容器之间分配流量。但是对于我的工作来说,我不需要这样的前端容器。所以我修改了代码,下面是我创建的文件。
服务特使.yaml
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 80
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: service
domains:
- "*"
routes:
- match:
prefix: "/service"
route:
cluster: local_service
http_filters:
- name: envoy.router
config: {}
clusters:
- name: local_service
connect_timeout: 0.25s
type: strict_dns
lb_policy: round_robin
hosts:
- socket_address:
address: 127.0.0.1
port_value: 9000
admin:
access_log_path: "/dev/null"
address:
socket_address:
address: 0.0.0.0
port_value: 8081
Dockerfile-服务
FROM envoyproxy/envoy-alpine:latest
FROM java:8
ADD gs-actuator-service-0.1.0.jar gs-actuator-service-0.1.0.jar
ADD ./start_service.sh /usr/local/bin/start_service.sh
RUN chmod u+x /usr/local/bin/start_service.sh
ENTRYPOINT /usr/local/bin/start_service.sh
启动服务.sh
#!/bin/sh
java -jar gs-actuator-service-0.1.0.jar &
envoy -c /etc/service-envoy.yaml --service-cluster service${SERVICE_NAME}
码头工人-compose.yml
version: '2'
services:
service1:
build:
context: .
dockerfile: Dockerfile-service
volumes:
- ./service-envoy.yaml:/etc/service-envoy.yaml
networks:
envoymesh:
aliases:
- service1
environment:
- SERVICE_NAME=1
expose:
- "80"
networks:
envoymesh: {}
gs-actuator-service-0.1.0.jar 是包含 Web 服务的 jar 文件。在 localhost 中运行时,可以使用
localhost:9000/prime?number=10
当我跑
sudo docker-compose up --build
它给出了以下输出,最后有一个错误行。
Building service1
Step 1/6 : FROM envoyproxy/envoy-alpine:latest
---> 44b4a2e0acd8
Step 2/6 : FROM java:8
---> d23bdf5b1b1b
Step 3/6 : ADD gs-actuator-service-0.1.0.jar gs-actuator-service-0.1.0.jar
---> fee1f402b547
Step 4/6 : ADD ./start_service.sh /usr/local/bin/start_service.sh
---> 52c2cc17c4dd
Step 5/6 : RUN chmod u+x /usr/local/bin/start_service.sh
---> Running in 95ee0537c3d1
Removing intermediate container 95ee0537c3d1
---> d8e9bdb2f95e
Step 6/6 : ENTRYPOINT /usr/local/bin/start_service.sh
---> Running in 27b20f261c0f
Removing intermediate container 27b20f261c0f
---> 26080be0b5ea
Successfully built 26080be0b5ea
Successfully tagged frontproxy_service1:latest
Recreating frontproxy_service1_1 ...
Recreating frontproxy_service1_1 ... done
Attaching to frontproxy_service1_1
service1_1 | /usr/local/bin/start_service.sh: 3:
/usr/local/bin/start_service.sh: envoy: not found
frontproxy_service1_1 exited with code 127
有人可以指出我在哪里弄错了吗?
谢谢