We have seen about the Kubernetes and more details so far, this series we are planning to start explaining the Kubernetes objects. Part of that lets start from Kubernetes pods, this could give details explanation about how to create a pod, delete pod, how it works and how we can create it.
What is a Pod?
Pods are the smallest deployable computing units that Kubernetes allows you to create and manage.
A Pod is a group of one or more containers with shared storage and network resources, as well as a specification for how the containers should be run. The contents of a Pod are always co-located, co-scheduled, and run in a shared context. A Pod represents an application-specific “logical host”: it contains one or more coupled application containers.
Pods are containers that abstract one or more containers in your Kubernetes cluster. Each container in a pod shares the pod’s resources, such as IP and storage.
Pod usage patterns
Pods can be used in two main ways:
- Pods that run a single container. The simplest and most common Pod pattern is a single container per pod, where the single container represents an entire application. In this case, you can think of a Pod as a wrapper.
- Pods that run multiple containers that need to work together. Pods with multiple containers are primarily used to support co-located, co-managed programs that need to share resources. These co-located containers might form a single cohesive unit of service — one container serving files from a shared volume while another container refreshes or updates those files. The Pod wraps these containers and storage resources together as a single manageable entity.
Each Pod is meant to run a single instance of a given application. If you want to run multiple instances, you should use one Pod for each instance of the application. This is generally referred to as replication. Replicated Pods are created and managed as a group by a controller, such as a Deployment.
How to create a Pod?
Using the Pod Object
Create a YAML file named
demo.yaml and paste the code below:
- image: demo/demo
- containerPort: 8080
Run the command below in your terminal to automatically generate a pod in your cluster.
# kubectl apply -f demo.yaml
Using the ReplicaSet
Create a YAML file named
demo_rs.yaml and paste the code below:
- name: demo
Run the command below in your terminal to create a ReplicaSet in your cluster. This ensures that the demo pod has a set number of pods always running.
# kubectl apply -f demo_rs.yaml
Read full article on Kubernetes Pods — FoxuTech