Which of the following label selectors will select pods with the label env exactly equal to production?
Equality selectors use = or == to match exact label values.
The selector env=production matches pods where the label env is exactly production. Option A uses set-based syntax but is equivalent; however, the question asks specifically for equality-based selector syntax.
Given the following pods with labels:
pod1: app=web, env=production pod2: app=api, env=staging pod3: app=web, env=staging pod4: app=api, env=production
What pods will be selected by the label selector app in (web, api),env notin (staging)?
Look for pods where app is either web or api and env is not staging.
Pods pod1 and pod4 have app label in (web, api) and env label not in (staging). Pod2 and pod3 have env=staging, so they are excluded.
Which of the following spec.selector.matchLabels configurations is valid for selecting pods with label tier equal to frontend?
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend-deployment
spec:
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: nginx
image: nginx:latestIn matchLabels, keys and values are simple key-value pairs without operators.
The matchLabels field expects a map of key-value pairs. Option C correctly uses tier: frontend. Options B, C, and D use invalid syntax for matchLabels.
You apply this label selector in a kubectl get pods command:
kubectl get pods -l 'env notin production'
What error will you get?
Check the syntax for set-based label selectors in kubectl commands.
The correct syntax for set-based selectors requires parentheses around the values, e.g., env notin (production). Without parentheses, the selector is invalid and causes an error.
You want to select pods that have label app equal to backend and label version either v1 or v2. Which label selector will correctly select these pods?
Use equality for single value and set-based syntax for multiple values.
Option D correctly uses app=backend for exact match and version in (v1,v2) for multiple allowed values. Option D uses invalid double equals. Option D tries to assign two values to the same key, which is invalid. Option D uses set-based syntax for app which is valid but less common; however, the question asks for exact app equal to backend.