Ramesh
Ramesh

Reputation: 21

K8: Unable to connect Pod using nginx reverse proxy

I am new to Kubernetes, and I am trying to host an application using Kubernetes in our internal compute service system.

Since our internal compute service doesn't support rewrite-target annotation I have to use the reverse proxy to handle the rewrite.

So, the flow I have is: VIP -> Service -> Pod [Sidecar which has nginx rewrite] -> Pod [Application container]

Here is manifest:

# Source: reportportal/templates/gateway-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: reportportal-gateway-ingress
  labels:     
    heritage: "Helm"
    release: "reportportal"
    chart: reportportal-5.2.1
    app: "reportportal"
spec:
  rules:

  - http:
      paths:
      - path: /
        backend:
          serviceName: reportportal-ui
          servicePort: headless
          

---
# Source: reportportal/templates/ui-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: reportportal-ui
  labels:     
    heritage: "Helm"
    release: "reportportal"
    chart: reportportal-5.2.1
    app: "reportportal"
  annotations:
    service: ui
    infoEndpoint: /info
spec:
  ports:
  - name: headless
    port: 5000
    protocol: TCP
    targetPort: 5000
  selector:
    component: reportportal-ui
  type: ClusterIP
  
  
---
# Source: reportportal/templates/ui-config-map.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: ui-nginx-conf
  labels:
     sdr.appname: reportportal
data:
  nginx.conf: |-
    user  nginx;
    worker_processes  1;

    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;

    events {
        worker_connections  1024;
    }

    http {
        keepalive_timeout  65;

        upstream ui {
            server 127.0.0.1:8080;
        }

        server {
            listen 5000;

            location / {
                #rewrite  /(ui)/?(.*)  /$2;
                proxy_pass         http://ui;
                proxy_redirect     off;
            }
        }
    }

---
# Source: reportportal/templates/ui-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: reportportal-ui
  labels:     
    heritage: "Helm"
    release: "reportportal"
    chart: reportportal-5.2.1
    app: "reportportal"
spec:
  replicas: 1
  selector:
    matchLabels:
      component: reportportal-ui
  template:
    metadata:
      labels:
        component: reportportal-ui
      annotations:
    spec:
      containers:
      - name: uinginx
        image: nginx:alpine
        ports:
        - containerPort: 5000
          protocol: TCP
        volumeMounts:
        - name: nginx-proxy-config
          mountPath: /etc/nginx/nginx.conf
          subPath: nginx.conf
      - name: ui
        image: "reportportal/service-ui:5.2.2"
        env:
          - name: RP_SERVER_PORT
            value: "8080"
        resources:
          requests:
            cpu: 100m
            memory: 64Mi
          limits:
            cpu: 200m
            memory: 128Mi
        readinessProbe:
          httpGet:
            path: "/health"
            port: 8080
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 3
      volumes:
        - name: nginx-proxy-config
          configMap:
            name: ui-nginx-conf
        
      securityContext:
        {}
      serviceAccountName:
      ...

I am using Minikube (in my local machine), when I try to hit the URL, I am getting "404 not found" page.

The issue here is, Service is unable to connect the Pod[Sidecar]!

Can someone please help to fix this issue?

Thanks in advance!

Upvotes: 2

Views: 1840

Answers (1)

Rico
Rico

Reputation: 61661

Tried this šŸ‚ with:

# MacOS
minikube start --driver=docker
kubectl apply -f file-with-all-the-manifests.yaml

and it works great for me šŸ¤·ā€ā™‚ļø.

From a debug pod on the same namespace šŸƒ:

/ # curl reportportal-ui:5000
<!doctype html>
  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta charset="utf-8">
      <title>Report Portal</title>
      <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="shortcut icon" href="favicon.ico"><link href="styles.535fa1.css" rel="stylesheet"><link href="main.535fa1.css" rel="stylesheet"></head>
    <body>
      <div id="app" style="width: 100%; height: 100%"></div>
      <div id="popover-root"></div>
      <div id="modal-root"></div>
      <div id="tooltip-root"></div>
      <div id="notification-root"></div>
      <div id="screen-lock-root"></div>
    <script type="text/javascript" src="polyfills.app.535fa1.js"></script><script type="text/javascript" src="styles.app.535fa1.js"></script><script type="text/javascript" src="main.app.535fa1.js"></script></body>
  </html>
/ #

Also works from the Nginx sidecar container šŸƒ:

/ # curl 127.0.0.1:8080
<!doctype html>
  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta charset="utf-8">
      <title>Report Portal</title>
      <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="shortcut icon" href="favicon.ico"><link href="styles.535fa1.css" rel="stylesheet"><link href="main.535fa1.css" rel="stylesheet"></head>
    <body>
      <div id="app" style="width: 100%; height: 100%"></div>
      <div id="popover-root"></div>
      <div id="modal-root"></div>
      <div id="tooltip-root"></div>
      <div id="notification-root"></div>
      <div id="screen-lock-root"></div>
    <script type="text/javascript" src="polyfills.app.535fa1.js"></script><script type="text/javascript" src="styles.app.535fa1.js"></script><script type="text/javascript" src="main.app.535fa1.js"></script></body>
  </html>
/ #

It's probably networking on whichever environment you are running. Your internal compute system or minikube. See if none of the pods are crashing:

kubectl get pods --all-namespaces

āœŒļø

Upvotes: 1

Related Questions