You want to expose a Deployment named 'nginx' on port 80 using a LoadBalancer service. Which YAML snippet is correct?
This is the correct minimal LoadBalancer Service definition. The apiVersion v1 and kind Service are correct, and setting type: LoadBalancer instructs the cluster to provision a cloud load balancer that forwards traffic to port 80. The selector app: nginx matches the deployment's pods, and since targetPort is omitted, it defaults to port (80) — a trick that keeps the manifest concise and is preferred in CKAD.
Why this answer
Option C is correct because it defines a Service of type LoadBalancer, exposing the 'nginx' Deployment on port 80. The apiVersion v1 is appropriate for a Service, and the selector matches the Deployment's labels. Option B includes an unnecessary explicit targetPort: 80, making it less preferred for the CKAD exam, which expects the most concise correct YAML.
Option A uses NodePort instead of LoadBalancer, and Option D uses an incorrect apiVersion.
Exam trap
The trap here is that candidates may confuse apiVersion apps/v1 with v1, or think that targetPort must be explicitly set. Option B is not the best answer because it includes unnecessary fields; the exam expects the most concise correct YAML.
How to eliminate wrong answers
Option A is wrong because it uses type NodePort instead of LoadBalancer, which does not provision an external load balancer and only exposes the service on a static port on each node. Option B is wrong because it explicitly sets targetPort: 80, which is redundant but not incorrect; however, the question asks for the correct snippet, and C is more concise and standard. Option D is wrong because it uses apiVersion apps/v1, which is for Deployments, not Services; Services must use apiVersion v1.