Kubernetes Ingress Tutorial For Beginners

Kubernetes Ingress Tutorial For Beginners

Kubernetes Ingress is a resource to add rules for routing traffic from external sources to the services in the kubernetes cluster.

In this Kubernetes ingress tutorial series, you will learn the concept of ingress resource and ingress controllers used for routing external traffic to Kubernetes deployments. Also, we will cover advanced ingress routing using ISTIO ingress service gateway.

Generally, a custom Nginx or an HAproxy kubernetes deployment will be exposed as a service for proxying external traffic to internal cluster services, where the routing rules will be baked into the pod and added as a configmap. Kubenetes ingress acts in a similar way except the routing rules will be maintained as Kubernetes ingress object. It has a huge advantage of dynamic routing rule configuration without redeploying the proxy pods.

Kubernetes Ingress Tutorial

To get started, you need to understand two key things.

  1. Kubernetes Ingress
  2. Kubernetes Ingress Controller.

Lets have a look at each one these concepts.

Kubernetes Ingress:

Kubernetes Ingress is a native kubernetes resource where you can have rules to route traffic from an external source to service endpoints residing inside the cluster. It requires an ingress controller for routing the rules specified in the ingress object. An ingress object looks like the following.

apiVersion: extensions/v1beta1
kind: Ingress
  name: test-ingress
  namespace: dev
  - host: test.apps.example.com
      - backend:
          serviceName: hello-service
          servicePort: 80

The above declaration means, all calls to test.apps.example.com should hit the service named hello-service residing in the dev namespace.

Key things to understand about ingress object.

  1. You should create ingress rules in the same namespace where you have the services deployed. You cannot route traffic to a service in a different namespace where you don’t have the ingress object.
  2. An ingress object requires an ingress controller for routing traffic.
  3. External traffic will not hit the ingress API, instead, it will hit the ingress controller service

Kubernetes Ingress Controller

Ingress controller is typically a proxy service deployed in the cluster. It is nothing but a kubernetes deployment exposed to a service. Following are the ingress controllers available for kubernetes.

  1. Nginx Ingress Controller (Community & From Nginx Inc)
  2. Traefik
  3. HAproxy
  4. Contour
  5. GKE Ingress Controller

Generally, Nginx is widely used as an ingress controller. Here is how an Nginx ingress controller works.

  1. The nginx.conf file inside the Nginx controller pod is a go template which can talk to Kubernetes ingress API and get the latest values for traffic routing in real time.
  2. The Nginx controller talks to Kubernetes ingress API to check if there is any rule created for traffic routing.
  3. If it finds any ingress rules, it will be applied to the Nginx controller configuration, that is a nginx.conf file inside the pod using the go template.

If you connect to the pod using exec and check the /etc/nginx/nginx.conf file, you can see all the rules specified in the ingress object applied in the conf file.

Here is the architecture diagram which explains the ingress setup on a kubernetes cluster.

kubernetes ingress

In this tutorial series, we will look into all types of ingress solutions supported by Kubernetes.

Here is the list of kubernetes Ingress setup tutorials.

  1. How to Setup Up Ingress on Kubernetes using Nginx Ingress controller.
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like