nginx ingress host app to master ip not working

5/17/2021

Attaching the desctiption below. I need to host the app in 192.168.5.91 which is the master ip of the kubetnet cluster. All these are running in private space. It can be accesed throgh localhost:30239. But i need to acces it via 192.168.5.51 (master.example.com) -added in /etc/hosts

     $kubectl describe service -n ingress-nginx  ingress-nginx
Name:              ingress-nginx-controller
Namespace:         ingress-nginx
Labels:            app.kubernetes.io/component=controller
                   app.kubernetes.io/instance=ingress-nginx
                   app.kubernetes.io/managed-by=Helm
                   app.kubernetes.io/name=ingress-nginx
                   app.kubernetes.io/version=0.46.0
                   helm.sh/chart=ingress-nginx-3.30.0
Annotations:       service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol: true
                   service.beta.kubernetes.io/do-loadbalancer-hostname: master-kmrl.example.com
Selector:          app.kubernetes.io/component=controller,app.kubernetes.io/instance=ingress-nginx,app.kubernetes.io/name=metrodash-ingress
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.98.115.20
IPs:               10.98.115.20
External IPs:      192.168.9.51
Port:              http  80/TCP
TargetPort:        http/TCP
Endpoints:         <none>
Port:              https  443/TCP
TargetPort:        https/TCP
Endpoints:         <none>
Session Affinity:  None
Events:            <none>

Name:              ingress-nginx-controller-admission
Namespace:         ingress-nginx
Labels:            app.kubernetes.io/component=controller
                   app.kubernetes.io/instance=ingress-nginx
                   app.kubernetes.io/managed-by=Helm
                   app.kubernetes.io/name=ingress-nginx
                   app.kubernetes.io/version=0.46.0
                   helm.sh/chart=ingress-nginx-3.30.0
Annotations:       <none>
Selector:          app.kubernetes.io/component=controller,app.kubernetes.io/instance=ingress-nginx,app.kubernetes.io/name=ingress-nginx
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.101.116.78
IPs:               10.101.116.78
Port:              https-webhook  443/TCP
TargetPort:        webhook/TCP
Endpoints:         192.168.79.191:8443
Session Affinity:  None
Events:            <none>

The service files attached here

 $kubectl get service --all-namespaces
NAMESPACE              NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)                      AGE
cert-manager           cert-manager                         ClusterIP      10.97.7.155      <none>         9402/TCP                     2d1h
cert-manager           cert-manager-webhook                 ClusterIP      10.102.27.254    <none>         443/TCP                      2d1h
default                kubernetes                           ClusterIP      10.96.0.1        <none>         443/TCP                      10d
ingress-nginx          ingress-nginx-controller             LoadBalancer   10.104.163.193   192.168.9.51   80:31152/TCP,443:31291/TCP   7m24s
ingress-nginx          ingress-nginx-controller-admission   ClusterIP      10.101.116.78    <none>         443/TCP                      8d
ingress-nginx          metrodash-service                    NodePort       10.107.176.33    <none>         80:30239/TCP                 13m
kube-system            calico-etcd                          ClusterIP      10.96.232.136    <none>         6666/TCP                     10d
kube-system            kube-dns                             ClusterIP      10.96.0.10       <none>         53/UDP,53/TCP,9153/TCP       10d
kubernetes-dashboard   dashboard-metrics-scraper            ClusterIP      10.109.44.9      <none>         8000/TCP                     9d
kubernetes-dashboard   kubernetes-dashboard                 ClusterIP      10.102.146.7     <none>         443/TCP                      9d

The ingress config

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: metrodash-ingress
  namespace: ingress-nginx
  annotations:
    nginx.ingress.kubernetes.io/proxy-send-timeout: '200'
    nginx.ingress.kubernetes.io/proxy-read-timeout: '200'
    nginx.ingress.kubernetes.io/proxy-connect-timeout: '200'
    # cert-manager.io/cluster-issuer: lets-encrypt-stag
spec:
  ingressClassName: nginx
  rules:
    - host: master.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: metrodash-service
                port:
                  number: 8000

Deployment config:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: metrodash-app
  namespace: ingress-nginx
  labels:
    app: metrodash
spec:
    replicas: 2
    selector:
      matchLabels:
         app: metrodash
    template:
      metadata:
        labels:
          app: metrodash
      spec:
        containers:
          - image: metrodash:latest
            name: metrodash
            imagePullPolicy: IfNotPresent
            envFrom:
            - secretRef:
                name: metrodash-secret
            - configMapRef:
                name: metrodash-config
            ports:
              - containerPort: 8000
                name: gunicorn

config map:

apiVersion: v1
kind: ConfigMap
metadata:
  name: metrodash-config
  namespace: ingress-nginx
data:
  DJANGO_ALLOWED_HOSTS: "*"
  STATIC_ENDPOINT_URL: "metrodash.com"
  STATIC_BUCKET_NAME: "metrodashbucket"
  DJANGO_LOGLEVEL: "info"
  DEBUG: "True"
  DATABASE_ENGINE: "postgresql_psycopg2"

Ingress described:

kubectl describe ingress -n ingress-nginx metrodash-ingress
Name:             metrodash-ingress
Namespace:        ingress-nginx
Address:          192.168.9.51
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host                     Path  Backends
  ----                     ----  --------
  master.example.com  
                           /   metrodash-service:8000 (192.168.79.134:8000,192.168.79.135:8000)
Annotations:               nginx.ingress.kubernetes.io/proxy-connect-timeout: 200
                           nginx.ingress.kubernetes.io/proxy-read-timeout: 200
                           nginx.ingress.kubernetes.io/proxy-send-timeout: 200
Events:                    <none>

Single node:

 kubectl get nodes
NAME          STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   10d   v1.21.0
-- Sajanraj
django
kubernetes
nginx-ingress

2 Answers

9/26/2021

The port set for metrodash-service inside ingress ist looking wrong to me.

-- Jamal Allogie
Source: StackOverflow

5/19/2021

check the ingress nginx controller and add host por as in the below format. $ kubectl get pod -n kube-system ingress-nginx-controller-789d9c4dc-5wnc2 -oyaml

[...]
ports:
- containerPort: 80
  hostPort: 80
  name: http
  protocol: TCP
- containerPort: 443
  hostPort: 443
  name: https
  protocol: TCP
- containerPort: 8443
  name: webhook
  protocol: TCP
[...]

To get the access via host ip , remove host FQDN name from the ingress config, leave empty or remove it.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: metrodash-ingress
  namespace: ingress-nginx
  annotations:
    nginx.ingress.kubernetes.io/proxy-send-timeout: '200'
    nginx.ingress.kubernetes.io/proxy-read-timeout: '200'
    nginx.ingress.kubernetes.io/proxy-connect-timeout: '200'
    # cert-manager.io/cluster-issuer: lets-encrypt-stag
spec:
  ingressClassName: nginx
  rules:
    - host: 
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: metrodash-service
                port:
                  number: 8000
-- Sajanraj
Source: StackOverflow