Why isn't my ingress controller route traffic from my external IP to the service in my cluster?

11/29/2019

I have a cluster on Digital Ocean. 1 master with 2 nodes. I'm using the Nginx Controller with the Digital Ocean Load Balancer. Three Items in my Ingress Service Work fine. The fourth where I use Nginx Doesn't. Does anyone know why?

Here are the configs. I left out the Ingress Services for the 1st through 3rd Deployments that are working. I can add them if needed.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-kubernetes-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: hw1.example.com
    http:
      paths:
      - backend:
          serviceName: hello-kubernetes-first
          servicePort: 80
  - host: hw2.example.com
    http:
      paths:
      - backend:
          serviceName: hello-kubernetes-second
          servicePort: 80
  - host: hw3.example.com
    http:
      paths:
      - backend:
          serviceName: hello-kubernetes-third
          servicePort: 80
  - host: hw4.example.com
    http:
      paths:
      - backend:
          serviceName: hello-kubernetes-fourth
          servicePort: 80
apiVersion: v1
kind: Service
metadata:
  name: hello-kubernetes-fourth
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: hello-kubernetes-fourth
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-kubernetes-fourth
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-kubernetes-fourth
  template:
    metadata:
      labels:
        app: hello-kubernetes-fourth
    spec:
      containers:
      - name: nginx
        image: nginx:1.8
        ports:
        - containerPort: 8080
-- tink3r
kubernetes
kubernetes-ingress

2 Answers

11/29/2019

The deployment configuration is incorrect. update the YAMLs as shown below

apiVersion: v1
kind: Service
metadata:
  name: hello-kubernetes-fourth
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: hello-kubernetes-fourth
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-kubernetes-fourth
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-kubernetes-fourth
  template:
    metadata:
      labels:
        app: hello-kubernetes-fourth
    spec:
      containers:
      - name: nginx
        image: nginx:1.8
        ports:
        - containerPort: 80

get inside nginx pod and verify that you are able to reach the service and getting the response

curl http://hello-kubernetes-fourth

Then you should be able to reach the service from ingress.

-- P Ekambaram
Source: StackOverflow

11/29/2019

First of all ,if you use the nginx image, the container Port should be the one exposed by the Dockerfile of the image. For the nginx image the ContainerPort should be port 80 https://hub.docker.com/layers/nginx/library/nginx/stable/images/sha256-cab8e4374e1e32bac58a8c7ae96c252cadcb1049545ed4bb3e3bfd5d087983b9

Now you should test if the nginx is available by accessing the podip:containerPort from the minikube node:

kubectl get po -o wide
hello-kubernetes-fourth-cb4fb668c-7tkd4   1/1     Running   0      25m  172.17.0.12                               

curl 172.17.0.12

After this, you should modify the ports of the service : targetPort should match the containerPort (80) and port 8080 Now access the Nginx by service URL:

kubectl describe svc hello-kubernetes-fourth

curl ClusterIP:8080

If OK, modify also the servicePort of the ingress to match the Service Port. Don't forget to enable the ingress, as it is disabled by default on minikube:

minikube addons enable ingress
* ingress was successfully enabled

after ingress pod is up, and adding in your host machine the MINIKUBEIP hw4.example.com in your /etc/hosts, you should be able to curl from the host machine:

curl hw4.example.com
-- iliefa
Source: StackOverflow