Getting an Kubernetes Ingress endpoint/IP address

4/15/2018
Base OS : CentOS (1 master 2 minions)
K8S version : 1.9.5 (deployed using KubeSpray)

I am new to Kubernetes Ingress and am setting up 2 different services, each reachable with its own path.

I have created 2 deployments :

kubectl run nginx --image=nginx --port=80
kubectl run echoserver --image=gcr.io/google_containers/echoserver:1.4 --port=8080

I have also created their corresponding services :

kubectl expose deployment nginx --target-port=80 --type=NodePort
kubectl expose deployment echoserver --target-port=8080 --type=NodePort

My svc are :

[root@node1 kubernetes]# kubectl get svc
NAME         TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
echoserver   NodePort   10.233.48.121   <none>        8080:31250/TCP   47m
nginx        NodePort   10.233.44.54    <none>        80:32018/TCP     1h

My NodeIP address is 172.16.16.2 and I can access both pods using

http://172.16.16.2:31250 &
http://172.16.16.2:32018

Now on top of this I want to deploy an Ingress so that I can reach both pods not using 2 IPs and 2 different ports BUT 1 IP address with different paths.

So my Ingress file is :

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: fanout-nginx-ingress
spec:
  rules:
  - http:
      paths:
      - path: /nginx
        backend:
          serviceName: nginx
          servicePort: 80
      - path: /echo
        backend:
          serviceName: echoserver
          servicePort: 8080

This yields :

[root@node1 kubernetes]# kubectl describe  ing fanout-nginx-ingress
Name:             fanout-nginx-ingress
Namespace:        development
Address:          
Default backend:  default-http-backend:80 (<none>)
Rules:
  Host  Path  Backends
  ----  ----  --------
  *     
        /nginx   nginx:80 (<none>)
        /echo    echoserver:8080 (<none>)
Annotations:
Events:  <none>

Now when I try accessing the Pods using the NodeIP address (172.16.16.2), I get nothing.

http://172.16.16.2/echo
http://172.16.16.2/nginx

Is there something I have missed in my configs ?

--
kubernetes
kubernetes-ingress

3 Answers

12/4/2018

I had the same issue on my bare metal installation - or rather something close to that (kubernetes virtual cluster - set of virtual machines connected via Host-Only-Adapter). Here is link to my kubernetes vlab.

First of all make sure that you have ingress controller installed. Currently there are two ingress controller worth trying kubernetes nginx ingress controller and nginx kubernetes ingress controller -I installed first one.

Installation

Go to installation instructions and execute first step

# prerequisite-generic-deployment-command
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml

Next get IP addresses of cluster nodes.

$ kubectl get nodes -o wide
NAME     STATUS   ROLES    ...   INTERNAL-IP    
master   Ready    master   ...   192.168.121.110
node01   Ready    <none>   ...   192.168.121.111
node02   Ready    <none>   ...   192.168.121.112

Further, crate ingress-nginx service of type LoadBalancer. I do it by downloading NodePort template service from installation tutorial and making following adjustments in svc-ingress-nginx-lb.yaml file.

$ curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/baremetal/service-nodeport.yaml > svc-ingress-nginx-lb.yaml

# my changes svc-ingress-nginx-lb.yaml
type: LoadBalancer
externalIPs:
  - 192.168.121.110
  - 192.168.121.111
  - 192.168.121.112
externalTrafficPolicy: Local

# create ingress- service
$ kubectl apply -f svc-ingress-nginx-lb.yaml

Verification

Check that ingress-nginx service was created.

$ kubectl get svc -n ingress-nginx
NAME            TYPE           CLUSTER-IP     EXTERNAL-IP                                                       PORT(S)                      AGE
ingress-nginx   LoadBalancer   10.110.127.9   192.168.121.110,192.168.121.111,192.168.121.112   80:30284/TCP,443:31684/TCP   70m

Check that nginx-ingress-controller deployment was created.

$ kubectl get deploy -n ingress-nginx
NAME                       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-ingress-controller   1         1         1            1           73m

Check that nginx-ingress pod is running.

$ kubectl get pods --all-namespaces -l 

app.kubernetes.io/name=ingress-nginx
NAMESPACE       NAME                                        READY   STATUS    RESTARTS   AGE
ingress-nginx   nginx-ingress-controller-5cd796c58c-lg6d4   1/1     Running   0          75m

Finally, check ingress controller version. Don't forget to change pod name!

$ kubectl exec -it nginx-ingress-controller-5cd796c58c-lg6d4 -n ingress-nginx -- /nginx-ingress-controller --version
-------------------------------------------------------------------------------
NGINX Ingress controller
  Release:    0.21.0
  Build:      git-b65b85cd9
  Repository: https://github.com/aledbf/ingress-nginx
-------------------------------------------------------------------------------

Testing

Test that ingress controller is working by executing steps in this tutorial -of course, you will omit minikube part.

Successful, execution of all steps will create ingress controler resource that should look like this.

$ kubectl get ing
NAME               HOSTS                                ADDRESS                                          PORTS    AGE
ingress-tutorial   myminikube.info,cheeses.all          192.168.121.110,192.168.121.111,192.168.121.112   80      91m

And pods that looks like this.

$ kubectl get pods 
NAME                              READY   STATUS             RESTARTS   AGE
cheddar-cheese-6f94c9dbfd-cll4z   1/1     Running            0          110m
echoserver-55dcfbf8c6-dwl6s       1/1     Running            0          104m
stilton-cheese-5f6bbdd7dd-8s8bf   1/1     Running            0          110m

Finally, test that request to myminikube.info propagates via ingress load balancer.

$ curl myminikube.info
CLIENT VALUES:
client_address=10.44.0.7
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://myminikube.info:8080/

SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001

HEADERS RECEIVED:
accept=*/*
host=myminikube.info
user-agent=curl/7.29.0
x-forwarded-for=10.32.0.1
x-forwarded-host=myminikube.info
x-forwarded-port=80
x-forwarded-proto=http
x-original-uri=/
x-real-ip=10.32.0.1
x-request-id=b2fb3ee219507bfa12472c7d481d4b72
x-scheme=http
BODY:

It was a long journey to make ingress working on bear metal like environment.Thus, i will include relevant links that helped me along.

-- Lukasz Dynowski
Source: StackOverflow

4/16/2018

It seems that your cluster is missing Ingress controller.

In general, Ingress controller works as follows: 1. search for a certain type of objects (ingress,"nginx") in a cluster 2. parse that object and create configuration section for a specific ingress pod. 3. update that pod object (restart it with updated configuration)

That particular pod is responsible for processing traffic from incoming ports (usually a couple of dedicated ports on nodes) to configured traffic destination in cluster.

You can choose from two supported and maintained controllers - Nginx and GCE

The ingress controller consists of several components that you create during installation. Here is installation part from Nginx Ingress documentation:

curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/namespace.yaml              | kubectl apply -f -
curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/default-backend.yaml        | kubectl apply -f -
curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/configmap.yaml              | kubectl apply -f -
curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/tcp-services-configmap.yaml | kubectl apply -f -
curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/udp-services-configmap.yaml | kubectl apply -f -

If you have RBAC authorization configured in your cluster:

curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/rbac.yaml      | kubectl apply -f -
curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/with-rbac.yaml | kubectl apply -f -

If no RBAC configured:

curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/without-rbac.yaml | kubectl apply -f -

In case you create cluster from scratch:

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

Verify your installation:

kubectl get pods --all-namespaces -l app=ingress-nginx --watch

You should see something like:

NAMESPACE       NAME                                       READY     STATUS    RESTARTS   AGE
ingress-nginx   nginx-ingress-controller-699cdf846-nj2rw   1/1       Running   0          1h

Check available services and their parameters:

kubectl get services --all-namespaces

If you are using custom service provider deployment (minikube, AWS, Azure, GKE), follow Nginx Ingress documentation for installation details.

See official Kubernetes Ingress documentation for details about Ingress.

-- VAS
Source: StackOverflow

4/16/2018

Check if you have an ingress controller in your cluster:

$ kubectl get po --all-namespaces

You should see something like:

kube-system nginx-ingress-controller-gwts0   1/1  Running   0    18d

It's only possible to create an ingress to address services inside the namespace in which the Ingress resides. Cross-namespace ingresses are not implemented for security reasons.

-- Nicola Ben
Source: StackOverflow