47
votes

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

8
Any useful info in logs of nginx-ingress-controller pod?Vishal Biyani
Hello, , I found the issue. I was expecting the service to be exported on port 80, but it is exported on 30927. Can I configure this to be exported on port 80?Dorin

8 Answers

38
votes

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
7
votes

As official document say:

Because NodePort Services do not get a LoadBalancerIP assigned by definition, the NGINX Ingress controller does not update the status of Ingress objects it manages

You have deployed the NGINX Ingress controller as described in the installation guide, so it is normal for your ADDRESS was empty!

Instead, the external client must append the NodePort allocated to the ingress-nginx Service to HTTP requests.

ps. This question is not about minikube

5
votes

I don't know if this will help, but i had the same problem. I didn't install no ingress controller or whatever like some people said on Github, i just created an Ingress to be able to point my subdomain to a different service and at first my Ingress had no IP address(it was empty).

NAME      HOSTS                            ADDRESS   PORTS   AGE
ingress   delivereo.tk,back.delivereo.tk             80      39s

I think it was because my 2 services for front-end app and back-end api had the Type of LoadBalancer. I changed it to NodePort because they don't need external ip now that the ingress controller will manage what url goes where.

And when i did change the type of my services to NodePort, after 2 or 3 minutes the IP address of the Ingress appeared. When i pointed my Cloudflare DNS to the new Ingress IP, i tested my subdomain and it worked !

BEFORE

apiVersion: v1
kind: Service
metadata:
  name: delivereotk
spec:
  ports:
    - port: 80
  selector:
    app: delivereotk
  type: LoadBalancer

AFTER

apiVersion: v1
kind: Service
metadata:
  name: delivereotk
spec:
  ports:
    - port: 80
  selector:
    app: delivereotk
  type: NodePort

Ingress

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  rules:
  - host: delivereo.tk
    http:
      paths:
        - backend:
            serviceName: delivereotk
            servicePort: 80
  - host: back.delivereo.tk
    http:
      paths:
        - backend:
            serviceName: backdelivereotk
            servicePort: 80
4
votes

Your hostname happy.k8s.io should resolve to an actual IP address of the nginx-ingress-controller, which points to the front of your load balancer.

You can check under which IP is the cluster working:

bash-3.2$ kubectl cluster-info
Kubernetes master is running at https://192.168.1.100:8443
KubeDNS is running at https://192.168.1.100:8443/api/v1/namespaces/kube- 
system/services/kube-dns:dns/proxy

Test the ingress controller for your cluster using curl

bash-3.2$ curl http://192.168.1.100:8080
default backend - 404

In the end, you should just add the domain entry to /etc/hosts :

192.168.1.100   happy.k8s.io
1
votes

I faced similar issue, realized I needed to :

  1. Enable the NGINX Ingress controller, run the following command:

    minikube addons enable ingress
    
  2. Verify that the NGINX Ingress controller is running

    kubectl get pods -n kube-system
    

Expect nginx-ingress-controller pod in running status.

1
votes

I encountered the same problem on GKE (Google Kubernetes Engine). It turned out there was a problem with ingress settings, I used incorrect names for desired services. You should check for errors by executing this command:

kubectl describe ingress <your-ingress-name>
0
votes

I had a similar case. The ingress we have written is just a ingress rule. To make the address available we need to have ingress controller pods running too.

Simply check if the controller pods is running or not

kubectl get pods

You should have the controller pods running as show in the image. If not you can install it using helm.

enter image description here

if you are using helm2 simply use the following command:

helm install stable/nginx-ingress --name my-nginx

follow this docs for different ways to install it. https://kubernetes.github.io/ingress-nginx/deploy/

When doing helm install you might get the following issue if you don't have tiller installed.

Error: could not find tiller

To fix it install tiller as following:

kubectl -n kube-system create serviceaccount tiller
kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
helm init --service-account tiller

To verify tiller is working:

kubectl get pods --namespace kube-system
0
votes

What you are looking for is a way to test your ingress resource.

You can do this by:

  1. Look for the ip address of the ingress controller pod/s and use port 80/443 along with this ip.
  2. Look for the service which is exposing the ingress controller deployment
  3. If there is no service you can create one and expose the ingress controller deployment
  4. If you want a hostname then you will need to manage the dns entries.