Bird
Raised Fist0
Kubernetesdevops~10 mins

Ingress controllers (Nginx, Traefik) in Kubernetes - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Ingress controllers (Nginx, Traefik)
User sends HTTP request
↓
Ingress Controller receives request
↓
Match request to Ingress rules
↓
Route request to correct Service
↓
Service forwards to Pod
↓
Pod processes and responds
↓
Response sent back to User
The ingress controller receives user requests, matches them to rules, routes to services, and returns responses.
Execution Sample
Kubernetes
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: example-service
            port:
              number: 80
This Ingress resource routes requests for example.com to example-service on port 80.
Process Table
StepActionIngress ControllerRequest HostMatched RuleService RoutedResponse
1User sends HTTP requestNginx or Traefik listensexample.comCheck rulesNone yetNone
2Ingress Controller receives requestReceives requestexample.comMatches host example.comNone yetNone
3Match path '/'Matches path prefix '/'example.comRule matchedexample-serviceNone
4Route to serviceRoutes request to example-service:80example.comRule matchedexample-serviceNone
5Service forwards to PodPasses request to Podexample.comRule matchedexample-serviceNone
6Pod processes requestNo actionexample.comRule matchedexample-serviceResponse generated
7Response sent backIngress Controller sends responseexample.comRule matchedexample-service200 OK
8EndRequest completeexample.comRule matchedexample-serviceResponse delivered
💡 Request processed and response sent back to user.
Status Tracker
VariableStartAfter Step 2After Step 4After Step 6Final
Request HostNoneexample.comexample.comexample.comexample.com
Matched RuleNoneNoneRule for example.com / matchedRule matchedRule matched
Service RoutedNoneNoneexample-serviceexample-serviceexample-service
ResponseNoneNoneNoneGenerated200 OK
Key Moments - 3 Insights
How does the ingress controller know which service to send the request to?
The ingress controller checks the host and path in the request against the Ingress rules (see execution_table step 3 and 4). It matches the host 'example.com' and path '/' to route to 'example-service'.
What happens if the request host does not match any Ingress rule?
The ingress controller will not find a matching rule and will typically return a 404 error or default backend response. This is why matching rules are important (refer to execution_table step 2 where matching is checked).
Why do we need an ingress controller like Nginx or Traefik?
Ingress controllers act like traffic managers. They listen for incoming requests and route them inside the cluster based on rules. Without them, external access to services is harder to manage (see concept_flow).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does the ingress controller match the request path '/'?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Check the 'Matched Rule' column in execution_table row for step 3.
According to the variable tracker, what is the value of 'Response' after step 6?
AGenerated
B200 OK
CNone
DRule matched
💡 Hint
Look at the 'Response' row under 'After Step 6' in variable_tracker.
If the request host was 'unknown.com', what would happen according to the flow?
ARequest routed to example-service
BPod processes request anyway
CIngress controller returns 404 or default response
DRequest ignored silently
💡 Hint
Refer to key_moments about unmatched hosts and execution_table step 2.
Concept Snapshot
Ingress controllers receive external HTTP requests.
They match requests by host and path to Ingress rules.
Then route requests to the correct Kubernetes Service.
Nginx and Traefik are popular ingress controllers.
They enable easy external access to cluster services.
Without them, managing traffic is complex.
Full Transcript
Ingress controllers like Nginx and Traefik listen for incoming HTTP requests from users. When a request arrives, the controller checks the host and path against defined Ingress rules. If a match is found, it routes the request to the appropriate Kubernetes Service, which then forwards it to the correct Pod. The Pod processes the request and sends a response back through the ingress controller to the user. If no matching rule exists, the ingress controller returns a 404 or default response. This process allows external traffic to reach internal services in a controlled way.

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

  1. Step 1: Understand Ingress controller purpose

    Ingress controllers manage how external users access services inside the Kubernetes cluster.
  2. Step 2: Identify correct function

    Nginx and Traefik route incoming traffic to the right service based on rules.
  3. Final Answer:

    To route external traffic to internal Kubernetes services -> Option D
  4. Quick Check:

    Ingress controller = traffic router [OK]
Hint: Ingress controllers route external traffic inside Kubernetes [OK]
Common Mistakes:
  • Confusing ingress controller with node management
  • Thinking ingress stores images
  • Mixing ingress with monitoring tools
2. Which annotation correctly specifies the use of the Nginx ingress controller in a Kubernetes Ingress resource?
easy
A. kubernetes.io/ingress.class: "nginx"
B. ingress.kubernetes.io/controller: "traefik"
C. kubernetes.io/controller: "nginx"
D. ingress.class: "nginx-controller"

Solution

  1. Step 1: Recall correct annotation key for ingress class

    The standard annotation to specify ingress controller is kubernetes.io/ingress.class.
  2. Step 2: Match correct value for Nginx

    The value for Nginx ingress controller is "nginx".
  3. Final Answer:

    kubernetes.io/ingress.class: "nginx" -> Option A
  4. Quick Check:

    Annotation key = kubernetes.io/ingress.class [OK]
Hint: Use kubernetes.io/ingress.class: "nginx" for Nginx [OK]
Common Mistakes:
  • Using wrong annotation keys
  • Mixing Traefik and Nginx values
  • Omitting quotes around values
3. Given this Ingress YAML snippet using Traefik:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    kubernetes.io/ingress.class: "traefik"
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /app
        pathType: Prefix
        backend:
          service:
            name: app-service
            port:
              number: 80
What happens when a user visits http://example.com/app/page?
medium
A. Traffic goes to default backend ignoring /app path
B. Traffic is blocked because pathType is incorrect
C. Traffic is routed to the app-service on port 80
D. Ingress controller returns 404 error

Solution

  1. Step 1: Analyze ingress rule for host and path

    The rule matches host example.com and path prefix /app, so /app/page matches.
  2. Step 2: Check backend service and port

    Requests matching the path are sent to app-service on port 80.
  3. Final Answer:

    Traffic is routed to the app-service on port 80 -> Option C
  4. Quick Check:

    Path prefix match routes traffic correctly [OK]
Hint: Path prefix routes all subpaths to backend service [OK]
Common Mistakes:
  • Assuming pathType Prefix is invalid
  • Ignoring host match requirement
  • Thinking default backend handles matched paths
4. You deployed an Nginx ingress controller but your Ingress resource is not routing traffic. Which fix is most likely correct?
medium
A. Add annotation kubernetes.io/ingress.class: "nginx" to the Ingress resource
B. Change service port to 8080 in the Ingress backend
C. Remove all annotations from the Ingress resource
D. Restart the Kubernetes API server

Solution

  1. Step 1: Identify cause of routing failure

    Ingress controller routes traffic only to Ingress resources with matching ingress.class annotation.
  2. Step 2: Apply correct annotation for Nginx

    Adding kubernetes.io/ingress.class: "nginx" tells Nginx controller to manage this Ingress.
  3. Final Answer:

    Add annotation kubernetes.io/ingress.class: "nginx" to the Ingress resource -> Option A
  4. Quick Check:

    Ingress class annotation enables controller routing [OK]
Hint: Add ingress.class annotation matching controller [OK]
Common Mistakes:
  • 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

  1. Step 1: Understand routing requirements

    Both services share the same domain; webapp on root path /, api on /api path.
  2. 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.
  3. Final Answer:

    Use one Ingress with two paths: / to webapp and /api to api service, with annotation kubernetes.io/ingress.class: "traefik" -> Option B
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard