An administrator runs 'kubectl run nginx --image=nginx --port=80' and then 'kubectl expose pod nginx --port=80 --type=NodePort'. Later, they run 'kubectl get svc nginx' and see that the NodePort is set to 0. What is the most likely reason?
Trap 1: The nodePort field was explicitly set to 0 in the service YAML, but…
Correct. If nodePort is set to 0, the service will not get a valid NodePort and will show 0.
Trap 2: The cluster has a mutating webhook that converted the service type…
Incorrect. There is no standard mutating webhook that changes NodePort to ClusterIP. The service type is NodePort, so it should get a port. The issue is more likely due to A or B.
Trap 3: The pod was created by a Deployment, so its labels do not match the…
Incorrect. The pod is created directly by 'kubectl run', so labels match the service selector.
- A
The pod was not ready when the service was created, so NodePort assignment was delayed.
Correct. If the pod is not ready, the service may defer NodePort assignment until the pod is ready, causing the NodePort to appear as 0.
- B
The nodePort field was explicitly set to 0 in the service YAML, but the administrator used a flag that was ignored.
Why it fails: Correct. If nodePort is set to 0, the service will not get a valid NodePort and will show 0.
- C
The cluster has a mutating webhook that converted the service type to ClusterIP because NodePort is disabled.
Why it fails: Incorrect. There is no standard mutating webhook that changes NodePort to ClusterIP. The service type is NodePort, so it should get a port. The issue is more likely due to A or B.
- D
The pod was created by a Deployment, so its labels do not match the service selector.
Why it fails: Incorrect. The pod is created directly by 'kubectl run', so labels match the service selector.