Cloud Native 6 min read

Understanding Kubernetes Ingress: Concepts, Core Components, and Practical Nginx Examples

This article explains what Kubernetes Ingress is, its core components, how to define Ingress rules with YAML, and provides practical examples using the Nginx Ingress Controller, including TLS support and basic authentication, to help manage traffic routing and load balancing in cloud‑native environments.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Understanding Kubernetes Ingress: Concepts, Core Components, and Practical Nginx Examples

Ingress is a Kubernetes API object that defines how external HTTP/HTTPS traffic is routed to services inside a cluster, acting as an entry point controller based on host, path, and port rules.

Before using Ingress you must have an Ingress Controller (e.g., Nginx, Traefik, HAProxy) installed in the cluster to implement the rules.

The core components of Ingress include the Ingress resource itself and the Ingress Controller that processes the resource.

Example Ingress rule definition (YAML):

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
    - host: app.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

This rule routes traffic for host app.example.com to api-service when the path is /api, and to frontend-service for other paths.

Practical example using Nginx Ingress Controller:

Deploy the controller:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.0/deploy/static/provider/cloud/deploy.yaml

Create an Ingress resource with the annotation kubernetes.io/ingress.class: "nginx":

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: app.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

Apply the manifest with kubectl apply -f ingress.yaml, then access http://app.example.com for the frontend and http://app.example.com/api for the API.

To enable SSL/TLS, add a TLS section and use cert‑manager for certificate issuance:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    cert-manager.io/issuer: "letsencrypt-prod"
spec:
  tls:
    - hosts:
        - app.example.com
      secretName: tls-secret
  rules:
    - host: app.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

For basic authentication, add the annotation nginx.ingress.kubernetes.io/auth-type: basic and reference a secret containing credentials:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/auth-type: basic
    nginx.ingress.kubernetes.io/auth-secret: basic-auth-secret
spec:
  rules:
    - host: app.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend-service
                port:
                  number: 80

In summary, Kubernetes Ingress provides flexible traffic routing and load balancing for applications, improving availability and scalability. Ensure a suitable Ingress Controller is installed before using Ingress.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeAuthenticationYAMLTLS
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.