1 - Core Concepts Flashcards

1
Q

Create a namespace called ‘mynamespace’ and a pod with image nginx called nginx on this namespace

A

kubectl create namespace mynamespace
kubectl run nginx –image=nginx –restart=Never -n mynamespace

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

Create the pod that was just described using YAML

A

kubectl run nginx –image=nginx –restart=Never –dry-run=client -n mynamespace -o yaml > pod.yaml

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

Create a busybox pod (using kubectl command) that runs the command “env”. Run it and see the output

A

kubectl run busybox –image=busybox –command –restart=Never -it –rm – env

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

Create a busybox pod (using YAML) that runs the command “env”. Run it and see the output

A

kubectl run busybox –image=busybox –restart=Never –dry-run=client -o yaml –command – env > envpod.yaml

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

Get the YAML for a new namespace called ‘myns’ without creating it

A

kubectl create namespace myns -o yaml –dry-run=client

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

Create the YAML for a new ResourceQuota called ‘myrq’ with hard limits of 1 CPU, 1G memory and 2 pods without creating it

A

kubectl create quota myrq –hard=cpu=1,memory=1G,pods=2 –dry-run=client -o yaml

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

Get pods on all namespaces

A

kubectl get po –all-namespaces

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

Create a pod with image nginx called nginx and expose traffic on port 80

A

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

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

Change pod’s image to nginx:1.7.1. Observe that the container will be restarted as soon as the image gets pulled

A

kubectl set image pod/nginx nginx=nginx:1.7.1
kubectl describe po nginx # you will see an event ‘Container will be killed and recreated’
kubectl get po nginx -w # watch it

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

Get nginx pod’s ip created in previous step, use a temp busybox image to wget its ‘/’

A

kubectl run busybox –image=busybox –rm -it –restart=Never – wget -O- $(kubectl get pod nginx -o jsonpath=’{.status.podIP}:{.spec.containers[0].ports[0].containerPort}’)

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

Get pod’s YAML

A

kubectl get po nginx -o yaml

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

Get information about the pod, including details about potential issues (e.g. pod hasn’t started)

A

kubectl describe po nginx

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

Get pod logs

A

kubectl logs nginx

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

If pod crashed and restarted, get logs about the previous instance

A

kubectl logs nginx -p
# or
kubectl logs nginx –previous

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

Execute a simple shell on the nginx pod

A

kubectl exec -it nginx – /bin/sh

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

Create a busybox pod that echoes ‘hello world’ and then exits

A

kubectl run busybox –image=busybox -it –restart=Never – /bin/sh -c ‘echo hello world’

17
Q

Do the same, but have the pod deleted automatically when it’s completed

A

kubectl run busybox –image=busybox -it –rm –restart=Never – /bin/sh -c ‘echo hello world’

18
Q

Create an nginx pod and set an env value as ‘var1=val1’. Check the env value existence within the pod

A

kubectl run nginx –image nginx –restart=Never –env=var1=val1 -it –rm – sh -c ‘echo $var1’