Kubernetes Architecture Flashcards
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’?
docker build -t myapp:v1.0 .
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.
sudo docker run -p 2224:8888 —name mycontainer -d myapp
What is the command to check out what contexts are available?
kubectl config get-contexts
Switch to a context called dev.
kubectl config use-context dev
Use a command to see all the resources you can create.
kubectl api-resources
Issue the command to see all the namespaces within a cluster
kubectl get namespaces
OR
kubectl get ns
Describe the default namespace.
kubectl describe ns default
OR
kubectl describe namespace default
Type out a manifest to create a namespace called test.
—-
apiVersion: v1
kind: Namespace
metadata:
name: test
Create a new namespace from a file called ns-test.yaml.
kubectl create -f ns-test.yaml
Create a namspace called dev from the CLI.
kubectl create ns dev
Write a resource quota manifest. Give it a name of tiny-rq. Give it 1 cpu and 1Gi of memory.
—-
apiVersion: v1
kind: ResourceQuota
metadata:
name: tiny-rq
spec:
hard:
cpu: “1”
memory: 1Gi
Create a resource quota from a manifest called rq-tiny.yaml in the test namespace
kubectl apply -f rq-tiny.yaml -n test
Delete a resource quota named rq-tiny from the test namespace
kubectl delete resourcequota rq-tiny -n test
Show al the pods in the current namespace and sort them by restart count.
kubectl get pods —sort-by=’.status.containerStatuses[0].restartCount’
Show all the services in the current namespace and sort them by name.
kubectl get services —sort-by=.metadata.name
Show all the pods across all the namespces and show extra details.
kubectl get pods —all-namespaces -o wide
Show everything except secrets across all namespaces.
kubectl get all -A
Create a port-forward to a pod called nginx from port 2224 to port 80 in the pod.
kubectl port-forward nginx 2224:80
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
—-
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
Port forward a pod called simpleservice from 2224 to 9876 in the pod allowing all ip addresses to access it.
kubectl port-forward simpleservice 2224:9876 —address=0.0.0.0
Create a pod on the command line using the nginx image. Name the pod webserver.
kubectl run webserver —image=nginx
Execute the date command on a pod called webserver.
kubectl exec webserver — date
Open an interactive session inside a pod called nginx.
kubectl exec -it nginx — bash
Copy a file from local to a pod named my_pod with one container in it.
kubectl cp <local> my_pod:<remote></remote></local>
Copy a file from a pod named web_server with only one container in it to local.
kubectl cp web_server:<remote> <local></local></remote>
Copy a file from local into a multi-container pod named web_server into a container called webby.
kubectl cp <local> web_server:<remote> -c webby</remote></local>
A context is a reference to…
…a cluster, namespace, and user
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.
livenessProbe:
initialDelaySeconds: 2
periodSeconds: 5
httpGet:
path: /health
port: 9876
timeoutSeconds: 1
failureThreshold: 3
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.
livenessProbe:
initialDelaySeconds: 2
periodSeconds: 5
exec:
command:
- cat
- /tmp/healthy
timeoutSeconds: 1
failureThreshold: 3
successThreshold: 2
What type of probe has a timeoutSeconds parameter?
The livenessProbe:
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.
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 4
periodSeconds: 4
successThreshold: 2
A liveness prob is intended to assure that a container is…
still performing its essential tasks.
What can you add to a container that you suspect may not be performing its tasks but still may be running?
Add a liveness probe! This will cause the container to reboot when the container is running but not performing it’s function.
What parameter would you set in a liveness probe to make it check liveness every 5 seconds for all eternity?
Set the periodSeconds parameter to 5.
Check the readiness of a pod called sise-lp on the command line by describing the pod and grepping for ‘health’.
kubectl describe pods sise-lp | grep -i health
Check the readiness of a pod called sise-lp on the command line by sending a curl to localhost:2224/health.
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
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.
readinessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 3
periodSeconds: 4
successThreshold: 2