Kubernetes – POD

Kubernetes - POD - describing POD
Kubernetes - POD - describing POD

Hi All,

GREETINGS FOR THE DAY 🙂 LIFE IS BEAUTIFUL 🙂

We are discussing Docker and Kubernetes. In previous few articles we discussed

  1. What is Kubernetes ? – https://knowledge-junction.in/2021/09/03/kubernetes-introduction-starting-point-for-beginners-helps-to-prepare-the-interview/
  2. Setting up local environment for Kuberneteshttps://knowledge-junction.in/2021/09/11/kubernetes-simplifying-setting-up-local-environment-creating-kubernetes-cluster-locally-helps-in-interview-preparation-kubernetes-for-beginners/
  3. Yaml file guide / referencehttps://knowledge-junction.in/2021/09/04/complete-guide-to-yaml/

We will move ahead and will discuss Kubernetes objects starting with POD

What is Kubernetes – POD ?

  • A POD is group of one or more container (What are containers – Docker – Beginning with Docker – Introduction to Containers and Docker – part 1 – Try to simplify the concepts / Helps to prepare interviews 🙂 – https://knowledge-junction.in/2021/08/07/docker-beginning-with-docker-introduction-to-containers-and-docker-part-1-try-to-simplify-the-concepts-helps-to-prepare-interviews/)
  • Resources like storage, network, namespaces, file system volumes are shared among the containers within POD
  • Types of POD
    1. Single Container POD
    2. Multi Container POD
  • Generally POD with single container is mostly used and very common use case
  • POD with multiple container which are tightly coupled is used advanced use case
  • Kubernetes manages PODs rather Containers
  • If we need to scale our application, we could have multiple PODs. We called this as Replicas
  • POD represents processes running on respective Nodes

POD Yaml file – following is an example – contains container running image nginx:1.14.2

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80

Following are few important points while creating yaml file for POD

  • apiVersion – it must be v1
  • kind – Pod
  • Containers within Pod – In above Yaml file we have specified one container
  • Above Yaml file will create a Pod having name – nginx
  • We could have more details for Pod like – CPU resources, Memory resources, assigning Pod to specific node and few more

POD Yaml file with Memory resources – In below YAML file we are having Container requesting memory resource of 100 MiB and memory limit of 200 MiB

Containers are not allowed to use the memory beyond there specified limit. If the Container allocates more memory than its memory limit then Container is terminated

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: knowledge-junction
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    resources:
      requests:
        memory: "100Mi"
      limits:
        memory: "200Mi"
    command: ["stress"]
    args: ["--vm", "1", "--vm-bytes", "150M", "--vm-hang", "1"]

Once we have POD Yaml file ready, we could use the following command to create POD

kubectl apply -f pod.yaml

We could also create POD with kubectl run command as

Syntax : kubectl run <POD-Name> –image=<Image name>

kubectl run nginx --image = nginx:1.14.2

To get all Pods in given namespace

$ kubectl get pods   
                                                                                                                                                                      NAME                                 READY   STATUS    RESTARTS   AGE
registry-deployment-969b8886-trhcp   1/1     Running   0          67d
test-nginx-f8b486fb4-6jjbz           1/1     Running   0          67d

To get more details like IP address of node / node name we could use option – “wide” as

Syntax : kubectl get pod <pod name> -o wide

kubectl get pod test-nginx-f8b486fb4-6jjbz -o wide

NAME                         READY   STATUS    RESTARTS   AGE   IP             NODE              NOMINATED NODE   READINESS GATES

test-nginx-f8b486fb4-6jjbz   1/1     Running   0          67d   000.00.00.00   servername   <none>           <none>

To have all POD details like – Namespace, Node, Start Time, Labels, Status, IP address details , Pod Template, Limits (cpu, memory), Requests (cpu, memory), Container details Volume details etc. we could use “describe” as

Syntax : kubectl describe pod <pod name>

kubectl describe pod test-nginx-f8b486fb4-6jjbz

Output of the above command will be

Kubernetes - POD - describing POD
fig : Kubernetes – POD – describing POD

Deleting POD – We could delete POd using “delete” parameter to KubeCtl as

Syntax – kubectl delete <Pod-Name>

kubectl delete pod test-nginx-f8b486fb4-6jjbz

POD Status

  • Following are POD status values :
ValueDetails
PendingContainers within the POD is not set up and ready to run
RunningThe POD is bound to node
Containers within POD is created
At least one container is running or restarting
SucceededAll Containers within POD terminated successfully
Containers will not be restarted
FailedAll Containers in POD terminated
Minimum once Container in POD terminated in failure
UnknownState of POD is not getting
Mostly this error occurs when there is communication error with node where POD is running
Table 1 : Kubernetes – POD – POD statuses

Best Practices :

  • Mostly PODs are not getting created directly
  • We create PODs generally through Deployment object

Thanks for reading !!! Feel free to discuss in case any suggestions / thoughts / questions

HAVE A GREAT TIME AHEAD!!!

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: