Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
How to configure NGINX to proxy API calls to backend deployed on Kubernetes?

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

BackendDeployment.yaml

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

BackendService.yaml

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

Backend is getting deployed perfectly

FrontendDeployment.yaml

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

FrontendService.yaml

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

Kubernetes documentation suggested 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.

https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/

nginx.conf

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;
    }
}

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

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

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You don't need Nginx to talk to the backend.

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

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!