
Answer-first summary for fast verification
Answer: Update the number of replicas in the YAML file and reapply the configuration: `kubectl apply -f app-deployment.yaml`.
The correct approach is to edit the number of replicas in the YAML file and rerun `kubectl apply -f app-deployment.yaml`. This method ensures that the desired state configuration is updated and preserved in the YAML file. Other methods, such as using `kubectl scale` or `kubectl autoscale`, achieve the same immediate outcome but do not update the YAML file. Consequently, any future `kubectl apply` commands would revert the replica count to the original value specified in the YAML file, which is undesirable. Similarly, using `kubectl edit` modifies the live configuration but does not update the local YAML file, leading to the same issue. References: [Kubernetes Deployment Scaling](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#scaling-a-deployment), [Kubernetes Autoscaling](https://kubernetes.io/blog/2016/07/autoscaling-in-kubernetes/), and [Managing Deployments](https://kubernetes.io/docs/concepts/cluster-administration/manage-deployment/#in-place-updates-of-resources).
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Your team is aiming to use desired state configuration for your application deployed on a GKE cluster. You have YAML files for Kubernetes Deployment and Service objects. The application is designed to run with 2 pods, as specified by the replicas parameter in app-deployment.yaml. The service utilizes a GKE Load Balancer, defined in app-service.yaml. After creating the Kubernetes resources with kubectl apply -f app-deployment.yaml and kubectl apply -f app-service.yaml, the deployment is now live but experiencing performance issues. To address this, you decide to increase the number of replicas to 5. What is the correct approach to update the replicas in the existing Kubernetes deployment objects?
A
Ignore the YAML file and use the kubectl scale command to adjust the replicas to 5: kubectl scale --replicas=5 -f app-deployment.yaml.
B
Ignore the YAML file and enable autoscaling on the deployment based on CPU usage, setting the maximum pods to 5: kubectl autoscale myapp --max=5 --cpu-percent=80.
C
Use kubectl edit to modify the current deployment configuration directly, then save the changes: kubectl edit deployment/app-deployment -o yaml --save-config.
D
Update the number of replicas in the YAML file and reapply the configuration: kubectl apply -f app-deployment.yaml.
No comments yet.