[英]nginx: [emerg] host not found in upstream "udagram-users:8080" in /etc/nginx/nginx.conf:11
After deploying to AWS EKS
I get this error部署到
AWS EKS
后出现此错误
Gtihub repo: https://github.com/oussamabouchikhi/udagram-microservices Gtihub 仓库: https://github.com/oussamabouchikhi/udagram-microservices
Steps to reproduce重现步骤
AWS EKS
cluster and node groupsAWS EKS
集群和节点组EKS
cluster with kubectl
kubectl
配置EKS
集群EKS
cluster (secrets first, then other services, then reverserproxy)EKS
集群(首先是 secrets,然后是其他服务,然后是 reverserproxy)kubectl apply -f env-secret.yaml
kubectl apply -f aws-secret.yaml
kubectl apply -f env-configmap.yaml
kubectl apply -f reverseproxy-deployment.yaml
kubectl apply -f reverseproxy-service.yaml
nginx-config nginx 配置
worker_processes 1;
events { worker_connections 1024; }
error_log /dev/stdout debug;
http {
sendfile on;
upstream users {
server udagram-users:8080;
}
upstream feed {
server udagram-feed:8080;
}
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
server {
listen 8080;
location /api/v0/feed {
resolver 8.8.8.8;
proxy_pass http://feed;
}
location /api/v0/users {
resolver 8.8.8.8;
proxy_pass http://users;
}
}
}
docker-compose docker-compose
version: '3'
services:
reverseproxy:
image: oussamabouchikhi/reverseproxy
ports:
- 8080:8080
restart: always
depends_on:
- udagram-users
- udagram-feed
networks:
- example-net
udagram-users:
image: oussamabouchikhi/udagram-api-users
volumes:
- $HOME/.aws:/root/.aws
environment:
POSTGRES_USERNAME: $POSTGRES_USERNAME
POSTGRES_PASSWORD: $POSTGRES_PASSWORD
POSTGRES_DB: $POSTGRES_DB
POSTGRES_HOST: $POSTGRES_HOST
AWS_REGION: $AWS_REGION
AWS_PROFILE: $AWS_PROFILE
AWS_MEDIA_BUCKET: $AWS_BUCKET
JWT_SECRET: $JWT_SECRET
URL: $URL
networks:
- example-net
udagram-feed:
image: oussamabouchikhi/udagram-api-feed
volumes:
- $HOME/.aws:/root/.aws
environment:
POSTGRES_USERNAME: $POSTGRES_USERNAME
POSTGRES_PASSWORD: $POSTGRES_PASSWORD
POSTGRES_DB: $POSTGRES_DB
POSTGRES_HOST: $POSTGRES_HOST
AWS_REGION: $AWS_REGION
AWS_PROFILE: $AWS_PROFILE
AWS_MEDIA_BUCKET: $AWS_BUCKET
JWT_SECRET: $JWT_SECRET
URL: $URL
networks:
- example-net
udagram-frontend:
image: oussamabouchikhi/udagram-frontend
ports:
- '8100:80'
networks:
- example-net
networks:
example-net:
external: true
reverseproxy-deployment反向代理部署
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
service: reverseproxy
name: reverseproxy
spec:
replicas: 1
selector:
matchLabels:
service: reverseproxy
template:
metadata:
labels:
service: reverseproxy
spec:
containers:
- image: oussamabouchikhi/reverseproxy:latest
name: reverseproxy
imagePullPolicy: Always
resources:
requests:
memory: '64Mi'
cpu: '250m'
limits:
memory: '1024Mi'
cpu: '500m'
ports:
- containerPort: 8080
restartPolicy: Always
reverseproxy-service反向代理服务
apiVersion: v1
kind: Service
metadata:
labels:
service: reverseproxy
name: reverseproxy
spec:
ports:
- name: "8080"
port: 8080
targetPort: 8080
selector:
service: reverseproxy
type: LoadBalancer
resolver
in nginx
confignginx
配置中使用resolver
The nginx
resolver
directive is required.需要
nginx
resolver
指令。
Nginx is a multiplexing server (many connections in one OS process), so each call of system resolver will stop processing all connections till the resolver answer is received. Nginx是一个多路复用服务器(一个OS进程中有很多连接),所以系统解析器的每次调用都会停止处理所有连接,直到收到解析器应答。 That's why Nginx implemented its own internal non-blocking resolver.
这就是为什么 Nginx 实现了自己的内部非阻塞解析器。
If your config file has static DNS
names (not generated), and you do not care about track IP changes without nginx reload
, you don't need nginx
's resolver.如果您的配置文件有 static
DNS
名称(未生成),并且您不关心跟踪 IP 没有nginx reload
的更改,则不需要nginx
的解析器。 In this case all DNS
names will be resolved on startup.在这种情况下,所有
DNS
名称都将在启动时解析。 Nginx
's resolver Nginx
的解析器
Nginx
resolver
directive should be used, if you want to resolve domain name in runtime without nginx
reload.如果要在运行时解析域名而无需
nginx
重新加载,则应使用Nginx
resolver
指令。
Eg:例如:
location /my_uri {
resolver kube-dns.kube-system valid=10s;
...
}
location /my_uri {
resolver 127.0.0.1:53 ipv6=off valid=10s;
...
}
Containers you are trying to link may not be on the same.network.您尝试链接的容器可能不在同一个网络上。 You may want to put them all on the same.network.
你可能想把它们都放在同一个网络上。
In your case su.nets are the same, it's ok:在你的情况下 su.nets 是一样的,没关系:
docker-compose
version: '3'
services:
reverseproxy:
...
networks:
- example-net
udagram-users:
...
networks:
- example-net
udagram-feed:
...
networks:
- example-net
udagram-frontend:
...
networks:
- example-net
networks:
example-net:
external: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.