A Pod may be a cluster of 1 or additional containers (such as dockhand containers), with shared storage/network, and a specification for the way to run the containers. A Pod’s contents are perpetually co-located and co-scheduled, and run in an exceedingly shared context. A Pod models an application-specific “logical host” – it contains one or additional application containers that are comparatively tightly coupled with each other’s — in an exceedingly pre-container world, being dead on an equivalent physical or virtual machine would mean being dead on an equivalent logical host
Uses of pods
Pods may be accustomed host vertically integrated application stacks (e.g. LAMP), however their primary motivation/purpose is to support co-located, co-managed helper programs, such as:
- Content management systems, file and information loaders and native cache managers, etc.
- Log and checkpoint backup, compression, rotation and snapshotting, etc.
- Proxies, bridges, and adapters.
- Controllers, managers, configurators, and updaters.
Types of Pod
There are two types of Pods:
- Single container pod.
- Multi container pod.
Single Container Pod
Pods are created using kubectl run command which pull a defined docker image from Docker registry to create pod.
$ kubectl run <name of pod> --image=<name of the image from registry>
Example − We will create a pod with a nginx image which is available on the Docker hub.
$ kubectl run nginx --image=nginx:1.14.2
Another example is creating the yaml file and then running the kubectl create command.
apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: containerPort: 80 imagePullPolicy: Always
Save above created yaml file with the name of nginx.yml and then run the create command to run document.
$ kubectl create -f nginx.yml
It will create a pod with the name of nginx. Pod can be described using describe command along with kubectl.
Multi Container Pod
Multi container pods are created using yaml which contains definition of the containers.
apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: containerPort: 80 imagePullPolicy: Always -name: Database Image: mysql Ports: containerPort: 7501 imagePullPolicy: Always
In the above code, we have created one pod with two containers inside it, one for nginx and the other for mysql.