Empty ADDRESS kubernetes ingress

Dorin picture Dorin · Jul 25, 2018 · Viewed 37.2k times · Source

I tried configuring ingress on my kubernetes cluster. I followed the documentation to install ingress controller and ran the following commands

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/baremetal/service-nodeport.yaml

After that default-http-backend and nginx-ingress-controller were running:

ingress-nginx   default-http-backend-846b65fb5f-6kwvp      1/1       Running   0          23h       192.168.2.28   node1
ingress-nginx   nginx-ingress-controller-d658896cd-6m76j   1/1       Running   0          6m        192.168.2.31   node1

I tried testing ingress and I deployed the following service:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: echoserver-deploy
spec:
  replicas: 2
  selector:
    matchLabels:
      app: echo
  template:
    metadata:
      labels:
        app: echo
    spec:
      containers:
        - name: my-echo
          image: gcr.io/google_containers/echoserver:1.8
---
apiVersion: v1
kind: Service
metadata:
  name: echoserver-svc
spec:
  selector:
    app: echo
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080

And the following ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: happy-ingress
  annotations:
    INGRESS.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: happy.k8s.io
      http:
        paths:
          - path: /echoserver
            backend:
              serviceName: echoserver-svc
              servicePort: 8080

When I ran the command 'kubectl get ing' I received:

NAME            HOSTS          ADDRESS   PORTS     AGE
happy-ingress   happy.k8s.io             80        14m

I didn't have ADDRESS resolved and I can’t figure out what the problem is because all the pods are running. Can you give me a hint as to what the issue can be?

Thanks

Answer

Shalauddin Ahamad Shuza picture Shalauddin Ahamad Shuza · Mar 19, 2019

You have to enable ingress addons by following command before creating ingress rules. You can also enable it before executing any other command

$ minikube addons enable ingress
ingress was successfully enabled

Wait until the pods are up and running. You can check by executing following command and wait for the similar output

kubectl get pods -n kube-system | grep nginx-ingress-controller

nginx-ingress-controller-5984b97644-jjng2   1/1       Running   2          1h

enter image description here For Deployment you have to specify the containerPort and for Service you have to specify http protocol.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: echoserver-deploy
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-echo
  template:
    metadata:
      labels:
        app: my-echo
    spec:
      containers:
        - name: my-echo
          image: gcr.io/kubernetes-e2e-test-images/echoserver:2.1
          ports:
          - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: echoserver-svc
spec:
  selector:
    app: my-echo
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
    name: http

For ingress rule change the port servicePort from 8080 to 80 the default http port.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: happy-ingress
  annotations:
    INGRESS.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: happy.k8s.io
    http:
      paths:
      - path: /echoserver
        backend:
          serviceName: echoserver-svc
          servicePort: 80

Now apply those files and create your pods, service and ingress rule. Wait few moment, it will take few moments to get ADDRESS for your ingress rule. enter image description here Now you can visit your service using minikube ip address but not by host name yet. For that you have to add the host and respective IP address in /etc/hosts file. So open /etc/hosts file in your favorite editor and add below line where is the actual IP of you minikube

<minikube_ip> happy.k8s.io

Now you access you service using host name. Verify be following command

curl http://happy.k8s.io/echoserver