2

I'm trying to set Envoy as a load balancer for a Java application. Following is the setup I'm trying to implement.

enter image description here

I followed Envoy Tutorial to get some idea and found a code. There, they use a front end envoy container as a single front end service, to distribute traffic among many backend containers. But for my work, I do not need such a front end container. So I modified the code and following are the files I created.

service-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-Service

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

start-service.sh

#!/bin/sh

java -jar gs-actuator-service-0.1.0.jar &
envoy -c /etc/service-envoy.yaml --service-cluster service${SERVICE_NAME}

docker-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 is the jar file which contains the web service. When run in localhost, it can be called using

localhost:9000/prime?number=10

When I run

sudo docker-compose up --build

it gives the following output with an error line at the end.

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

Can someone please point out where I'm getting this wrong?

Thank you

Pasindu Tennage
  • 1,480
  • 3
  • 14
  • 31
  • try `/usr/local/bin/envoy -c /etc/service-envoy.yaml --service-cluster service${SERVICE_NAME}` in `start-service.sh` and see if it can find it. – Arian Motamedi Feb 25 '19 at 19:13

1 Answers1

1

Are you on Windows? If you are, check all of your files with Notepad++ and at the bottom right you can change from CR LF to LF. Change it across all files, save it and try to run it again.

Thiago Casa Nova
  • 208
  • 1
  • 4
  • 14