Kubernetes: Apps and pods

Kubernetes

A Pod is the smallest deployable units of computing in a Kubernetes environment. A pod can host just one application (container) or several.

Let us see if there are any pods running in the default namespace “default”

[root@kubmaster01 ~]# kubectl get pod
No resources found in default namespace.

Now let us run an application (container)
[root@kubmaster01 ~]# kubectl run app1 –image=httpd
pod/app1 created

[root@kubmaster01 ~]# kubectl get pod
=======
NAME    READY     STATUS     RESTARTS     AGE
app1    1/1    Running     0     84s
========

The above command ran the app1 container using imperative method. However, Kubernetes created the container using other default settings. Let us find out the configuration of the container in a yaml format. It reads that there is a pod named app1 running a container named app1. One out of One container is running.

The below command displays the app1 pod in a yaml format

[root@kubmaster01 ~]# kubectl get pod app1 -o yaml

[root@kubmaster01 ~]# kubectl describe pod app1

====== === 
Name: app1
Namespace: default
Priority: 0
Service Account: default
Node: kubworker01/192.168.146.130
Start Time: Thu, 15 Aug ……
===== ===

[root@kubmaster01 ~]# kubectl describe pod app1

===== =====
Name: app1
Namespace: default
Priority: 0
Service Account: default
Node: kubworker01/192.168.146.130
Start Time: Thu, 15 Aug 2024 18:14:04 +0530
Labels: run=app1
Annotations: cni.projectcalico.org/containerID: b175aaf32640bea4bb365e3b41cdf901b0ae0d33b26113c18f5eb06025449b78
cni.projectcalico.org/podIP: 172.16.135.65/32
cni.projectcalico.org/podIPs: 172.16.135.65/32
Status: Running
IP: 172.16.135.65
IPs:
IP: 172.16.135.65
Containers:
app1:
Container ID: con
===== =====

[root@kubmaster01 ~]# kubectl explain pods

The above command explains the fields that are part of a yaml manifest file. However, it explains only the top-level parameters such as apiVersion, kind, metadata, spec, etc. If we need to see an explanation of the parameter that declared the name of the container in a pod, we will have to use the below command.

[root@kubmaster01 ~]# kubectl explain pod.spec.containers.name

An alternate method will be to use the “recursive” switch that explains all parameters from top level to low-level as show below.

 

[root@kubmaster01 ~]# kubectl get pod -o wide