0
0
Kubernetesdevops~30 mins

Host-based routing in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Host-based routing with Kubernetes Ingress
📖 Scenario: You are managing a Kubernetes cluster that hosts multiple web applications. You want to route traffic to different services based on the hostname in the URL. This is called host-based routing.For example, requests to app1.example.com should go to the app1-service, and requests to app2.example.com should go to the app2-service.
🎯 Goal: Create a Kubernetes Ingress resource that routes traffic to two different services based on the hostname in the request.
📋 What You'll Learn
Create a basic Ingress resource with host-based rules
Route app1.example.com to app1-service
Route app2.example.com to app2-service
Use path / for both hosts
Use networking.k8s.io/v1 API version
💡 Why This Matters
🌍 Real World
Host-based routing is used in real Kubernetes clusters to serve multiple websites or apps from the same IP address, saving resources and simplifying DNS management.
💼 Career
Understanding Ingress and host-based routing is essential for Kubernetes administrators and DevOps engineers managing multi-tenant or multi-application environments.
Progress0 / 4 steps
1
Create the basic Ingress skeleton
Create a Kubernetes Ingress resource named host-routing-ingress with API version networking.k8s.io/v1 and kind Ingress. Include metadata with the name and an empty spec section.
Kubernetes
Need a hint?

Start with the basic structure of an Ingress resource. Use apiVersion, kind, metadata with name, and an empty spec.

2
Add host-based routing rules
Inside the spec section, add a rules list with two entries. Each entry should have a host field and an empty http section. Use hosts app1.example.com and app2.example.com.
Kubernetes
Need a hint?

Under spec, add rules as a list. Each rule has a host and an http key. Leave http empty for now.

3
Define paths and backend services
For each host in the rules, add an http.paths list with one path. Use path: / and pathType: Prefix. Set the backend.service.name to app1-service for app1.example.com and app2-service for app2.example.com. Use backend.service.port.number: 80.
Kubernetes
Need a hint?

Each http section needs a paths list with one path. The path is / with pathType: Prefix. The backend points to the correct service name and port 80.

4
Display the complete Ingress YAML
Print the complete Ingress YAML manifest to verify the host-based routing configuration.
Kubernetes
Need a hint?

Use a print statement to output the full YAML manifest as a string exactly as defined.