Kubernetes CKAD weekly challenge #1 Creating Pods

Kim Wuestkamp
Mar 25, 2019 · 2 min read
Image for post
Image for post

ALL CHALLENGES AND TIPS

Rules!

  1. avoid creating yaml manually from scratch

Notices

Todays Task: Pod Creation

  1. 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 my-label: test.

3. Create the pod from the YAML file.

4. Connect via ssh to the pod. Make sure its hostname is written into the file /tmp/hostname.

5. Delete the pod instantly without waiting time.

Solution

1.

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.

2.

Then edit pod1.yaml to make it look ~like this (I removed unimportant lines):

3.

k replace -f pod1.yaml --forcek get pod -l my-label
NAME READY STATUS RESTARTS AGE
pod1 0/1 Completed 0 39s
k 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

End

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.

ALL CHALLENGES AND TIPS

More on

Image for post
Image for post
https://killer.sh

FAUN

The Must-Read Publication for Creative Developers & DevOps Enthusiasts

Sign up for FAUN

By FAUN

Medium’s largest and most followed independent DevOps publication. Join thousands of aspiring developers and DevOps enthusiasts Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Kim Wuestkamp

Written by

wuestkamp.com | killer.sh (CKS CKA CKAD Simulator) | Software Engineer, Infrastructure Architect, Certified Kubernetes, Certified Symfony

FAUN

FAUN

The Must-Read Publication for Creative Developers & DevOps Enthusiasts. Medium’s largest DevOps publication.

Kim Wuestkamp

Written by

wuestkamp.com | killer.sh (CKS CKA CKAD Simulator) | Software Engineer, Infrastructure Architect, Certified Kubernetes, Certified Symfony

FAUN

FAUN

The Must-Read Publication for Creative Developers & DevOps Enthusiasts. Medium’s largest DevOps publication.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store