<pre><code>Base OS : CentOS (1 master 2 minions)
K8S version : 1.9.5 (deployed using KubeSpray)
</code></pre>

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

<p>I have created 2 deployments :</p>

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

<p>I have also created their corresponding services :</p>

<pre><code>kubectl expose deployment nginx --target-port=80 --type=NodePort
kubectl expose deployment echoserver --target-port=8080 --type=NodePort
</code></pre>

<p>My <code>svc</code> are :</p>

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

<p>My NodeIP address is <code>172.16.16.2</code> and I can access both pods using</p>

<pre><code>http://172.16.16.2:31250 &amp;
http://172.16.16.2:32018
</code></pre>

<p>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.</p>

<p>So my Ingress file is :</p>

<pre><code>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
</code></pre>

<p>This yields :</p>

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

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

<pre><code>http://172.16.16.2/echo
http://172.16.16.2/nginx
</code></pre>

<p>Is there something I have missed in my configs ? </p>

<p>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 <a href="https://github.com/ldynia/vagrant-k8s-centos" rel="noreferrer">kubernetes vlab</a>.</p>

<p>First of all make sure that you have ingress controller installed. Currently there are two ingress controller worth trying <a href="https://github.com/kubernetes/ingress-nginx" rel="noreferrer">kubernetes nginx ingress controller</a> and <a href="https://github.com/nginxinc/kubernetes-ingress" rel="noreferrer">nginx kubernetes ingress controller</a> -I installed first one.</p>

<h3>Installation</h3>

<p>Go to <a href="https://kubernetes.github.io/ingress-nginx/deploy/" rel="noreferrer">installation instructions</a> and execute first step </p>

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

<p>Next get IP addresses of cluster nodes.</p>

<pre><code>$ kubectl get nodes -o wide
NAME     STATUS   ROLES    ...   INTERNAL-IP    
master   Ready    master   ...   192.168.121.110
node01   Ready    &lt;none&gt;   ...   192.168.121.111
node02   Ready    &lt;none&gt;   ...   192.168.121.112
</code></pre>

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

<pre><code>$ curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/baremetal/service-nodeport.yaml &gt; 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
</code></pre>

<h3>Verification</h3>

<p>Check that <code>ingress-nginx</code> service was created.</p>

<pre><code>$ 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
</code></pre>

<p>Check that <code>nginx-ingress-controller</code> deployment was created.</p>

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

<p>Check that <code>nginx-ingress</code> pod is running.</p>

<pre><code>$ 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
</code></pre>

<p>Finally, check ingress controller version. <strong>Don't forget to change pod name!</strong></p>

<pre><code>$ 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
-------------------------------------------------------------------------------
</code></pre>

<h2>Testing</h2>

<p>Test that ingress controller is working by executing steps in this <a href="https://medium.com/@Oskarr3/setting-up-ingress-on-minikube-6ae825e98f82" rel="noreferrer">tutorial</a> -of course, you will omit <code>minikube</code> part. </p>

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

<pre><code>$ 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
</code></pre>

<p>And pods that looks like this.</p>

<pre><code>$ 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
</code></pre>

<p>Finally, test that request to <code>myminikube.info</code> propagates via ingress load balancer. </p>

<pre><code>$ 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:
</code></pre>

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

<ul>
<li><a href="https://kubernetes.github.io/ingress-nginx/deploy/" rel="noreferrer">reproducable tutorial</a> </li>
<li><a href="https://linuxhint.com/install-minikube-ubuntu/" rel="noreferrer">installation of minikube on ubuntu</a></li>
<li><a href="https://medium.com/@cashisclay/kubernetes-ingress-82aa960f658e" rel="noreferrer">ingress I</a></li>
<li><a href="https://medium.com/@Oskarr3/setting-up-ingress-on-minikube-6ae825e98f82" rel="noreferrer">ingress II</a></li>
<li><a href="https://github.com/kubernetes/ingress-nginx/issues/1750" rel="noreferrer">digging</a></li>
<li><a href="https://github.com/kubernetes/minikube/tree/master/deploy/addons/ingress" rel="noreferrer">reverse engineering on ingress in kubernetes</a></li>
</ul>
