Kubernetes Pods: An Introduction
Table of contents
What is a k8s pods?
A Kubernetes (k8s) pod is the smallest deployable unit in Kubernetes, which can contain one or more containers. Pods are used to manage and run applications within a Kubernetes cluster.
When you create a Deployment, Kubernetes creates a Pod to host your application instance. A Pod is a Kubernetes abstraction that represents a group of one or more application as containers and share resources for those containers.
These resources include:
Shared storage, as Volumes.
Networking, as a unique cluster IP address.
Information about how to run each container, such as the container image version or ports to be used.
We can create Kubernetes (k8s) pods in two primary ways:
Imperative Method
In the imperative approach, you directly issue commands to create and manage Pods.
Creating a Pod:
kubectl run my-pod --image=nginx --restart=Never
This command creates a Pod named "my-pod" using "nginx" image.
Listing Pods:
kubectl get pods
This command displays all the Pods in the current namespace.
Deleting a Pod:
kubectl delete pod my-pod
This command removes the specified Pod.
Declarative Method
In the declarative method, you define the desired state of your Pods in a YAML configuration file.
Create a Pod YAML file (pod.yaml):
apiVersion: v1 kind: Pod metadata: name: my-pod spec: containers: - name: my-container image: nginx
The manifest (YAML): We will break the manifest down into four parts:
ApiVersion — Version of the Kubernetes API you’re using
Kind — Kind of object you want to create.
Metadata — Information that uniquely identifies the object, such as name or namespace.
Spec — Specified configuration of our pod, for example image name, container name, volumes, etc.
Applying the configuration:
kubectl apply -f pod.yaml
This command creates the Pod according to the specifications defined in the YAML file.
Viewing the Pod’s status:
kubectl describe pod my-pod
This provides detailed information about the Pod, including its status and events.
Deleting a Pod:
kubectl delete -f pod.yaml
This removes the Pod defined in the YAML configuration.
Key Concepts
Pod: The smallest deployable unit in Kubernetes, typically encapsulating a single container.
Imperative vs. Declarative: The imperative method involves command-based actions, while the declarative method relies on configuration files to manage resources.
kubectl: The command-line tool used to interact with the Kubernetes API.
That’s a quick rundown of setting up a Kubernetes cluster, creating PODs using both imperative and declarative methods, and managing them with key commands. Kubernetes is all about managing containers at scale, and these approaches helped me gain a deeper understanding of POD management!
"I believe this article will be beneficial, allowing you to uncover fresh insights and gain enriching knowledge."
Happy Learning🙂
PARTH SHARMA
Subscribe to my newsletter
Read articles from Parth Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by