kubectl - Core Concepts Flashcards

1
Q

List all namespaces

A

kubectl get ns

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

List all pods in all

A

kubectl get po –all-namespaces

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

List all the pods in the particular namespace

A

kubectl get po -n

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

List all the services in the particular namespace

A

kubectl get svc -n

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

List all the pods showing name and namespace with a json path expression

A

kubectl get pods -o=jsonpath=”{.items[*][‘metadata.name’, ‘metadata.namespace’]}”

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

Create an nginx pod in a default namespace and verify the pod running

A
  1. kubectl run nginx –image=nginx –restart=Never

2. kubectl get po

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

Create the same nginx pod with a yaml file

A
  1. kubectl run nginx –image=nginx –restart=Never –dry-run -o yaml > nginx-pod.yaml
  2. kubectl create -f nginx-pod.yaml
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Output the yaml file of nginx pod

A

kubectl get po nginx -o yaml

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

Output yaml of nginx pod without cluster-specific information

A

kubectl get po nginx -o yaml –export

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

Get the complete details of the nginx pod

A

kubectl describe pod nginx

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

Delete the nginx pod

A

kubectl delete po nginx

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

Delete the pod created with example-pod.yaml

A

kubectl delete -f example-pod.yaml

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

Force delete nginx pod

A

kubectl delete po nginx –grace-period=0 –force

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

Create nginx pod version 1.17.4 and expose port 80

A

kubectl run nginx –image=nginx:1.17.4 –restart=Never –port=80

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

Change nginx image to 1.15-alpine and verify

A
  1. kubectl set image pod/nginx nginx=nginx:1.15-alpine

2. kubectl describe po nginx

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

Change nginx pod image to 1.15-alpine but you can’t remember the image name

A

kubectl edit po nginx

17
Q

output just the image version of the nginx pod

A

kubectl get po nginx -o jsonpath=’{.spec.containers[].image}{“\n”}’

18
Q

Create nginx pod and get to the shell

A
  1. kubectl run nginx –image=nginx –restart=Never

2. kubectl exec -it nginx /bin/sh

19
Q

Get the IP address of the nginx pod

A

kubectl get po nginx -o wide

20
Q

Create a busybox pod and run command ls while creating it then check the logs

A
  1. kubectl run busybox –image=busybox –restart=Never – ls

2. kubectl logs busybox

21
Q

The busybox pod crashed, check previous logs

A

kubectl logs busybox -p

22
Q

Create busybox pod with command sleep 3600

A

kubectl run busybox –image=busybox –restart=Never – /bin/sh -c “sleep 3600”

23
Q

Use the busybox pod to check the connection of the busybox pod

A

IP=$(kubectl get po nginx -o=jsonpath=’{.status.podIPs[].ip}’); kubectl exec -it busybox – wget -o- $IP

24
Q

Create a busybox pod and echo message ‘How are you’ and delete it manually

A
  1. kubectl run busybox –image=nginx –restart=Never -it – echo “How are you”
  2. kubectl delete po busybox
25
Q

Create a busybox pod and echo message ‘How are you’ and have it deleted immediately

A

kubectl run busybox –image=nginx –restart=Never -it –rm – echo “How are you”

26
Q

List the nginx pod with custom columns POD_NAME and POD_STATUS

A

kubectl get po -o=custom-columns=”POD_NAME:.metadata.name, POD_STATUS:.status.containerStatuses[].state”

27
Q

List all the pods sorted by name

A

kubectl get pods –sort-by=.metadata.name

28
Q

List all the pods sorted by created timestamp

A

kubectl get pods–sort-by=.metadata.creationTimestamp

29
Q

Create a Pod with three busy box containers with commands “ls; sleep 3600;”, “echo Hello World; sleep 3600;” and “echo this is the third container; sleep 3600”

A
  1. kubectl run busybox –image=busybox –restart=Never —dry-run=client -o yaml – bin/sh -c “sleep 3600; ls” > multi-container.yaml
  2. Edit yaml to add the containers
  3. kubectl create -f multi-container.yaml
30
Q

Check the logs of each container on busybox pod

A

kubectl logs busybox -c busybox1
kubectl logs busybox -c busybox2
kubectl logs busybox -c busybox3

31
Q

Check the previous logs of the second container busybox2

A

kubectl logs busybox -c busybox2 –previous

32
Q

Run command ls in the third container busybox3 of the above pod

A

kubectl exec busybox -c busybox3 – ls

33
Q

Add pod container metrics to file file.log and verify

A
  1. kubectl top pod busybox –container > file.log

2. cat file.log

34
Q

Ensure /var/logs/main.txt exists in container main-container in pod multi-pod

A
  1. kubectl exec -it multi-pod -c main-container – sh

2. cat /var/log/main.txt

35
Q

Run curl localhost from nginx sidecar container

A
  1. kubectl exec -it mult-pod -c sidecar-container – sh
  2. apt-get udpate && apt-get install -y curl
  3. curl localhost
36
Q

Edit label app on nginx1 pod to be v2

A

kubectl label po nginx1 app=v2 –overwrite

37
Q

Delete nginx1, nginx2, and nginx3 pods with one command

A

kubectl delete po nginx{1,2,3}

38
Q

Create an nginx pod with env variable var1=val1

A

kubectl run nginx –image=nginx –restart=Never –env=var1=val1