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>