Bird
Raised Fist0
Kubernetesdevops~20 mins

Ingress resource definition in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Ingress Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of kubectl get ingress command
Given this Ingress YAML, what will be the output of kubectl get ingress my-ingress?
Kubernetes
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /app
        pathType: Prefix
        backend:
          service:
            name: app-service
            port:
              number: 80
A
NAME         CLASS    HOSTS         ADDRESS   PORTS   AGE
my-ingress   <none>   example.com   <none>   80      1m
B
NAME         HOSTS         ADDRESS   PORTS   AGE
my-ingress   example.com             80      1m
C
NAME         CLASS    HOSTS         ADDRESS   PORTS   AGE
my-ingress   <none>   example.com             80      1m
D
NAME         CLASS    HOSTS         ADDRESS   PORTS   AGE
my-ingress   <none>   example.com             443     1m
Attempts:
2 left
💡 Hint
Look carefully at the columns shown by kubectl get ingress and the ports defined.
❓ Configuration
intermediate
2:00remaining
Correct Ingress pathType usage
Which Ingress resource snippet correctly uses pathType to match all paths starting with /api?
A
paths:
- path: /api
  pathType: Prefix
  backend:
    service:
      name: api-service
      port:
        number: 8080
B
paths:
- path: /api*
  pathType: Prefix
  backend:
    service:
      name: api-service
      port:
        number: 8080
C
paths:
- path: /api/
  pathType: ImplementationSpecific
  backend:
    service:
      name: api-service
      port:
        number: 8080
D
paths:
- path: /api
  pathType: Exact
  backend:
    service:
      name: api-service
      port:
        number: 8080
Attempts:
2 left
💡 Hint
Prefix matches all paths starting with the given prefix exactly as written.
❓ Troubleshoot
advanced
2:00remaining
Ingress not routing to service
You created this Ingress but requests to http://example.com/app return 404. What is the most likely cause?
Kubernetes
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /app
        pathType: Exact
        backend:
          service:
            name: app-service
            port:
              number: 80
AThe service name app-service is incorrect and does not exist in the cluster.
BThe pathType Exact requires the request path to be exactly /app, but the request URL has a trailing slash or extra path segments.
CThe Ingress resource is missing the ingressClassName field.
DThe Ingress resource must specify the port name instead of port number.
Attempts:
2 left
💡 Hint
Check how pathType Exact matches request paths.
🧠 Conceptual
advanced
2:00remaining
Understanding Ingress TLS configuration
Which statement about TLS configuration in a Kubernetes Ingress resource is correct?
ATLS configuration in Ingress automatically redirects HTTP traffic to HTTPS.
BTLS configuration is optional and ignored if no hosts are specified in the TLS section.
CThe TLS secret must contain only the private key, the certificate is fetched automatically from the cluster.
DThe TLS section specifies the secret name containing the TLS certificate and the hosts it applies to.
Attempts:
2 left
💡 Hint
Think about what the TLS section defines and what it requires.
✅ Best Practice
expert
2:00remaining
Best practice for Ingress resource annotations
Which annotation is recommended to enable automatic HTTPS redirect in NGINX Ingress Controller?
Anginx.ingress.kubernetes.io/ssl-redirect: "true"
Bnginx.ingress.kubernetes.io/force-ssl-redirect: "false"
Ckubernetes.io/ingress.class: "nginx"
Dnginx.ingress.kubernetes.io/use-regex: "true"
Attempts:
2 left
💡 Hint
Look for the annotation that controls SSL redirect behavior.

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

  1. Step 1: Understand Ingress role

    An Ingress resource defines rules to route external traffic to services inside the cluster.
  2. Step 2: Compare with other resources

    ConfigMaps store config, PersistentVolumes manage storage, and scheduling is done by the scheduler, not Ingress.
  3. Final Answer:

    To route external HTTP(S) traffic to internal services based on rules -> Option A
  4. 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?
easy
A. apiVersion: networking.k8s.io/v1\nkind: Service\nmetadata:\n name: example-ingress\nspec:\n selector:\n app: my-service\n ports:\n - protocol: TCP\n port: 80\n targetPort: 80
B. 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
C. apiVersion: v1\nkind: Ingress\nmetadata:\n name: example-ingress\nspec:\n rules:\n - host: example.com\n http:\n paths:\n - path: /app\n backend:\n serviceName: my-service\n servicePort: 80
D. apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: example-ingress\nspec:\n rules:\n - http:\n paths:\n - path: /app\n backend:\n service:\n name: my-service\n port: 8080

Solution

  1. Step 1: Check apiVersion and kind

    Correct apiVersion for Ingress is networking.k8s.io/v1 and kind is Ingress.
  2. 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.
  3. Final Answer:

    YAML with apiVersion networking.k8s.io/v1, kind Ingress, path /app, service my-service, port 80 -> Option B
  4. 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?
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /web
        pathType: Prefix
        backend:
          service:
            name: web-service
            port:
              number: 80
medium
A. Traffic to host example.com and path starting with /web
B. Traffic to any host and path /web
C. Traffic to host example.com and any path
D. Traffic to host example.com and path exactly /web

Solution

  1. Step 1: Identify host and path in rules

    The rule specifies host example.com and path /web with pathType Prefix.
  2. Step 2: Understand pathType Prefix meaning

    Prefix means any path starting with /web will match, not just exactly /web.
  3. Final Answer:

    Traffic to host example.com and path starting with /web -> Option A
  4. Quick Check:

    Host and prefix path routing = Traffic to host example.com and path starting with /web [OK]
Hint: Prefix path matches all paths starting with given string [OK]
Common Mistakes:
  • Assuming path matches exactly instead of prefix
  • Ignoring host field and assuming any host
  • Confusing pathType Prefix with Exact
4. You applied this Ingress YAML but traffic is not routing correctly:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: bad-ingress
spec:
  rules:
  - http:
      paths:
      - path: /app
        pathType: Prefix
        backend:
          serviceName: app-service
          servicePort: 80
What is the likely cause of the problem?
medium
A. Missing host field in rules
B. Incorrect apiVersion for Ingress
C. Using deprecated backend syntax serviceName and servicePort instead of service.name and service.port.number
D. Missing metadata name field

Solution

  1. 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.
  2. Step 2: Confirm correct syntax

    Correct syntax uses service.name and service.port.number fields under backend.service.
  3. Final Answer:

    Using deprecated backend syntax serviceName and servicePort instead of service.name and service.port.number -> Option C
  4. 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?
hard
A. apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: multi-service-ingress\nspec:\n rules:\n - host: example.com\n http:\n paths:\n - path: /a\n pathType: Prefix\n backend:\n service:\n name: service-a\n port:\n number: 80
B. apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: multi-service-ingress\nspec:\n rules:\n - host: example.com\n http:\n paths:\n - path: /a\n backend:\n serviceName: service-a\n servicePort: 80\n - path: /b\n backend:\n serviceName: service-b\n servicePort: 80
C. apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: multi-service-ingress\nspec:\n rules:\n - http:\n paths:\n - path: /a\n pathType: Exact\n backend:\n serviceName: service-a\n servicePort: 80\n - path: /b\n pathType: Exact\n backend:\n serviceName: service-b\n servicePort: 80
D. apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: multi-service-ingress\nspec:\n rules:\n - http:\n paths:\n - path: /a\n pathType: Prefix\n backend:\n service:\n name: service-a\n port:\n number: 80\n - path: /b\n pathType: Prefix\n backend:\n service:\n name: service-b\n port:\n number: 80

Solution

  1. Step 1: Check apiVersion and kind

    All options use correct apiVersion and kind for Ingress.
  2. Step 2: Validate backend syntax and multiple paths

    apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: multi-service-ingress\nspec:\n rules:\n - http:\n paths:\n - path: /a\n pathType: Prefix\n backend:\n service:\n name: service-a\n port:\n number: 80\n - path: /b\n pathType: Prefix\n backend:\n service:\n name: service-b\n port:\n number: 80 correctly uses service.name and service.port.number with two paths under one rule without host, matching the requirement.
  3. Step 3: Compare pathType usage

    Prefix pathType allows routing all requests starting with /a or /b, which is typical for path-based routing.
  4. Final Answer:

    Ingress with two paths /a and /b routing to service-a and service-b using correct backend syntax -> Option D
  5. Quick Check:

    Multiple paths with service.name and port.number = apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: multi-service-ingress\nspec:\n rules:\n - http:\n paths:\n - path: /a\n pathType: Prefix\n backend:\n service:\n name: service-a\n port:\n number: 80\n - path: /b\n pathType: Prefix\n backend:\n service:\n name: service-b\n port:\n number: 80 [OK]
Hint: Use one rule with multiple paths and service.name/port.number [OK]
Common Mistakes:
  • Using deprecated backend syntax serviceName/servicePort
  • Missing one of the paths or services
  • Using pathType Exact which may limit routing
  • Defining only one path instead of two
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