<p>I have two deployments one for backend and other for frontend both deployed on the Kubernetes cluster.</p>

<p><strong>BackendDeployment.yaml</strong></p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend-deployement
  labels:
    app: backend-kube
spec:
  replicas: 1
  selector:
    matchLabels:
      app: backend-app-kube
  template:
    metadata:
      labels:
        app: backend-app-kube
    spec:
      containers:
        - name: backend-kube-image
          image: fxx/frox-backend-kube
          ports:
            - containerPort: 8111
</code></pre>

<p><strong>BackendService.yaml</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: backend-app-kube-service
spec:
  selector:
    app: backend-app-kube
  ports:
    - protocol: TCP
      port: 8111
      targetPort: 8111
</code></pre>

<p>Backend is getting deployed perfectly </p>

<p><strong>FrontendDeployment.yaml</strong></p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend-deployement
  labels:
    app: frontend-kube
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fronted-app-kube
  template:
    metadata:
      labels:
        app: fronted-app-kube
    spec:
      containers:
        - name: fronted-kube-image
          image: fxx/frox-front-kube
          ports:
            - containerPort: 80
</code></pre>

<p>FrontendService.yaml</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: fronted-app-kube-service
spec:
  selector:
    app: fronted-app-kube
  type: NodePort
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
</code></pre>

<p>Kubernetes documentation suggested 
<em>Now that you have your backend, you can create a frontend that connects to the backend. The frontend connects to the backend worker Pods by using the DNS name given to the backend Service.</em></p>

<blockquote>
  <p><a href="https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/</a></p>
</blockquote>

<p><strong>nginx.conf</strong></p>

<pre><code>server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri /index.html;                 
    }
    location /api {
    proxy_pass http://backend-app-kube-service;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection ‘upgrade’;
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
</code></pre>

<p>Now when i am creating the frontend deployment it gives me error in container construction 
<strong><em>[emerg] 1#1: host not found in upstream</em></strong></p>

<p>Can somebody please give the solution 
How can I make frontend to talk to backend using Nginx</p>

<p>You don't need Nginx to talk to the backend. </p>

<p>Front end can talk to backend directly by using the backend address as <code>http://backend-app-kube-service:8111</code> if they are in the same namespace.</p>

<p>If they are in different namespaces you need to give the FQDN which will be like <code>http://backend-app-kube-service.namespace.svc.cluster.local:8111</code></p>
