Shashikant shah

Thursday 10 December 2020

What is a Pods in Kubernetes. Part-02

1.What is a Pods ? 

Pods are the smallest, most basic deployable objects in Kubernetes. A Pod represents a single instance of a running process in your cluster. Pods contain one or more containers, such as Docker containers. When a Pod runs multiple containers, the containers are managed as a single entity and share the Pod's resources.


  1. One or more containers deployed on pod.
  2. Containers in a pod share an IP Address, hostname and other resources.
  3. Containers within the same pod have access to shared volumes.
  4. Pods handle Volumes, Secrets, and configuration for containers.
  5. With Horizontal Pod Autoscaling, Pods of a Deployment can be automatically started and halted based on CPU usage.
  6. Each Pod has its unique IP Address and ports within the cluster.
  7. Any data saved inside the Pod will disappear without a persistent storage.

# kubectl get pods

NAME       READY   STATUS    RESTARTS   AGE
      nginxpod       2/2        Running          0               4m25s

NAME           :- Pod name
      READY 2/2   :- <running status of container>/<total of container in pod>
      STATUS        :-  status of pod.
      RESTARTS  :- restart count.
      AGE              :- running status time.

# kubectl run <pod_name>  --image=<image_name>

# kubectl run nginx --image=nginx

# kubectl describe pods nginx

# kubectl get pods --show-labels

# kubectl get pods -w (watch command)

# kubectl get po -o wide (which node, pod is working)

# kubectl delete pod <pod_name>

# kubectl delete pods --all (delete all pods)

# kubectl get pods <pod_name> (How many container are running in pod.)

# kubectl edit pod <pod_name>   (edit pod file update and changes.)

# kubectl explain pod --recursive | less  (help for create yaml file)

# kubectl get pods --all-namespaces

Kubernetes system namespaces use :- kube-system

New Pods default namespaces use :- default

# kubectl explain pod ( help for yaml file parami)

# kubectl  exec  <pod_name>  -c <container_name> -it bash (login container)

# kubectl describe pods nginx (check debug pods and containers)

# kubectl logs nginxpod -c rediscontainer (check logs for container)

# kubectl exec <pod_name> date  (execute date command)

kubectl exec <pod_name> -c <container-name> date  (execute date command in single container)


Check yaml file (create and apply is same command)

# kubectl create -f first_pod.yaml --dry-run=client

# kubectl apply -f first_pod.yaml --dry-run=client

How to create yaml file ?

# kubectl explain pods

# kubectl explain pod --recursive | less

Example for help create pod yaml file

# kubectl run nginx --dry-run=client --image=nginx -o yaml



# cat first_pod.yaml

apiVersion: v1        resource API version

kind: Pod              resource name

metadata:          details of info

  name: nginxpod pod name

  labels:                  lable name             

    app: nginxlab

spec:                  specification of conatiner

  containers:

  - name: ngxcontainer   first container name

    image: nginx               image name

  - name: rediscontainer  second container name

    image: redis                image name

# kubectl   apply   -f    first_pod.yaml

# kubectl   delete  -f  first_pod.yaml







No comments:

Post a Comment