Ingress

Ingress routes external HTTP/HTTPS traffic to Services based on hostnames and paths.

An Ingress is a smart HTTP router at the edge of your cluster. Instead of one LoadBalancer per service, a single Ingress routes many hostnames and URL paths to different Services.

You need an Ingress Controller

The Ingress object is just rules. An Ingress Controller (such as NGINX Ingress or Traefik) actually reads those rules and does the routing. Without a controller running, an Ingress does nothing.

Ingress routing two paths to two Services, each backed by PodsInternetIngresshost/path rules/app/apiService: appService: apiPodsPods
Ingress β†’ Service β†’ Pods: one entry point routes by host and path.

What it can do

  • Route by hostname (e.g. api.example.com) and path (e.g. /app).
  • Terminate TLS/HTTPS using certificates from Secrets.

Example

Example Β· yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: site-ingress
spec:
  rules:
    - host: example.com
      http:
        paths:
          - path: /app
            pathType: Prefix
            backend:
              service:
                name: app
                port:
                  number: 80
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: api
                port:
                  number: 8080

When to use it

  • A team uses an Ingress to route api.example.com to the API service and app.example.com to the frontend service using a single cloud load balancer.
  • An operator configures path-based routing in an Ingress so /api/* goes to the backend service and /* goes to the SPA frontend.
  • A platform team adds TLS termination via an Ingress using a certificate managed by cert-manager, enabling HTTPS without changing the backend service.

More examples

Host-based Ingress routing

Routes two hostnames to separate backend services using a single Ingress resource and one load balancer.

Example Β· yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-ingress
spec:
  rules:
    - host: api.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: api-svc
                port:
                  number: 80
    - host: app.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend-svc
                port:
                  number: 80

Path-based routing

Routes /api/* requests to a backend API service and all other paths to the frontend SPA service on the same host.

Example Β· yaml
spec:
  rules:
    - host: example.com
      http:
        paths:
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: api-svc
                port:
                  number: 8080
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend-svc
                port:
                  number: 80

Ingress with TLS termination

Adds TLS termination at the Ingress by referencing a TLS Secret containing the certificate and private key.

Example Β· yaml
spec:
  tls:
    - hosts:
        - example.com
      secretName: example-com-tls
  rules:
    - host: example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend-svc
                port:
                  number: 80

Discussion

  • Be the first to comment on this lesson.
Ingress β€” Kubernetes | SoundsCode