Ingress - Chapter 14

Among the Service Types the NodePort and LoadBalancer are most often used. In this chapter, we will explore the Ingress API resource, which represents a layer of abstraction deployed in front of the Service API, offering a unified method of managing access to our application from the external world.

Ingress - Chapter 14
  • Explain what Ingress and Ingress Controllers are.
  • Understand when to use Ingress.
  • Access an application from the external world using Ingress.

Using an Ingress resource we can update our application without worrying about its external access, by decoupling the routing rules from the application and centralize the rules management. To allow the inbound connection to reach the cluster Services, Ingress configures a Layer 7 HTTP/HTTPS LoadBalance for Services and provides, TLS (Transport Layer Security), Name-based virtual hosting, Fanout routing and LoadBalancing.

With Ingress users do not connect directly to a Service. They will reach the Ingress endpoint and then the request is forwarded to the desired Service.

Name-Based Virtual Hosting lets you create rules to send users to different Services, by using different URLS's.

Name-Based Virtual Hosting
source: learnings.edx.org

We can also define Fanout Ingress rules, when requests example.com/blue and example.com/green would be forwarded to different Services.

Fanout Ingress
source: learnings.edx.org

The ingress is fulfilled by an Ingress Controller, which is a reverse proxy responsible for traffic routing based on rules defined in the Ingress resource.

An Ingress Controller is an application watching the Master Node's API server for changes in the Ingress resources and updates the Layer 7 Load Balancer accordingly. Kubernetes supports an array of Ingress Controllers.
Minikube ships the Nginx Ingress Controller setup as an add-on. It can easily be enabled by running.:

$ minikube addons enable ingress

We'll deploy the Name-based Ingress Virtual Hosting Ingress rule by applying following configuration

apiVersion: networking.k8s.io/v1 
kind: Ingress
metadata:
  name: virtual-host-ingress
  namespace: default
spec:
  rules:
  - host: blue.example.com
    http:
      paths:
      - backend:
          service:
            name: webserver-blue-svc
            port:
              number: 80
        path: /
        pathType: ImplementationSpecific
  - host: green.example.com
    http:
      paths:
      - backend:
          service:
            name: webserver-green-svc
            port:
              number: 80
        path: /
        pathType: ImplementationSpecific
$ kubectl create -f virtual-host-ingress.yaml
ingress.networking.k8s.io/virtual-host-ingress created

Get your minikube IP and update your host file accordingly and create two entries for blue.example.com and green.example.com

$ minikube ip