web-server. Which command will add the label env=production to this Pod without restarting it?The kubectl label command adds labels to existing resources without restarting them. Option B correctly adds the label env=production to the Pod named web-server.
Option B requires --overwrite only if the label exists, but it's not necessary here. Option B patches the Pod but is more complex. Option B tries to edit with a label selector, which is incorrect.
Labels on the Deployment resource go under metadata.labels. Labels on Pods created by the Deployment go under spec.template.metadata.labels. This ensures selectors match and Pods are labeled correctly.
Option A is only for selectors, not labels. Option A is invalid because containers do not have labels. Option A uses annotations, which are different from labels.
app=frontend to a Pod, but the Service with selector app=frontend does not route traffic to it. What is the most likely cause?For a Service to route traffic to a Pod, the Pod's labels must exactly match the Service's selector labels. Even a small difference causes no matching.
Option C is incorrect because Services dynamically watch labels. Option C is possible but less common if namespaces differ. Option C affects traffic routing but does not prevent selection.
team=devops to all Pods in the namespace production. Which command achieves this in one step?The --all flag selects all Pods in the namespace. Option D correctly adds the label team=devops to all Pods in production.
Option D tries to label Pods that already have the label, which is redundant. Option D misses the --all flag and will fail. Option D uses an invalid flag --selector instead of -l.
Admission controller webhooks can enforce policies like immutability by rejecting updates that change labels on critical resources. This is the best automated approach.
Option A is manual and error-prone. Option A does not prevent label changes on the Deployment itself. Option A misuses annotations, which are not selectors and do not replace labels.