Making ingress available at <nodeinternalip>/<serviceendpoint> in kubernetes cluster

11/28/2020

I have 2 node cluster with 1 worker node. I have setup ingress controller as per documentation and then created Deployment, service ( nodeport ) and ingress object. My goal is to make the service accessible using curl -s INTERNAL_IP/Serviceendpoint. What configurations are required to make this happen. This works great on minikube but not on the cluster. Note - service works fine and shows nginx page when accessed using <INTERNALIP>:NODEPORT

Here is sample service and Ingress object definition -

    apiVersion: v1
    kind: Service
    metadata:
      name: nginx-test1
      labels:
        app: nginx-test1
    spec:
      ports:
      - port: 80
        protocol: TCP
        targetPort: 80
      selector:
        app: nginx-test1
      type: NodePort
    ---
    apiVersion: networking.k8s.io/v1beta1
    kind: Ingress
    metadata:
      name: nginx-test1
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - http:
          paths:
          - path: /nginx-test1
            backend:
              serviceName: nginx-test1
              servicePort: 80
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      creationTimestamp: null
      labels:
        app: nginx-test1
      name: nginx-test1
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx-test1
      strategy: {}
      template:
        metadata:
          creationTimestamp: null
          labels:
            app: nginx-test1
        spec:
          containers:
          - image: nginx
            name: nginx-test1
            resources: {}
            ports:
            - containerPort: 80
              protocol: TCP

$kubectl get nodes -o wide
NAME           STATUS   ROLES    AGE   VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION       CONTAINER-RUNTIME
controlplane   Ready    master   50m   v1.19.0   172.17.0.10   <none>        Ubuntu 18.04.4 LTS   4.15.0-111-generic   docker://19.3.6
node01         Ready    <none>   49m   v1.19.0   **172.17.0.11**   <none>        Ubuntu 18.04.4 LTS   4.15.0-111-generic   docker://19.3.6

kubectl get svc
NAME          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes    ClusterIP   10.96.0.1       <none>        443/TCP        51m
nginx-test1   NodePort    10.96.244.119   <none>        80:30844/TCP   3m3s


kubectl describe ing
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Name:             nginx-test1
Namespace:        default
Address:
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /nginx-test1   nginx-test1:80   10.244.1.8:80,10.244.1.9:80)
Annotations:  nginx.ingress.kubernetes.io/rewrite-target: /

**curl -s -v 172.17.0.11/nginx-test1**
***   Trying 172.17.0.11...
* TCP_NODELAY set
* connect to 172.17.0.11 port 80 failed: Connection refused
* Failed to connect to 172.17.0.11 port 80: Connection refused
* Closing connection 0**
-- stackuser
kubernetes
nginx

0 Answers