Introduction
When working with Kubernetes, exposing your applications to the outside world is an important task. By default, Kubernetes provides services like ClusterIP, NodePort, and LoadBalancer, but they are not always flexible or cost-effective for real-world production systems.
This is where the Ingress Controller in Kubernetes comes into play. It helps you manage external access to your services in a smart and centralized way using routing rules.
In this article, we will understand what an Ingress Controller is, why it is used, and how to configure it step by step with a real example using simple words and practical explanations.
What is Ingress in Kubernetes?
Ingress in Kubernetes is an API object that manages external HTTP and HTTPS access to services inside a cluster.
Instead of exposing multiple services separately, Ingress allows you to define rules for routing traffic to different services based on:
URL paths
Domain names
Hostnames
It acts like a smart router sitting at the entry point of your Kubernetes cluster.
What is an Ingress Controller?
An Ingress Controller is a component that actually implements the rules defined in the Ingress resource.
Important point:
Without an Ingress Controller, Ingress rules will not work.
Popular Ingress Controllers:
NGINX Ingress Controller
Traefik
HAProxy
In this article, we will use NGINX Ingress Controller as it is the most commonly used.
Why Use Ingress Controller in Kubernetes?
Using an Ingress Controller provides several benefits:
Centralized routing for multiple services
Supports domain-based routing
Reduces cloud load balancer costs
Enables SSL/TLS termination
Improves scalability and flexibility
Step 1: Install NGINX Ingress Controller
First, you need to install the NGINX Ingress Controller in your Kubernetes cluster.
Using kubectl:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml
This command installs all required components like:
Controller Pod
Service
Configurations
To verify installation:
kubectl get pods -n ingress-nginx
Step 2: Create a Sample Deployment
Now, create a simple application deployment.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 2
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: nginx
ports:
- containerPort: 80
Apply it:
kubectl apply -f deployment.yaml
Step 3: Create a Service
Expose the deployment using a ClusterIP service.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
Apply it:
kubectl apply -f service.yaml
Step 4: Create an Ingress Resource
Now create an Ingress resource to route traffic.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- host: myapp.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-service
port:
number: 80
Apply it:
kubectl apply -f ingress.yaml
Step 5: Update Hosts File (Local Testing)
For local testing, map your domain to localhost.
Example (Windows hosts file):
127.0.0.1 myapp.local
Now open browser:
http://myapp.local
Step 6: Verify Ingress Controller
Check if ingress is working:
kubectl get ingress
Also check logs:
kubectl logs -n ingress-nginx <pod-name>
How Routing Works in Ingress
When a request comes:
Request hits Ingress Controller
Controller checks rules
Matches hostname/path
Forwards request to correct service
This happens very fast and automatically.
Example: Multiple Services Routing
You can route different paths to different services.
rules:
- host: myapp.local
http:
paths:
- path: /app1
pathType: Prefix
backend:
service:
name: service1
port:
number: 80
- path: /app2
pathType: Prefix
backend:
service:
name: service2
port:
number: 80
Best Practices for Ingress Controller
Use HTTPS with TLS certificates
Use annotations for advanced configuration
Monitor ingress logs
Use proper domain names in production
Limit access using security rules
Common Mistakes to Avoid
Not installing Ingress Controller
Incorrect service name in Ingress
Wrong port configuration
DNS not configured properly
Real-World Use Cases
Hosting multiple microservices under one domain
API gateway for backend services
SSL termination at entry point
Load balancing traffic
Summary
Ingress Controller in Kubernetes is a powerful way to manage external access to your applications. By using a single entry point and routing rules, you can efficiently expose multiple services with better control, scalability, and cost optimization. With tools like NGINX Ingress Controller, configuring ingress becomes simple and production-ready.