CKAD-exercises/a.core_concepts.md at main · dgkanatsios/CKAD-exercises

01 - 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 --namespace mynamespace

02 - Create the pod that was just described using YAML

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: mynamespace
spec:
  containers:
    - image: nginx
      name: nginx

03 - Create a busybox pod (using kubectl command) that runs the command "env". Run it and see the output

Forma Errada

$ kubectl run --image busybox --restart Never -- env 
	pod/env created

# Veja que o container não tem **args** ou **command**, o que era pra ser o 
# comando **env** tornou-se o nome do Pod.
$ kubectl get pods env -o yaml                              
	apiVersion: v1
	kind: Pod
	metadata:
	  labels:
	    run: env
	  name: env
	  namespace: ckad
	spec:
	  containers:
	  - image: busybox
	    imagePullPolicy: Always
	    name: env

Forma Correta

$ kubectl run **busybox** --image busybox --restart Never -- env 
	pod/busybox created

# Nesta segunda versão o Pod recebe o nome correto e o parâmetro
# **env** torna-se o args do container.
$ kubectl get pods busybox -o yaml 
	apiVersion: v1
	kind: Pod
	metadata:
	  labels:
	    run: busybox
	  name: busybox
	  namespace: ckad
	spec:
	  containers:
	  - args:
	    - env
	    image: busybox

Outra Opção Possível

# Desta forma o Pod será deletado após a execução do comando
$ kubectl run -it --rm busybox \\
	--image busybox \\
	--restart Never \\
	--command -- env
			PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
			TERM=xterm
			...
	pod "busybox" deleted

# Mais um exemplo
$ kubectl run -it --rm busybox \\
	--image busybox \\
	--restart Never \\
	--command -- /bin/sh -c "echo \\"Hello World\\"";
			Hello World
	pod "busybox" deleted

04 - Create a busybox pod (using YAML) that runs the command "env". Run it and see the output

# A grande pegadinha aqui é esquecer do **restartPolicy: Never**
# e o Pod ficar em CrashLoopBackoff
apiVersion: v1
kind: Pod
metadata:
  name: busybox
spec:
  containers:
    - image: busybox
      name: busybox
      args:
        - env
  restartPolicy: Never

05 - Get the YAML for a new namespace called 'myns' without creating it

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

		apiVersion: v1
		kind: Namespace
		metadata:
		  creationTimestamp: null
		  name: myns
		spec: {}
		status: {}

06 - Get the YAML for a new ResourceQuota called 'myrq' with hard limits of 1 CPU, 1G memory and 2 pods without creating it


07 - Get pods on all namespaces

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

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