Bird
0
0

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📝 Best Practice Q15 of 15
Kubernetes - Ingress
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?
AapiVersion: 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
BapiVersion: 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
CapiVersion: 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
DapiVersion: 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
Step-by-Step Solution
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]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes