<p>To start playing with Kubernetes I created a small project where I create a three nodes cluster on my local machine using Vagrant and Vbox:
<a href="https://github.com/sasadangelo/k8s-cluster" rel="nofollow noreferrer">https://github.com/sasadangelo/k8s-cluster</a></p>

<p>Just typing <code>vagrant up</code> my cluster is up and running and I can start to play with it. I got familiar with the main concepts and commands and created a simple "Hello World" application composed by a docker image with an NGINX web server where you can connect via browser and a "Hello World" message appears with the hostname. The hostname helps me to understand which Pod responded to my request.</p>

<p>Here the project:
<a href="https://github.com/sasadangelo/k8s-tutorials/tree/master/hello-k8s" rel="nofollow noreferrer">https://github.com/sasadangelo/k8s-tutorials/tree/master/hello-k8s</a></p>

<p>Currently, I can create a deployment with <code>kubectl create</code> exposing it as a service with <code>kubectl expose</code> and then increase replica with <code>kubect scale</code>. At the moment, I am able to use use NodePort service, so with <code>kubectl describe service</code> I can see on which IP the 5 Pods listen, I connect to them and everything works fine.</p>

<p>My problem is that now I want to load balance the traffic. <strong>I want to connect to a single IP</strong> and as soon as I click on the browser Reload button I want to see that different Pod names appear.</p>

<p>I know that Kubernetes by default offers only NodePort service and if I want a load balancer I need something like an Ingress. I also know that a simple reverse proxy like Ingress Nginx is a good implementation for my needs.</p>

<p>However, I read lot of tutorials but I have hard time understanding how I should configure it to achieve what I need.</p>

<p>Here code I have so far:
<a href="https://github.com/sasadangelo/k8s-cluster/tree/master/ingress" rel="nofollow noreferrer">https://github.com/sasadangelo/k8s-cluster/tree/master/ingress</a></p>

<p>Can anyone help me how to fix Ingress code to achieve what I need?</p>

Salvatore D'angelo
<p>Kube Proxy which is a kubernetes component provides load balancing at L4 layer via iptables load balancing.So with ClusterIP type service itself you get load balancing between pods. But with clusterIP type service you can not access it from outside the cluster i.e from a browser. Nodeport type service provides access to the pods from outside the cluster with load balancing at L4 layer by kube proxy.</p>

<p>LoadBalancer and Ingress provides load balancing and rule based routing at L7 layer if that's what you are looking for.</p>

<p>Looking at your code you have yamls for nginx ingress controller and exposed it as Nodeport. What you need next is to create an ingress resource</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: hello-world.info
    http:
      paths:
      - path: /
        backend:
          serviceName: web
          servicePort: 8080
</code></pre>

<p>Once you create above ingress and you have a ClusterIP type service for your pod with a name web which exposed port 8080, You should be able to access it.</p>

<p>Here is the <a href="https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/" rel="nofollow noreferrer">doc</a> on using nginx ingress for an hello world application on Minikube which you can follow to make ingress work in your setup as well.</p>
