Labs ICT
โญ Pro Login

Ingress

HTTP routing and SSL termination for your cluster

Ingress โ€” HTTP Routing

An Ingress exposes HTTP and HTTPS routes from outside the cluster to Services within the cluster. It provides URL-based routing, SSL termination, and name-based virtual hosting.

Think of Ingress as a smart entry point that routes traffic to the right Service based on the URL.

Ingress Architecture


  Internet
     โ”‚
     โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚  Load Balancer (single IP)              โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚  Ingress Controller (NGINX, Traefik)    โ”‚
  โ”‚                                          โ”‚
  โ”‚  /api/* โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ Service: api-svc        โ”‚
  โ”‚  /web/* โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ Service: web-svc        โ”‚
  โ”‚  blog.example.com โ”€โ”€โ–ถ Service: blog-svc โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  One entry point, multiple Services

Creating an Ingress


apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
    - host: myapp.example.com
      http:
        paths:
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: api-service
                port:
                  number: 80
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend-service
                port:
                  number: 80

ingressClassName โ€” Which Ingress controller handles this rule (NGINX, Traefik, etc.).

rules โ€” Define hostnames and path-based routing.

pathType: Prefix โ€” Matches paths that start with the specified value.

SSL/TLS Termination


apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: tls-ingress
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - myapp.example.com
      secretName: myapp-tls-secret
  rules:
    - host: myapp.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-service
                port:
                  number: 443

The tls section points to a Kubernetes Secret containing your TLS certificate and key. The Ingress controller handles HTTPS on the outside and forwards plain HTTP to your services.

Installing an Ingress Controller

Ingress resources do nothing without an Ingress controller. You must install one:


# Install NGINX Ingress Controller with Helm
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install nginx-ingress ingress-nginx/ingress-nginx

# Check if the controller is running
kubectl get pods -n ingress-nginx

๐Ÿงช Quick Quiz

What is an Ingress in Kubernetes?