KodeKloud Engineer Kubernetes Tasks

Level 1-1. How to create a POD in Kubernetes cluster

KodeKloud Engineer Kubernetes Tasks

Photo by Growtika on Unsplash

Question 1:

The Nautilus DevOps team has started practicing some pods and services deployment on Kubernetes platform as they are planning to migrate most of their applications on Kubernetes platform. Recently one of the team members has been assigned a task to create a pod as per details mentioned below:

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

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

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.

Solution :

- Note: I Highly recommend you not to COPY and PASTE the answers. Try to understand the concept first and then try to solve the question.

we are going to execute all these commands in jump host itself.

  1. Before we start, let's check the presence of kubectl in our jump host.

$ kubectl version

  1. Now, let's create a pod-definition file, we are going to create a pod with the help of this pod-definition file only.

    $ k run pod-httpd --image=httpd:latest --dry-run=client -o yaml > pod-definition.yaml

Here as per the question, i have given pod-httpd as pod name and image as httpd with tag latest and --dry-run=client flag in Kubernetes is used to perform a simulation of a command without actually making any changes to the cluster. This can be useful for testing out commands or for getting a preview of what a command will do before executing it.

When the --dry-run=client the flag is specified, Kubernetes will print out the actions that it would have taken if the command had been executed, but it will not make any changes to the cluster.

The -o yaml option in kubectl is used to specify the output format of the command. By default, kubectl outputs the results of commands in a human-readable format. However, you can use the -o yaml option to output the results in YAML format.

and finally we are keeping all these things in a file named pod-definition.yaml

since, in question, they asked us to change label. So, let's edit our pod-definition file.

  1. EDIT our pod-definition.yaml file.

    $ vi pod-definition.yaml

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

    Now, as we have our pod-definition file ready, let's create a pod.

    $ k create -f pod-definition.yaml

    When we create a Kubernetes cluster, we can use the -f flag to specify the path to a configuration file. This will allow you to customize the cluster to your specific needs.

  2. Verification

$ k get pods

This command will list out the pods in our cluster.

$ k describe pod pod-httpd

This command will describe our pod, here we will get complete information related to our pod like the image used, the container used to create a pod, IP address, labels, and many more. We can match the values of the pod with our question.

If Everything is good then, we can click on submit

we will meet in the next article with another interesting topic, till then keep practicing.

please like 👍, follow Nagacharan , share and comment 💬your views on this article.

Did you find this article valuable?

Support Nagacharan by becoming a sponsor. Any amount is appreciated!