📖 Scenario: You are working with a Kubernetes cluster that runs several web applications. You want to control how users from outside the cluster can reach these applications. Kubernetes provides a way to manage this external access using a resource called Ingress.
🎯 Goal: Learn how to create a simple data structure representing services and their ports, add a configuration for an Ingress controller, apply the logic to map external paths to services, and finally display the Ingress rules that manage external access.
📋 What You'll Learn
Create a dictionary called services with exact service names and ports
Add a variable called ingress_controller with the value 'nginx'
Create a dictionary called ingress_rules that maps URL paths to service names using a for loop
Print the ingress_rules dictionary to show how Ingress manages external access
💡 Why This Matters
🌍 Real World
In real Kubernetes clusters, Ingress resources control how users from outside the cluster access internal services. This project models that mapping simply.
💼 Career
Understanding Ingress is key for DevOps roles managing Kubernetes clusters, as it helps configure secure and organized external access to applications.
Progress0 / 4 steps
1
Create the services dictionary
Create a dictionary called services with these exact entries: 'webapp': 80, 'api': 8080, 'auth': 9090.
Kubernetes
Hint
Use curly braces to create a dictionary with keys as service names and values as ports.
2
Add the Ingress controller configuration
Add a variable called ingress_controller and set it to the string 'nginx'.
Kubernetes
Hint
Just assign the string 'nginx' to the variable ingress_controller.
3
Create Ingress rules mapping paths to services
Create a dictionary called ingress_rules that maps these URL paths to service names: '/app' to 'webapp', '/api' to 'api', and '/login' to 'auth'. Use a for loop with variables path and service to build this dictionary from a list of tuples.
Kubernetes
Hint
Create an empty dictionary, then fill it by looping over the list of path-service pairs.
4
Display the Ingress rules
Write a print statement to display the ingress_rules dictionary.
Kubernetes
Hint
Use print(ingress_rules) to show the final mapping.
Practice
(1/5)
1. What is the primary role of an Ingress in Kubernetes?
easy
A. To manage external access to services inside the cluster
B. To store configuration data for pods
C. To schedule pods on nodes
D. To monitor resource usage of containers
Solution
Step 1: Understand Ingress purpose
Ingress is designed to control how external users access services running inside Kubernetes.
Step 2: Compare with other components
Other components like ConfigMaps store data, schedulers place pods, and metrics monitor usage, but Ingress manages external access.
Final Answer:
To manage external access to services inside the cluster -> Option A
Quick Check:
Ingress controls external access = C [OK]
Hint: Ingress controls outside traffic to services [OK]
Common Mistakes:
Confusing Ingress with ConfigMap or Scheduler
Thinking Ingress manages internal pod scheduling
Assuming Ingress monitors resource usage
2. Which of the following is the correct basic syntax to define an Ingress resource in YAML?
Ingress uses apiVersion networking.k8s.io/v1, kind Ingress, and defines rules with host and http paths.
Step 2: Check options for correct fields
apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: example-ingress\nspec:\n rules:\n - host: example.com\n http:\n paths:\n - path: /\n pathType: Prefix\n backend:\n service:\n name: example-service\n port:\n number: 80 matches the correct structure with service name and port under backend. apiVersion: v1\nkind: Service\nmetadata:\n name: example-ingress\nspec:\n selector:\n app: example\n ports:\n - protocol: TCP\n port: 80\n targetPort: 9376 is a Service definition. The other options define a Deployment or incorrectly use a tcp field.
The host field is set to app.example.com, which defines the hostname for routing.
Step 2: Understand routing based on host
Traffic to app.example.com with path prefix /app routes to my-service on port 8080.
Final Answer:
app.example.com -> Option A
Quick Check:
Host in rule = app.example.com [OK]
Hint: Look for host field in Ingress rules [OK]
Common Mistakes:
Confusing service name with hostname
Ignoring the host field and picking path or service name
Choosing partial strings like 'app' instead of full hostname
4. You created an Ingress resource but external traffic is not reaching your service. Which of these is a likely cause?
medium
A. The pod image is missing a label
B. The cluster has no nodes
C. The service port is set to 0
D. The Ingress controller is not installed or running
Solution
Step 1: Check Ingress controller presence
Ingress resources need an Ingress controller to process rules and route traffic. Without it, Ingress does nothing.
Step 2: Evaluate other options
Pod labels or service ports affect internal routing but won't stop Ingress from receiving traffic. No nodes means cluster is down, but question focuses on Ingress.
Final Answer:
The Ingress controller is not installed or running -> Option D
Quick Check:
Ingress needs controller to route traffic = B [OK]
Hint: Ingress needs a controller running to work [OK]
Common Mistakes:
Ignoring the need for an Ingress controller
Blaming pod labels for external access issues
Confusing service port 0 with Ingress failure
5. You want to expose two services, service-a and service-b, on the same domain but different paths using Ingress. Which configuration correctly achieves this?
hard
A. Use a LoadBalancer service type for each service instead of Ingress
B. Create two Ingress resources with the same host example.com, each with one path for service-a and service-b
C. Define one Ingress with rules for host example.com and paths /a routing to service-a, /b routing to service-b
D. Expose service-a and service-b on different ports without Ingress
Solution
Step 1: Understand Ingress path routing
Ingress can route different URL paths on the same host to different services using rules with multiple paths.
Step 2: Compare options for best practice
Define one Ingress with rules for host example.com and paths /a routing to service-a, /b routing to service-b uses one Ingress with multiple paths, which is efficient and standard. Create two Ingress resources with the same host example.com, each with one path for service-a and service-b may cause conflicts. Options C and D avoid Ingress and don't meet the requirement.
Final Answer:
Define one Ingress with rules for host example.com and paths /a and /b routing to respective services -> Option C
Quick Check:
One Ingress, multiple paths = A [OK]
Hint: Use one Ingress with multiple paths for same host [OK]
Common Mistakes:
Creating multiple Ingresses with same host causing conflicts
Using LoadBalancer instead of Ingress for path routing
Exposing services on different ports without hostname routing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.