Kubernetes Commands Flashcards
GCloud command to retrieve credentials that provides permissions to execute kubectl commands on a GCP cluster.
(Must be run at least once per cluster, does not need to be called a second time unless you lose credentials from your $HOME/.kube/config directory)
gcloud container clusters get-credentials [CLUSTER_NAME] –zone [ZONE_NAME]
kubectl command that lists all pods in the namespace
kubectl get pods
declarative kubectl deploy command using a manifest file?
kubectl apply -f [DEPLOYMENT_FILE]
imperative kubectl deploy command
kubectl run [DEPLOYMENT_NAME]
- -image
- -replicas
- -labels
- -port
- -generator (specifies api version)
- -save-config (saves config for future use)
Describe the steps create a kubernetes deployment using the GCP console.
console.cloud.google.com > Hamburger (top left) > Kubernetes Engine (Compute) > Workloads > Deploy > provide the repo or use an existing container > Deploy
What is the command for autoscaling a deployment between a minimum and maximum number of pods?
Why would you need to autoscale a deployment?
kubectl autoscale deployment [DEPLOYMENT_NAME]
- -min=5
- -max=15
- -cpu-percent=75
You would want to autoscale a deployment so as not to exceed the bounds of your resources for billing or performance of prod resources.
What is the command for rolling back a deployment?
kubectl rollout undo deployment [deployment_name]
What are the commands for a canary style deployment?
kubectl apply -f my-app-v2.yaml
kubectl scale deploy/my-app-v2 -replicas=5
kubectl delete -f my-app-v1.yaml
What is the command to view the rollout history?
kubectl rollout history deployment [deployment_name] –revision=2
What is the command to rollback to a specific version?
kubectl rollout undo deployment [deployment_name] –revision=2
How do you rollback using the cloud console?
You can’t. The cloud console doesn’t have a direct rollback feature.
You can gcloud authenticate using:
gcloud container clusters get-credentials [CLUSTER_NAME] –zone [ZONE_NAME]
Then use any of the following to rollback:
kubectl rollout undo deployment [deployment_name]
kubectl rollout undo deployment [deployment_name] –revision=2
What is the command to pause a rollout of a deployment?
Why would you need to pause a deployment?
kubectl rollout pause deployment [deployment_name]
A deployment should be paused if you see issues arise and suspect the deployment is linked to those issues being logged in metrics, analytics, or logs.
What is the command to resume a deployment?
kubectl rollout resume deployment [deployment_name]
What is the command to delete a deployment?
kubectl delete deployment [deployment_name]
Using the gcp console, how do you scale a kubernetes deployment?
console.cloud.google.com > Navigation (top left Hamburger) > Kubernetes Engine > Workloads > click a deployment > Actions > Scale > enter a number > click Scale