Skip to main content
This lab demonstrates path-based routing using an NGINX Ingress Controller to expose two applications—video and wear—running in the app-space namespace. You’ll deploy the controller, expose it via a Service, create an Ingress resource with path rules, and troubleshoot a common redirect issue.

Prerequisites

  • A running Kubernetes cluster with kubectl configured to connect to the control plane.
  • video and wear apps already deployed in the app-space namespace (services named video-service and wear-service listening on port 8080).

Quick alias for kubectl

For convenience, alias kubectl to k:
Using an alias like k speeds up interactive work. If you want this alias to persist, add the alias command to your shell profile (e.g. ~/.bashrc or ~/.profile).

Verify application Pods

Confirm the application Pods are running:

Step 1 — Create namespace for the Ingress controller

Create a dedicated namespace for the Ingress controller objects:

Step 2 — Create the NGINX ConfigMap

The controller needs a ConfigMap for configuration settings:

Step 3 — Check RBAC objects for the Ingress controller

Verify the Role and RoleBinding that grant the controller the necessary permissions:
The Role grants permission for configmaps, endpoints, namespaces, pods, and secrets, which the controller needs to operate.

Step 4 — Deploy the Ingress Controller Deployment

The supplied deployment YAML had YAML syntax/typo issues (example of common errors):
This example shows typical YAML pitfalls: incorrect key casing (tempLate), misspelled keys (tabels), and wrong indentation. Such typos cause kubectl to fail with YAML parsing errors. Always validate YAML (e.g., kubectl apply --dry-run=client -f <file>) before creating resources.
Fix the YAML (correct template, metadata, indentation, and include metadata.namespace: ingress-space) and apply it. After creating the corrected Deployment, the Ingress controller Pod should start in ingress-space. If you encountered a parsing error like this when creating the resource:
open and fix the file before retrying.

Step 5 — Expose the Ingress Controller with a Service

Expose the controller so external traffic can reach it. A quick method is kubectl expose:
The controller’s Service picked NodePort 32741. If you need a specific NodePort, edit the Service and set spec.ports[0].nodePort:
Example Service YAML (as seen prior to editing):

Step 6 — Create the Ingress resource to route requests to the apps

Create an Ingress in the app-space namespace that routes:
  • /wear -> wear-service:8080
  • /watch -> video-service:8080
Confirm existing services:
Create the Ingress using kubectl create with rules:
Describe it to verify backend mappings and endpoints:

Step 7 — Verify traffic and troubleshoot redirects

When accessing the Ingress in a browser, you might see a redirect error (ERR_TOO_MANY_REDIRECTS). This commonly occurs when the NGINX Ingress Controller automatically redirects HTTP requests to HTTPS while your Ingress or clients are not configured for TLS, causing a redirect loop. Example browser screenshot showing the error:
A dark Chrome browser error page saying "This page isn't working" and that the site redirected too many times (ERR_TOO_MANY_REDIRECTS). It shows the site URL (labs.kodekloud.com), suggests clearing cookies, and has a Reload button.
Check Pod and application logs to ensure backends are healthy:
Inspect controller logs for redirect responses (HTTP 308 indicates a permanent redirect):
A 308 status means the controller (or an upstream) is issuing a permanent redirect from HTTP to HTTPS. Resolution: disable automatic SSL redirect for this Ingress by adding the annotation nginx.ingress.kubernetes.io/ssl-redirect: "false" (and add a rewrite target if required). Example Ingress YAML with the fix:
Apply the edit:
After disabling SSL redirect, HTTP requests should reach the backend services and the web applications will be accessible through the Ingress paths. Example: /watch should display the application content (the lab demonstrates a live-stream page):
A laptop on a wooden desk displaying a live-stream video of a basketball going through a hoop with "Live Stream" shown on the screen. Papers, a fruit bowl and a glass jar sit nearby on the table.

Summary — Key points and troubleshooting checklist

  • Validate your Ingress Controller Deployment YAML for correct keys (template), spelling and indentation before applying.
  • The NGINX Ingress Controller may enforce SSL redirects by default. If you don’t have TLS configured, set the annotation nginx.ingress.kubernetes.io/ssl-redirect: "false" on the Ingress to prevent HTTP→HTTPS redirect loops.
  • Use kubectl expose to quickly create a Service, then kubectl edit svc to set a specific nodePort if necessary.
  • To troubleshoot routing issues:
    • Verify Services and Endpoints: kubectl get svc -n <ns>, kubectl get endpoints -n <ns>
    • Inspect the Ingress: kubectl describe ingress -n <ns>
    • Check controller logs for redirect/route errors.
    • Check application logs to ensure the app is listening on the expected port.

Quick resource table

This completes the ingress networking lab with path-based routing, controller deployment, service exposure, and a common SSL redirect troubleshooting example.

Watch Video