Complete the code to specify the number of replicas in a Kubernetes deployment.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-service
spec:
replicas: [1]
selector:
matchLabels:
app: my-serviceThe replicas field defines how many pod copies run. Setting it to 1 means one pod will run.
Complete the code to define the container image in the pod template.
spec:
template:
metadata:
labels:
app: my-service
spec:
containers:
- name: my-service-container
image: [1]The image field specifies the container image to run. Here, my-service:1.0 is the correct service image.
Fix the error in the deployment selector to correctly match the pod labels.
spec:
selector:
matchLabels:
app: [1]
template:
metadata:
labels:
app: my-serviceThe selector must exactly match the pod template labels. Here, both use app: my-service.
Fill both blanks to define a service that exposes the deployment on port 80 and targets container port 8080.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-service
ports:
- protocol: TCP
port: [1]
targetPort: [2]The service port is the external port (80), and targetPort is the container port (8080) the service forwards to.
Fill all three blanks to create a deployment with 3 replicas, using the image 'my-service:2.0', and label the pods with 'app: my-service'.
apiVersion: apps/v1 kind: Deployment metadata: name: my-service spec: replicas: [1] selector: matchLabels: app: [2] template: metadata: labels: app: [3] spec: containers: - name: my-service-container image: my-service:2.0
The deployment needs 3 replicas, and the selector and pod labels must both be 'app: my-service' to match pods correctly.