📘 Understanding Kubernetes Ingress with Minikube

 By Raees Qazi | DevOps Engineer | Learner | Mentor | Creator

🚀 Introduction

As a DevOps engineer, we often deploy applications in containers using Kubernetes. Normally, we use Deployments to manage Pods and Services to expose these Pods to the outside world.

But let’s say you have multiple applications (like NGINX and Apache) running on your Kubernetes cluster. Do we need a separate service (and potentially a separate IP) for each one?

This is where Ingress comes in — an efficient way to manage and route incoming traffic to the appropriate service based on the URL path or domain.

Press enter or click to view image in full size

🧠 Why Ingress?

Let me explain with a scenario.

You deploy two different apps:

  • One NGINX-based (maybe your frontend)
  • One Apache-based (maybe your static web server)

Without Ingress, you’d need two separate services, and users would need to know which IP/port belongs to which app.

With Ingress, you can route traffic like this:

http://yourdomain.com/nginx  → NGINX app  
http://yourdomain.com/apache → Apache app

Ingress acts as a smart router at the entry point of your cluster.

🔧 Hands-On: Ingress with Minikube

Let’s implement this using Minikube (running on a VM). This demo assumes:

✅ Pre-requisites:

  • 1 VM on AWS with 2 CPU & 4 GB RAM (e.g., t2.medium)
  • Minikube installed and running

🛠️ Steps to Set Up Ingress Routing

1️⃣ Start Minikube

minikube start

2️⃣ Check Cluster Status

minikube status
kubectl get nodes

3️⃣ Create Apache Deployment & Service

apache-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: apache-deployment
spec:
replicas: 1
selector:
matchLabels:
app: apache
template:
metadata:
labels:
app: apache
spec:
containers:
- name: apache
image: httpd:2.4
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: apache-service
spec:
selector:
app: apache
ports:
- port: 80
targetPort: 80
type: ClusterIP
kubectl apply -f apache-deployment.yaml

4️⃣ Create NGINX Deployment & Service

nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- port: 80
targetPort: 80
type: ClusterIP
kubectl apply -f nginx-deployment.yaml

5️⃣ Enable Ingress in Minikube

minikube addons enable ingress

6️⃣ Create Ingress Resource

ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: apache-nginx-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: "tws.com"
http:
paths:
- path: /apache
pathType: Prefix
backend:
service:
name: apache-service
port:
number: 80
- path: /nginx
pathType: Prefix
backend:
service:
name: nginx-service
port:
number: 80
kubectl apply -f ingress.yaml

7️⃣ Map Hostname to Minikube IP

echo "$(minikube ip) tws.com" | sudo tee -a /etc/hosts

Or manually edit your /etc/hosts file and add:

<Minikube_IP>  tws.com

8️⃣ Test Ingress Routing

curl http://tws.com/apache
curl http://tws.com/nginx

Alternatively, you can use port-forwarding for browser access:

kubectl port-forward svc/apache-service 8081:80 --address 0.0.0.0 &
kubectl port-forward svc/nginx-service 8082:80 --address 0.0.0.0 &

Now, access in your browser:

📘 Extra Kubernetes Concepts

Here are a few more helpful Kubernetes terms to know:

🚫 Taints

Used to repel pods from being scheduled on specific nodes. For example, if you taint a node, no pod will run on it unless it has a matching toleration.

✅ Tolerations

Allow specific pods to tolerate taints and run on tainted nodes.

🩺 Probes

Used for health checks:

  • Liveness Probe: Is the app still running?
  • Readiness Probe: Is the app ready to accept traffic?

For example, if your NGINX server returns status code 200, it’s considered healthy.

🎯 Conclusion

Ingress simplifies traffic routing in Kubernetes clusters. Instead of exposing each service separately, you can route based on paths or domains — making your infrastructure cleaner and scalable.

Stay consistent with your Kubernetes practice. If you found this guide helpful, feel free to share it with others.

Happy DevOps-ing!
— Raees Qazi

Comments

Popular posts from this blog

📘 Understanding Prometheus in a Simple Way-Part 3 (For DevOps Beginners)

Grafana Setup & Dashboard Creation (Part-5)— Explained by Raees Yaqoob Qazi

My First Python Program: A Simple Calculator