kubernetes ingress
Below is a clean, working NGINX Ingress demo that routes:
/httpdโ httpd service/nginxโ nginx service
This is a classic interview + lab demo ๐
(Path-based routing)
โ Prerequisites (IMPORTANT)
Ingress Controller must be installed
kubectl create ns ingress-nginx kubectl get pods -n ingress-nginxIf not installed (quick install):
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yamlKubernetes cluster running (minikube / EKS / kubeadm)
๐น Step 1: Deploy HTTPD App
httpd-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-deploy
spec:
replicas: 2
selector:
matchLabels:
app: httpd
template:
metadata:
labels:
app: httpd
spec:
containers:
- name: httpd
image: httpd
ports:
- containerPort: 80
httpd-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: httpd-svc
spec:
selector:
app: httpd
ports:
- port: 80
targetPort: 80
Apply:
kubectl apply -f httpd-deploy.yaml
kubectl apply -f httpd-svc.yaml
๐น Step 2: Deploy NGINX App
nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
nginx-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
selector:
app: nginx
ports:
- port: 80
targetPort: 80
Apply:
kubectl apply -f nginx-deploy.yaml
kubectl apply -f nginx-svc.yaml
๐น Step 3: Create Ingress (Path-Based Routing)
ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /httpd
pathType: Prefix
backend:
service:
name: httpd-svc
port:
number: 80
- path: /nginx
pathType: Prefix
backend:
service:
name: nginx-svc
port:
number: 80
Apply:
kubectl apply -f ingress.yaml
๐น Step 4: Verify
kubectl get ingress
kubectl describe ingress app-ingress
kubectl get svc
kubectl get pods -o wide
kubectl logs -n ingress-nginx deploy/ingress-nginx-controller
๐น Step 5: Access Application
Get Ingress IP
kubectl get ingress
Example:
ADDRESS: 192.168.49.2
Access URLs
http://<INGRESS-IP>/httpd โ Apache HTTPD page
http://<INGRESS-IP>/nginx โ NGINX welcome page
๐ฏ Interview Explanation (Perfect Answer)
Ingress performs L7 routing and routes traffic based on URL paths.
In this demo,/httpdtraffic is routed to the httpd service, and/nginxtraffic is routed to the nginx service using a single LoadBalancer IP.
๐ง Key Learning Summary
| Feature | Explanation |
| Ingress | Layer-7 HTTP routing |
| Controller | NGINX Ingress Controller |
| Routing Type | Path-based |
| Benefit | Single LB, multiple services |
| Rewrite Target | Removes /httpd & /nginx |
๐ Want Next?
Convert this to EKS + AWS ALB Ingress
Add TLS / HTTPS
Add host-based routing


