Bird
0
0

Which YAML snippet correctly defines a Kubernetes service with a selector for a service mesh?

easy📝 Syntax Q3 of 15
Kubernetes - Networking
Which YAML snippet correctly defines a Kubernetes service with a selector for a service mesh?
AapiVersion: v1\nkind: Pod\nmetadata:\n name: my-service\nspec:\n containers:\n - name: app\n image: my-image
BapiVersion: v1\nkind: Service\nmetadata:\n name: my-service\nspec:\n selector:\n app: my-app\n ports:\n - protocol: TCP\n port: 80\n targetPort: 8080
CapiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: my-service\nspec:\n replicas: 3\n selector:\n matchLabels:\n app: my-app
DapiVersion: v1\nkind: Service\nmetadata:\n name: my-service\nspec:\n ports:\n - protocol: UDP\n port: 80\n targetPort: 8080
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct service YAML

    apiVersion: v1\nkind: Service\nmetadata:\n name: my-service\nspec:\n selector:\n app: my-app\n ports:\n - protocol: TCP\n port: 80\n targetPort: 8080 defines a Service with selector and TCP port, matching typical service mesh setup.
  2. Step 2: Check other options

    apiVersion: v1\nkind: Pod\nmetadata:\n name: my-service\nspec:\n containers:\n - name: app\n image: my-image is a Pod, not a Service. apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: my-service\nspec:\n replicas: 3\n selector:\n matchLabels:\n app: my-app is a Deployment, not a Service. apiVersion: v1\nkind: Service\nmetadata:\n name: my-service\nspec:\n ports:\n - protocol: UDP\n port: 80\n targetPort: 8080 uses UDP, usually not for HTTP services.
  3. Final Answer:

    YAML defining a Service with selector and TCP port -> Option B
  4. Quick Check:

    Service YAML with selector and TCP port = correct [OK]
Quick Trick: Service must have selector and TCP port for mesh traffic [OK]
Common Mistakes:
  • Confusing Pod or Deployment YAML with Service YAML
  • Using UDP instead of TCP for service ports
  • Omitting selector in Service definition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes