1 - Core Concepts Flashcards
Create a namespace called ‘mynamespace’ and a pod with image nginx called nginx on this namespace
kubectl create namespace mynamespace
kubectl run nginx –image=nginx –restart=Never -n mynamespace
Create the pod that was just described using YAML
kubectl run nginx –image=nginx –restart=Never –dry-run=client -n mynamespace -o yaml > pod.yaml
Create a busybox pod (using kubectl command) that runs the command “env”. Run it and see the output
kubectl run busybox –image=busybox –command –restart=Never -it –rm – env
Create a busybox pod (using YAML) that runs the command “env”. Run it and see the output
kubectl run busybox –image=busybox –restart=Never –dry-run=client -o yaml –command – env > envpod.yaml
Get the YAML for a new namespace called ‘myns’ without creating it
kubectl create namespace myns -o yaml –dry-run=client
Create the YAML for a new ResourceQuota called ‘myrq’ with hard limits of 1 CPU, 1G memory and 2 pods without creating it
kubectl create quota myrq –hard=cpu=1,memory=1G,pods=2 –dry-run=client -o yaml
Get pods on all namespaces
kubectl get po –all-namespaces
Create a pod with image nginx called nginx and expose traffic on port 80
kubectl run nginx –image=nginx –restart=Never –port=80
Change pod’s image to nginx:1.7.1. Observe that the container will be restarted as soon as the image gets pulled
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
Get nginx pod’s ip created in previous step, use a temp busybox image to wget its ‘/’
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}’)
Get pod’s YAML
kubectl get po nginx -o yaml
Get information about the pod, including details about potential issues (e.g. pod hasn’t started)
kubectl describe po nginx
Get pod logs
kubectl logs nginx
If pod crashed and restarted, get logs about the previous instance
kubectl logs nginx -p
# or
kubectl logs nginx –previous
Execute a simple shell on the nginx pod
kubectl exec -it nginx – /bin/sh