📖 Scenario: You are setting up a simple web application on Kubernetes. You want to allow users to access your app through a friendly web address. To do this, you will create an Ingress resource that directs traffic to your app's service.
🎯 Goal: Build a Kubernetes Ingress resource definition that routes HTTP traffic from the host myapp.example.com to a service named myapp-service on port 80.
📋 What You'll Learn
Create a YAML manifest for an Ingress resource named myapp-ingress in the default namespace.
Set the host to myapp.example.com.
Route all HTTP requests (path /) to the service myapp-service on port 80.
Use the networking.k8s.io/v1 API version.
💡 Why This Matters
🌍 Real World
Ingress resources are used in Kubernetes to manage external access to services inside the cluster. They provide a simple way to route traffic based on hostnames and paths.
💼 Career
Understanding Ingress definitions is essential for Kubernetes administrators and DevOps engineers to expose applications securely and efficiently.
Progress0 / 4 steps
1
Create the basic Ingress resource skeleton
Create a YAML manifest starting with apiVersion: networking.k8s.io/v1, kind: Ingress, and metadata with name: myapp-ingress and namespace: default.
Kubernetes
Hint
Start by defining the API version, kind, and metadata fields for the Ingress resource.
2
Add the Ingress rules with host and path
Add a spec section with rules that define the host as myapp.example.com and a single HTTP path /.
Kubernetes
Hint
Use spec.rules to define the host and HTTP paths. Use pathType: Prefix for the path.
3
Configure the backend service and port
Under the path, add a backend section that points to the service named myapp-service on port 80.
Kubernetes
Hint
Use the backend.service.name and backend.service.port.number fields to specify the target service and port.
4
Display the complete Ingress manifest
Print the full YAML manifest for the Ingress resource named myapp-ingress with the host myapp.example.com routing path / to service myapp-service on port 80.
Kubernetes
Hint
Review the full manifest to ensure all parts are included and correctly indented.
Practice
(1/5)
1. What is the main purpose of a Kubernetes Ingress resource?
easy
A. To route external HTTP(S) traffic to internal services based on rules
B. To store configuration data for pods
C. To manage persistent storage volumes
D. To schedule pods on specific nodes
Solution
Step 1: Understand Ingress role
An Ingress resource defines rules to route external traffic to services inside the cluster.
Step 2: Compare with other resources
ConfigMaps store config, PersistentVolumes manage storage, and scheduling is done by the scheduler, not Ingress.
Final Answer:
To route external HTTP(S) traffic to internal services based on rules -> Option A
Quick Check:
Ingress routes external traffic [OK]
Hint: Ingress routes external traffic to services inside Kubernetes [OK]
Common Mistakes:
Confusing Ingress with ConfigMap or PersistentVolume
Thinking Ingress schedules pods
Assuming Ingress manages storage
2. Which of the following is the correct minimal YAML snippet to define an Ingress that routes /app path to a service named my-service on port 80?
Correct apiVersion for Ingress is networking.k8s.io/v1 and kind is Ingress.
Step 2: Validate backend service and port
apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: example-ingress\nspec:\n rules:\n - http:\n paths:\n - path: /app\n pathType: Prefix\n backend:\n service:\n name: my-service\n port:\n number: 80 uses correct new syntax with service name and port number 80 matching the question.
Final Answer:
YAML with apiVersion networking.k8s.io/v1, kind Ingress, path /app, service my-service, port 80 -> Option B
Quick Check:
Correct Ingress YAML uses networking.k8s.io/v1 and service port number [OK]
Hint: Use networking.k8s.io/v1 and service.port.number for Ingress backend [OK]
Common Mistakes:
Using old apiVersion v1 for Ingress
Using serviceName/servicePort instead of service.name/port.number
Wrong port number in backend
Defining Service instead of Ingress
3. Given this Ingress YAML snippet, what host and path will route traffic to web-service?
C. Using deprecated backend syntax serviceName and servicePort instead of service.name and service.port.number
D. Missing metadata name field
Solution
Step 1: Check backend syntax in Ingress spec
The YAML uses old syntax with serviceName and servicePort which is deprecated in networking.k8s.io/v1.
Step 2: Confirm correct syntax
Correct syntax uses service.name and service.port.number fields under backend.service.
Final Answer:
Using deprecated backend syntax serviceName and servicePort instead of service.name and service.port.number -> Option C
Quick Check:
Use service.name and service.port.number in Ingress backend [OK]
Hint: Use service.name and service.port.number for backend in networking.k8s.io/v1 [OK]
Common Mistakes:
Using old backend syntax causing Ingress controller to ignore rules
Assuming missing host always breaks routing
Confusing apiVersion correctness
Forgetting metadata name
5. You want to expose two services, service-a and service-b, on the same IP but different paths /a and /b. Which Ingress YAML snippet correctly defines this?