Setting Up Ingress Controllers with Nginx and Traefik in Kubernetes
📖 Scenario: You are managing a Kubernetes cluster for a small company. You want to expose two simple web applications to the internet using Ingress controllers. You will set up both Nginx and Traefik ingress controllers and configure them to route traffic to the right apps.
🎯 Goal: Learn how to deploy Nginx and Traefik ingress controllers in Kubernetes and create ingress resources to route traffic to two web applications.
📋 What You'll Learn
Create Kubernetes namespaces for the apps
Deploy two simple web applications
Install Nginx ingress controller
Install Traefik ingress controller
Create ingress resources for both controllers
Test routing by accessing the apps via ingress
💡 Why This Matters
🌍 Real World
Ingress controllers are used in Kubernetes to manage external access to services inside the cluster. They help route internet traffic to the right app based on domain names or paths.
💼 Career
Knowing how to install and configure ingress controllers like Nginx and Traefik is essential for DevOps engineers and Kubernetes administrators to expose applications securely and efficiently.
Progress0 / 4 steps
1
Create namespaces and deploy web applications
Create two Kubernetes namespaces called app-nginx and app-traefik. Then deploy a simple nginx web server in app-nginx namespace and a simple httpd web server in app-traefik namespace. Use the image nginx:stable for nginx and httpd:latest for httpd. Name the deployments nginx-app and httpd-app respectively.
Kubernetes
Hint
Use kubectl create namespace to make namespaces and kubectl create deployment with --image and -n to deploy apps in namespaces.
2
Install Nginx ingress controller
Install the Nginx ingress controller in the ingress-nginx namespace using the official Kubernetes manifest from https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.9.1/deploy/static/provider/cloud/deploy.yaml. Create the namespace ingress-nginx before applying the manifest.
Kubernetes
Hint
Use kubectl apply -f with the URL to install the Nginx ingress controller after creating its namespace.
3
Install Traefik ingress controller
Install the Traefik ingress controller in the ingress-traefik namespace. First create the namespace ingress-traefik. Then apply the official Traefik manifest from https://raw.githubusercontent.com/traefik/traefik/v2.10/docs/content/reference/dynamic-configuration/kubernetes-crd.yaml and https://raw.githubusercontent.com/traefik/traefik/v2.10/docs/content/reference/static-configuration/kubernetes-deployment.yaml in this order.
Kubernetes
Hint
Create the namespace first, then apply the CRD manifest, then the deployment manifest for Traefik.
4
Create ingress resources and test access
Create an ingress resource named nginx-ingress in the app-nginx namespace that routes host nginx.example.com to the nginx-app service on port 80. Also create an ingress resource named httpd-ingress in the app-traefik namespace that routes host httpd.example.com to the httpd-app service on port 80. Use the correct ingress class annotations: kubernetes.io/ingress.class: nginx for Nginx and kubernetes.io/ingress.class: traefik for Traefik. Finally, print Ingress setup complete to confirm.
Kubernetes
Hint
Use YAML manifests with correct ingress class annotations and apply them with kubectl apply -n <namespace> -f -. Then print the confirmation message.
Practice
(1/5)
1. What is the main role of an Ingress controller like Nginx or Traefik in Kubernetes?
easy
A. To monitor pod resource usage
B. To manage Kubernetes cluster nodes
C. To store container images
D. To route external traffic to internal Kubernetes services
Solution
Step 1: Understand Ingress controller purpose
Ingress controllers manage how external users access services inside the Kubernetes cluster.
Step 2: Identify correct function
Nginx and Traefik route incoming traffic to the right service based on rules.
Final Answer:
To route external traffic to internal Kubernetes services -> Option D
Changing service port without checking actual port
Removing annotations disables routing
Restarting API server does not fix ingress routing
5. You want to expose two services, webapp and api, on the same domain using Traefik ingress. The webapp should respond on / and api on /api. Which Ingress configuration correctly achieves this?
hard
A. Create two Ingresses with same host but no annotations
B. Use one Ingress with two paths: / to webapp and /api to api service, with annotation kubernetes.io/ingress.class: "traefik"
C. Use one Ingress with only /api path to api service, and no path for webapp
D. Create one Ingress with annotation kubernetes.io/ingress.class: "nginx" for Traefik
Solution
Step 1: Understand routing requirements
Both services share the same domain; webapp on root path /, api on /api path.
Step 2: Configure single Ingress with multiple paths and correct annotation
One Ingress resource with two paths and annotation kubernetes.io/ingress.class: "traefik" directs traffic properly.
Final Answer:
Use one Ingress with two paths: / to webapp and /api to api service, with annotation kubernetes.io/ingress.class: "traefik" -> Option B
Quick Check:
Multiple paths in one Ingress with correct class [OK]
Hint: One Ingress, multiple paths, correct ingress.class annotation [OK]
Common Mistakes:
Using wrong ingress.class annotation for Traefik
Creating multiple Ingresses without annotations
Missing path for root service
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.