Pods in Kubernetes

My name is Shyju Krishnan having 10+ Years of experience as an IT infrastructure/Solution Architect
Search for a command to run...

My name is Shyju Krishnan having 10+ Years of experience as an IT infrastructure/Solution Architect
No comments yet. Be the first to comment.
In this series, i will brainstorm basic to advanced topics with examples,with commands,with usecases
Kubernetes Namespaces After reading this post you will be understanding the high level of Kubernetes namespace and basic kubectl commands related to namespaces. What is namespace ๐ค In Kubernetes, namespaces provide a mechanism for isolating groups...
API (Application Programming Interface) security is critical for protecting sensitive data and maintaining the integrity of systems and applications. APIs are used to connect different systems and applications, and as a result, they can provide a gat...

Well after months of deep slumber, away from social media networks, I had to return to Pune and adapt to hybrid working. I was browsing through meetup.com and was intrigued by one event from AWS user group Pune. It is AWS Reinvent 2022 -Recap on 21st...

Episode 2

Simplify Access Control and Enhance Transparency Over Your ML Projects

Episode 1

Pods are the smallest and most basic deployable objects in Kubernetes. A Pod represents a single instance of a running process in your Kubernetes 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.
Pods also contain shared networking and storage resources for their containers:
- Network: Pods are automatically assigned unique IP addresses. Pod containers share the same network namespace, including IP address and network ports. Containers in a Pod communicate with each other inside the Pod on localhost.
- Storage: Pods can specify a set of shared storage volumes that can be shared among the containers.
Pods we create two ways either command line or through manifest files,
Sample manifest file
apiVersion: v1
kind: Pod
metadata:
name: static-web
labels:
role: myapp
spec:
containers:
- name: web
image: nginx
ports:
- name: web
containerPort: 80
protocol: TCP
Create the pod
Kubectl create -f <file.yaml>
kubectl get pod
kubectl get pod --show-labels
Kubectl delete pod <pod name>
When you run kubectl get pod to inspect a Pod running on your cluster, a Pod can be in one of the following possible phases:
Pending: Pod has been created and accepted by the cluster, but one or more of its containers are not yet running. This phase includes time spent being scheduled on a node and downloading images.
Running: Pod has been bound to a node, and all of the containers have been created. At least one container is running, is in the process of starting, or is restarting.
Succeeded: All containers in the Pod have terminated successfully. Terminated Pods do not restart.
Failed: All containers in the Pod have terminated, and at least one container has terminated in failure. A container "fails" if it exits with a non-zero status.
Unknown: The state of the Pod cannot be determined.
By default, Pods run on nodes in the default node pool for the cluster. You can configure the node pool a Pod selects explicitly or implicitly:
You can explicitly force a Pod to deploy to a specific node pool by setting a node selector in the Pod manifest. This forces a Pod to run only on Nodes in that node pool.
You can specify resource requests for the containers you run. The Pod will only run on nodes that satisfy the resource requests. For instance, if the Pod definition includes a container that requires four CPUs, the Service will not select Pods running on Nodes with two CPUs.
Sample YAML file assigning Pods to Nodes
apiVersion: v1
kind: Pod
metadata:
name: with-node-affinity
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: another-node-label-key
operator: In
values:
- another-node-label-value
containers:
- name: with-node-affinity
image: k8s.gcr.io/pause:2.0
Reference ๐ Assigning Pods to Nodes
By default pod, there is no limitation for memory and CPU. You can set a limit to control the memory and CPU
It is strongly recommended that you configure limits for your Pods, based on the requirements of the actual workloads
apiVersion: v1
kind: Pod
metadata:
name: frontend
spec:
containers:
- name: app
image: images.my-company.example/app:v4
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
- name: log-aggregator
image: images.my-company.example/log-aggregator:v6
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
Reference ๐ Resource Management for Pods

Hope you have got an idea about Kubernetes Pod and how to create it
Happy Learning โ
Thank you !๐