我很难将Envoy
设置为VueJS App
的前端代理。
我的Python-Flask
后端服务与Envoy
结合使用时效果很好。
也许我在Dockerfile/Docker-Compose
中出错了。作为我的初学者,在node
中添加类似envoy docker-base-image
的内容有些棘手。
我的实际配置出现以下错误:
upstream connect error or disconnect/reset before headers. reset reason: connection failure
非常感谢大家。
文件夹结构
code
|-- envoy
| |-- Dockerfile-frontenvoy
| `-- front-envoy.yaml
|-- docker-compose.yml
`-- frontend
|-- Dockerfile
`-- service-envoy.yaml
ENVOY front-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: backend
domains:
- "*"
routes:
- match:
prefix: "/"
route:
cluster: frontend
http_filters:
- name: envoy.router
config: {}
clusters:
- name: frontend
connect_timeout: 0.25s
type: strict_dns
lb_policy: round_robin
http2_protocol_options: {}
hosts:
- socket_address:
address: frontend
port_value: 80
admin:
access_log_path: "/dev/null"
address:
socket_address:
address: 0.0.0.0
port_value: 8001
docker-compose.yml
version: '3'
services:
front-envoy:
build:
context: ./envoy
dockerfile: Dockerfile-frontenvoy
volumes:
- ./envoy/front-envoy.yaml:/etc/front-envoy.yaml
networks:
- envoymesh
expose:
- "80"
- "8001"
ports:
- "8000:80"
- "8001:8001"
frontend:
container_name: frontend
restart: always
build:
context: ./frontend
dockerfile: Dockerfile
volumes:
- ./frontend:/code
- ./frontend/service-envoy.yaml:/etc/service-envoy.yaml
networks:
envoymesh:
aliases:
- frontend
environment:
- SERVICE_NAME=frontend
expose:
- "80"
networks:
envoymesh: {}
前端Dockerfile
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM envoyproxy/envoy:latest as production-stage
WORKDIR /code
COPY --from=build-stage . .
ADD ./boot.sh /usr/local/bin/boot.sh
RUN chmod u+x /usr/local/bin/boot.sh
ENTRYPOINT /usr/local/bin/boot.sh
前端boot.sh
#!/bin/sh -e
envoy -c /etc/service-envoy.yaml --service-cluster service${SERVICE_NAME}
前线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: frontend
domains:
- "*"
routes:
- match:
prefix: "/"
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: 8080
admin:
access_log_path: "/dev/null"
address:
socket_address:
address: 0.0.0.0
port_value: 8081