- avoid creating yaml manually from scratch
- use only https://kubernetes.io/docs/home/ for help.
- check my solution after you did yours. You might even have a better one ;)
- This challenge was tested on k8s 1.18. Please let us know should you encounter any issues in the comments
- how to be fast with Kubectl ≥ 1.18
Todays Task: Pod Creation
- Create a pod of image bash which runs once to execute the command
hostname > /tmp/hostname && sleep 1d.
2. Export and edit its YAML to add a label
3. Create the pod from the YAML file.
4. Connect via ssh to the pod. Make sure its hostname is written into the file
5. Delete the pod instantly without waiting time.
use kubectl >= 1.18alias k=kubectlk run -h # show helpk run pod1 --image=bash -- bash -c "hostname >> /tmp/hostname && sleep 1d"k get pod pod1 -o yaml > pod1.yamlk get pod pod1 -o yaml --export > pod1.yaml # DEPRECATED do not use!
It’s also possible to use the
--o yaml --dry-run=client option during Pod creation to only get the YAML output. Though in this task it was requested to output in a file.
Then edit pod1.yaml to make it look ~like this (I removed unimportant lines):
k replace -f pod1.yaml --forcek get pod -l my-label
NAME READY STATUS RESTARTS AGE
pod1 0/1 Completed 0 39sk exec -it pod1 cat /tmp/hostnamek delete pod pod1 --force --grace-period 0
We could also add labels to pods using:
k label -h # show helpk label pod pod1 new-label=awesome
This first challenge just showed us on a simple example how to create a Kubernetes object via console command and then dump its YAML to further configure it.