Step by step approach of Kubernetes task on creating a Pod by the KodeKloud Engineer Program:

First of all before jumping right into the task, let's understand what is a Pod ?

Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.

Didn't get the technical definition?? don't worry I got you, now let's understand it with a simple real life example:
Let's consider you're baking a cake. In this scenario:

  1. Your kitchen is like the overall system or project you're working on.

  2. Ingredients for the cake are like the various components or resources needed for your project.

  3. Tools like mixing bowls, spoons, and measuring cups are like the environment or infrastructure where your project runs.

  4. Pods would be like organizing your ingredients and tools into separate containers based on their use. For example:

    • You might have one Pod/container for dry ingredients like flour, sugar, and baking powder.

    • Another Pod/container could hold wet ingredients like eggs, milk, and oil.

    • Each Pod/container contains everything you need for a specific part of the baking process.

  5. Running the project would be like baking your cake by taking out the necessary ingredients and tools from their respective Pods and following the recipe.

So, this is how Pods in computing keep things organized and make it easier to manage different parts of a program, organizing ingredients and tools into containers (Pods) helps you to be organized and efficient while baking a cake.

To know more about Pods, refer to Kubernetes official docs: https://kubernetes.io/docs/concepts/workloads/pods/

Now let's perform a realtime task

a. Create a pod named pod-httpd using httpd image with latest tag only and remember to mention the tag i.e httpd:latest.

b. Labels app should be set to httpd_app, also container should be named as httpd-container.

Checkout the video of this task on: https://youtu.be/cYyq2Of5his

Step 1: Verify state of the Kubernetes cluster

  1. Run the below command to view the state of the cluster

     kubectl get all
    

    It returns resources inside the cluster like pods, services, deployments etc.

Step 2: Verify pod existence

  1. Before creating the pod, verify it's existence by running below command.

     kubectl get pods
    

    It will return the name, state and all the details about the pod.

Step 3: Create a YAML file for the Pod

  1. Create a YAML file which will include the configurations to create the Pod as per the task.

     vi file_name.yaml
    
  2. Refer to this YAML file below to create a Pod as per the task.

     apiVersion: v1
     kind: Pod
     metadata:
       name: pod-httpd
       labels:
         app: httpd_app
     spec:
       containers:
       - name: httpd-container
         image: httpd:latest
    

    Optional: If you're new to linux having difficulties writing or exiting the vi editor, go through the below steps.

    After entering the editor press ESC key followed by the letter "i" to enter insert mode, now you can write or modify contents within the file.

    To save and exit press ESC key followed by a colon ":" symbol with the letters "w" and "q" i.e :wq .

    If there are any errors prompting to override just simply add an exclamation marks "!" at the end of the command i.e :wq! .

Step 4: Create a Pod from the YAML file

  1. Run the below command to create a Pod with the configs defined within the YAML file.

     kubectl apply -f file_name.yaml
    

Step 6: Verify Pod status

  1. Run the below command to know about the status of the Pod if its created or not, Pod must be in running state.

     kubectl get pods
    

Step 7: Verify Pod details

  1. Run the below command to ensure that the Pod matches the exact details as mentioned in the task.

     kubectl describe pod pod_name
    

    Congratulations!! you've successfully completed this task!!!

1
Subscribe to my newsletter

Read articles from Mohammad Abubaker directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mohammad Abubaker
Mohammad Abubaker

Software engineer who wants to give back to community by sharing his learnings in the field of DevOps and surrounding technologies.