I have four images in docker which are two services, a frontend and a reverseproxy.
When I was using docker-compose up
, it works and the services were running.
But when I want to use kubectl apply -f
to run in pod. There are [emerg] 1#1: host not found in upstream "backend-user:8080" in /etc/nginx/nginx.conf:11 in logs. I have no idea about this.
Here is my images:
bmjlearntocode/reverseproxy latest
bmjlearntocode/udacity-frontend local
bmjlearntocode/udacity-restapi-user latest
bmjlearntocode/udacity-restapi-feed latest
Here is the docker-compose.yaml
version: "3"
services:
reverseproxy:
image: bmjlearntocode/reverseproxy
ports:
- 8080:8080
restart: always
depends_on:
- backend-user
- backend-feed
backend-user:
image: bmjlearntocode/udacity-restapi-user
volumes:
- $HOME/.aws:/root/.aws
environment:
POSTGRESS_USERNAME: $POSTGRESS_USERNAME
POSTGRESS_PASSWORD: $POSTGRESS_PASSWORD
POSTGRESS_DB: $POSTGRESS_DB
POSTGRESS_HOST: $POSTGRESS_HOST
AWS_REGION: $AWS_REGION
AWS_PROFILE: $AWS_PROFILE
AWS_BUCKET: $AWS_BUCKET
JWT_SECRET: $JWT_SECRET
URL: "http://localhost:8100"
backend-feed:
image: bmjlearntocode/udacity-restapi-feed
volumes:
- $HOME/.aws:/root/.aws
environment:
POSTGRESS_USERNAME: $POSTGRESS_USERNAME
POSTGRESS_PASSWORD: $POSTGRESS_PASSWORD
POSTGRESS_DB: $POSTGRESS_DB
POSTGRESS_HOST: $POSTGRESS_HOST
AWS_REGION: $AWS_REGION
AWS_PROFILE: $AWS_PROFILE
AWS_BUCKET: $AWS_BUCKET
JWT_SECRET: $JWT_SECRET
URL: "http://localhost:8100"
frontend:
image: bmjlearntocode/udacity-frontend:local
ports:
- "8100:80"
Here is the nginx.conf
worker_processes 1;
events { worker_connections 1024; }
error_log /dev/stdout debug;
http {
sendfile on;
upstream user {
server backend-user:8080;
}
upstream feed {
server backend-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 {
proxy_pass http://feed;
}
location /api/v0/users {
proxy_pass http://user;
}
}
}
When I use docker-compose up
, it works.
Here is the reverseproxy-deployment.ymal
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
service: reverseproxy
name: reverseproxy
spec:
replicas: 2
template:
metadata:
labels:
service: reverseproxy
spec:
containers:
- image: bmjlearntocode/reverseproxy
name: reverseproxy
imagePullPolicy: Always
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "1024Mi"
cpu: "500m"
ports:
- containerPort: 8080
restartPolicy: Always
I am not sure about why the nginx can not find the 'back-end' when the pod start, but can run in docker-compose up