What does this manifest declare?
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 3
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: myrepo/api:1.4.2
ports:
- containerPort: 8080Options
- Keep 3 Pods of
myrepo/api:1.4.2, tied to labelsapp: api(Correct option) - Run 8080 copies of the app on every node of the cluster
- Create a database named api that has three replicas
- Open port 3 on the node so that the app can be reached
Answer
Keep 3 Pods running from image myrepo/api:1.4.2; the selector ties the Deployment to Pods labeled app: api
Why
A Deployment is a desired-state declaration: "I want 3 replicas of this Pod template".
template describes each Pod (labels and containers). selector.matchLabels tells the Deployment which Pods belong to it, so the labels in template.metadata.labels must match.
If a Pod dies, Kubernetes creates another to keep 3. Changing the image tag triggers a rolling update.
Remember
Deployment = desired replicas + Pod template; labels link them.