<p>After deploying to <code>AWS EKS</code> I get this error <br/></p>
<p>Gtihub repo: <a href="https://github.com/oussamabouchikhi/udagram-microservices" rel="nofollow noreferrer">https://github.com/oussamabouchikhi/udagram-microservices</a></p>
<p><br/>Steps to reproduce</p>
<ol>
<li>Create <code>AWS EKS</code> cluster and node groups</li>
<li>Configure <code>EKS</code> cluster with <code>kubectl</code></li>
<li>Deploy to <code>EKS</code> cluster (secrets first, then other services, then reverserproxy)
<br/>. <code>kubectl apply -f env-secret.yaml</code>
<br/>. <code>kubectl apply -f aws-secret.yaml</code>
<br/>. <code>kubectl apply -f env-configmap.yaml</code>
<br/>. ...
<br/>. <code>kubectl apply -f reverseproxy-deployment.yaml</code>
<br/>. <code>kubectl apply -f reverseproxy-service.yaml</code></li>
</ol>
<p><a href="https://i.stack.imgur.com/bQGqF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bQGqF.png" alt="enter image description here" /></a></p>
<p>nginx-config</p>
<pre><code>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;
        }            
    }

}
</code></pre>
<p>docker-compose</p>
<pre><code>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
</code></pre>
<p>reverseproxy-deployment</p>
<pre><code>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

</code></pre>
<p>reverseproxy-service</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    service: reverseproxy
  name: reverseproxy
spec:
  ports:
  - name: &quot;8080&quot;
    port: 8080
    targetPort: 8080
  selector:
    service: reverseproxy
  type: LoadBalancer
</code></pre>

Oussama Bouchikhi
<h1>Use <code>resolver</code> in <code>nginx</code> config</h1>
<p>The <code>nginx</code> <a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#resolver" rel="nofollow noreferrer"><code>resolver</code></a> directive is required.</p>
<p>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. That's why Nginx implemented its own internal non-blocking resolver.</p>
<p>If your config file has static <code>DNS</code> names (not generated), and you do not care about track IP changes without <code>nginx reload</code>, you don't need <code>nginx</code>'s resolver. In this case all <code>DNS</code> names will be resolved on startup.
<code>Nginx</code>'s resolver</p>
<p><code>Nginx</code> <code>resolver</code> directive should be used, if you want to resolve domain name in runtime without <code>nginx</code> reload.</p>
<p>E.g.:</p>
<pre><code>location /my_uri {
  resolver kube-dns.kube-system valid=10s;
  ...
}
</code></pre>
<pre><code>location /my_uri {
  resolver 127.0.0.1:53 ipv6=off valid=10s;
  ...
}
</code></pre>
<h1>Use the same network (not your case, but still worth noting)</h1>
<p>Containers you are trying to link may not be on the same network.
You may want to put them all on the same network.</p>
<p>In your case subnets are the same, it's ok:</p>
<p><code>docker-compose</code></p>
<pre><code>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
</code></pre>
