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.
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: 80This 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.yamlCreate 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: 80Apply 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: 80For 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: 80In 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
