What is Kubernetes pod? Pod Cheat Sheet
https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/
https://kubernetes.io/docs/concepts/workloads/pods/
Pods are the smallest and primary deployable objects of computing that you can create and manage in Kubernetes Cluster.
A Pod signifies a single instance of a running process in your Kubernetes cluster, The containers of pod are managed as a single a single entity and share the all resources of a pod.
A Pod is a group of one of more containers such as docker containers with shared network resources and storage, and instructions and specifications for how to run containers.
The Pods in a Kubernetes cluster are basically used in two main methods.
• Single container per Pod. The “one-container-per-Pod” model is that the commonest Kubernetes use case; In this situation, you’ll think about a Pod as a wrapper around one container; Kubernetes manages Pods instead of managing the containers directly.
• Pods that run multiple containers that need to collective work. A Pod can encapsulate an application composed of multiple co-located containers that are tightly coupled and need to share resources. These co-located containers form a single cohesive unit of service—for example, one container serving data stored in a shared volume to the public, while a separate sidecar container refreshes or updates those files. The Pod wraps these containers, storage resources, and an ephemeral network identity together as a single unit.
If you didn’t install Kubernetes kindly click here installation guide
Here is the example to create a pod, from a yaml file.
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
– name: nginx
image: nginx:1.23.3
ports:
– containerPort: 80
Run the following command.
pod/nginx created
[root@client01 ~]#
Verify and list the created pod in a name space
[root@client01 ~]# kubectl get pods
[root@client01 ~]# kubectl get po
To get list of pod with watch
[root@client01 ~]# kubectl get pod -A –watch
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 54s
To create the pod from STDIN
cat <<EOF | kubectl create -f -
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx:latest
EOF
To delete the pod running below command.
To get the detailed information about pod such as Name, Namespace, Nodes, IP etc execute the following command
If you need to check the logs of running pod than need to run following command.
Use the following command if pod has multiple containers
If you need to output the logs for all pods with a label
To manage and assign the pod resources like as CPU, Memory has a look into below example.
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
– name: nginx
image: nginx:1.23.3
resources:
requests:
memory: “64Mi”
cpu: “250m”
limits:
memory: “128Mi”
cpu: “500m”
ports:
– containerPort: 80
In above example pod requested 64Mi memory and 250m CPU, while limits options preventing the maximum memory and cpu.
To get the output of a pod in yaml format
To get output of a pod in json format
To store the output of a pod in yaml format.
To get the wide ouput like as IP, Node Name, NOMINATED NODE READINESS GATES
To get list of all pods in a namespace
Note here “default” is the namespace name.
Create the pod from image.
Start a nginx pod and let the container expose port 8888
Dry run; print the corresponding API objects without creating them
Start a nginx pod and set environment variables “DNS_DOMAIN=cluster” and “POD_NAMESPACE=default” in the container
Start a nginx pod and set labels “app= nginx ” and “env=prod” in the container
Start a nginx pod, but overload the spec with a partial set of values parsed from JSON
Start a busybox pod and keep it in the foreground, don’t restart it if it exits
Run the pod in interactive shell command mode.
Execute a command after creating a pod
Run the command in running container
To update patch in running pod
hostname”,”image”:”new image”}]}}’
To get utilization metrics of a pod
To get utilization metrics of all containers of pod