Kubernetes Commands Flashcards

1
Q

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)

A

gcloud container clusters get-credentials [CLUSTER_NAME] –zone [ZONE_NAME]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

kubectl command that lists all pods in the namespace

A

kubectl get pods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

declarative kubectl deploy command using a manifest file?

A

kubectl apply -f [DEPLOYMENT_FILE]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

imperative kubectl deploy command

A

kubectl run [DEPLOYMENT_NAME]

  • -image
  • -replicas
  • -labels
  • -port
  • -generator (specifies api version)
  • -save-config (saves config for future use)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe the steps create a kubernetes deployment using the GCP console.

A

console.cloud.google.com > Hamburger (top left) > Kubernetes Engine (Compute) > Workloads > Deploy > provide the repo or use an existing container > Deploy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the command for autoscaling a deployment between a minimum and maximum number of pods?

Why would you need to autoscale a deployment?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the command for rolling back a deployment?

A

kubectl rollout undo deployment [deployment_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the commands for a canary style deployment?

A

kubectl apply -f my-app-v2.yaml
kubectl scale deploy/my-app-v2 -replicas=5
kubectl delete -f my-app-v1.yaml

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the command to view the rollout history?

A

kubectl rollout history deployment [deployment_name] –revision=2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the command to rollback to a specific version?

A

kubectl rollout undo deployment [deployment_name] –revision=2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you rollback using the cloud console?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the command to pause a rollout of a deployment?

Why would you need to pause a deployment?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the command to resume a deployment?

A

kubectl rollout resume deployment [deployment_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the command to delete a deployment?

A

kubectl delete deployment [deployment_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Using the gcp console, how do you scale a kubernetes deployment?

A

console.cloud.google.com > Navigation (top left Hamburger) > Kubernetes Engine > Workloads > click a deployment > Actions > Scale > enter a number > click Scale

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

kubectl command for updating a container image?

A

kubectl set image
[deployment_version]/[deployment_name]
[image_name]=[image_name]:[image_version] –record

17
Q

kubectl command for deleting an object

A

kubectl delete [type] [object-name]