DEV Community

Cover image for #033 Kubernetes - Pods lab 3
Omar
Omar

Posted on

#033 Kubernetes - Pods lab 3

Introduction

this is part 33 from the journey it's a long journey(360 day) so go please check previous parts , and if you need to walk in the journey with me please make sure to follow because I may post more than once in 1 Day but surely I will post daily at least one 😍.

And I will cover lot of tools as we move on.


Lab

In last lecture we use the Imperative method , now we need to use the declarative method.
yaml is really important for devops we use it in docker but we did not understand what it is or how it's really work , so it will be good also to cover it somewhere in this journey.

yml

this is the yml file for a pod , it's on my github account you can access it on this link or if you follow me on docker parts so you already have DevOps folder just pull it.

let's back to the the file and break it to parts :

  1. apiVersion: Defines what version is used to create the Kubernetes Object.
  2. kind: Defines what object needs to be created in our example it's a single pod. We have name of first-api-dec if you remember in last part we call it first-api.
  3. metadata: You can add data here that helps uniquely identify objects in the Kubernetes cluster like name, type, etc.
  4. spec: This is the most important where you describe the description of the characteristics you want the resource to have, its desired state, etc.

get-pods

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

this is the old pod is have an error I can fix it but no need to it in this part so why bother :p
we need to create our new pod from this yml file
create

kubectl create -f ./app_033.yml
Enter fullscreen mode Exit fullscreen mode

because I am in same folder as file I can access it using ./app_033.yml so if you are in DevOpsJourney folder you should write ./app_033/app_033.yml
get-pods2

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

we can see we have our new pod is running and we see it take the name that we give it first-api-dec in the yml file.

Top comments (6)

Collapse
 
sunilvijay profile image
Sunil Vijay

Hello Omar, Your Docs are really good. Thanks for writing. I just wanted to view your DockerFile but couldn't view it, It says 404 not found in docker HUB.

Collapse
 
omarkhatib profile image
Omar

Hello I am glad that you like them , can you share what link you use to access it?

Collapse
 
sunilvijay profile image
Sunil Vijay
Thread Thread
 
omarkhatib profile image
Omar

it's work fine for me not sure why didn't work for you , this is a picture for Dockerfile .
I will make sure to replace it with my own , I just pick a random Online one because I was busy,
BTW you can use any other image you want , just search in dockerhub for simple-api Or use any image you want , I use specifically this image because it contain a port and to open in browser.

Thread Thread
 
sunilvijay profile image
Sunil Vijay

Thanks btw. Just wanted to know if any external packages are installed during this pull from docker hub. Thanks for your time. πŸ‘πŸ»

Thread Thread
 
omarkhatib profile image
Omar

github.com/emondek/simple-api
Also I pick this because the files are available on github , you can read how the api is written also Dockerfile