Kubernetes Architecture Flashcards

1
Q

Assuming you have a Dockerfile in the directory you are working in, what is the command to build a container image named ‘myapp’ with a tag of ‘v1.0’?

A

docker build -t myapp:v1.0 .

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

What is the command to run a docker container in the background (detached)? The container should be called mycontainer and the image is named myapp. Any traffic sent to port 2224 should be forwarded to port 8888 inside the container.

A

sudo docker run -p 2224:8888 —name mycontainer -d myapp

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

What is the command to check out what contexts are available?

A

kubectl config get-contexts

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

Switch to a context called dev.

A

kubectl config use-context dev

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

Use a command to see all the resources you can create.

A

kubectl api-resources

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

Issue the command to see all the namespaces within a cluster

A

kubectl get namespaces

OR

kubectl get ns

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

Describe the default namespace.

A

kubectl describe ns default

OR

kubectl describe namespace default

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

Type out a manifest to create a namespace called test.

A

—-
apiVersion: v1
kind: Namespace
metadata:
name: test

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

Create a new namespace from a file called ns-test.yaml.

A

kubectl create -f ns-test.yaml

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

Create a namspace called dev from the CLI.

A

kubectl create ns dev

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

Write a resource quota manifest. Give it a name of tiny-rq. Give it 1 cpu and 1Gi of memory.

A

—-
apiVersion: v1
kind: ResourceQuota
metadata:
name: tiny-rq
spec:
hard:
cpu: “1”
memory: 1Gi

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

Create a resource quota from a manifest called rq-tiny.yaml in the test namespace

A

kubectl apply -f rq-tiny.yaml -n test

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

Delete a resource quota named rq-tiny from the test namespace

A

kubectl delete resourcequota rq-tiny -n test

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

Show al the pods in the current namespace and sort them by restart count.

A

kubectl get pods —sort-by=’.status.containerStatuses[0].restartCount’

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

Show all the services in the current namespace and sort them by name.

A

kubectl get services —sort-by=.metadata.name

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

Show all the pods across all the namespces and show extra details.

A

kubectl get pods —all-namespaces -o wide

17
Q

Show everything except secrets across all namespaces.

A

kubectl get all -A

18
Q

Create a port-forward to a pod called nginx from port 2224 to port 80 in the pod.

A

kubectl port-forward nginx 2224:80

19
Q

Write a pod manifest using the following information:

Pod Name: simpleservece
Pod Label: simpleservice-web
Container Name: simpleservice-web
image: mhousenblas/simpleservice:0.5.0
Port Name: web
Container Port: 9876
protocol: TCP

A

—-
apiVersion: v1
kind: Pod
metadata:
name: simpleservice
labels:
name: simpleservice-web
spec:
containers:
- name: simpleservice-web
image: mhausenblas/simpleservice:0.5.0
ports:
- name: web
containerPort: 9876
protocol: TCP

20
Q

Port forward a pod called simpleservice from 2224 to 9876 in the pod allowing all ip addresses to access it.

A

kubectl port-forward simpleservice 2224:9876 —address=0.0.0.0

21
Q

Create a pod on the command line using the nginx image. Name the pod webserver.

A

kubectl run webserver —image=nginx

22
Q

Execute the date command on a pod called webserver.

A

kubectl exec webserver — date

23
Q

Open an interactive session inside a pod called nginx.

A

kubectl exec -it nginx — bash

24
Q

Copy a file from local to a pod named my_pod with one container in it.

A

kubectl cp <local> my_pod:<remote></remote></local>

25
Q

Copy a file from a pod named web_server with only one container in it to local.

A

kubectl cp web_server:<remote> <local></local></remote>

26
Q

Copy a file from local into a multi-container pod named web_server into a container called webby.

A

kubectl cp <local> web_server:<remote> -c webby</remote></local>

27
Q

A context is a reference to…

A

…a cluster, namespace, and user

28
Q

Write and httpGet liveness probe for a container. Make it wait 2 seconds before it starts and it should check every 5 seconds. The path is /health on port 9876. It should fail if it hasn’t succeeded in 1 second. Only let it fail three times.

A

livenessProbe:
initialDelaySeconds: 2
periodSeconds: 5
httpGet:
path: /health
port: 9876
timeoutSeconds: 1

failureThreshold: 3
29
Q

Write an exec command liveness probe for a container. Give it an initial delay of 2 seconds. Make it check every 5 seconds. Let the probe have 1 second to decide whether the probe has succeeded or failed. It should only be allowed to check three times. Make it succeed twice in a row before it is considered live.

A

livenessProbe:
initialDelaySeconds: 2
periodSeconds: 5
exec:
command:
- cat
- /tmp/healthy
timeoutSeconds: 1
failureThreshold: 3
successThreshold: 2

30
Q

What type of probe has a timeoutSeconds parameter?

A

The livenessProbe:

31
Q

Write a readiness probe for a container using the httpGet method. The path is /health and port is 8080. Make sure there is an initialDelay of 3 seconds. Make it check every 4 seconds. Make sure it has to succeeed twice to be considered ready.

A

readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 4
periodSeconds: 4
successThreshold: 2

32
Q

A liveness prob is intended to assure that a container is…

A

still performing its essential tasks.

33
Q

What can you add to a container that you suspect may not be performing its tasks but still may be running?

A

Add a liveness probe! This will cause the container to reboot when the container is running but not performing it’s function.

34
Q

What parameter would you set in a liveness probe to make it check liveness every 5 seconds for all eternity?

A

Set the periodSeconds parameter to 5.

35
Q

Check the readiness of a pod called sise-lp on the command line by describing the pod and grepping for ‘health’.

A

kubectl describe pods sise-lp | grep -i health

36
Q

Check the readiness of a pod called sise-lp on the command line by sending a curl to localhost:2224/health.

A

Step 1: Port forward the pod.
kubectl port-forward sise-lp 2224:9876 —address=0.0.0.0

Step 2: Send the curl request
curl localhost:2224/health

37
Q

Write a readiness probe using the exec command method. Target /tmp/healthy. Give it 3 seconds delay before starting. Make it check every 4 seconds and make it succeed twice before being considered ready.

A

readinessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 3
periodSeconds: 4
successThreshold: 2