Site icon i2tutorials

Kubernetes – Pod

Kubernetes – Pod

 

It’s possible to create pods with multiple containers inside them. For example, keeping a database container and a data container together in a pod.

Types of Pod

Pods come in two types:

Single Container Pod

Kubectl run can be used to create pods, where we specify an image on the Docker registry which we will pull when creating the pod.

$ kubectl run <name of pod> --image=<name of the image from registry>

Example − Let’s create a pod with a Tomcat image from Docker Hub.

$ kubectl run tomcat --image = tomcat:8.0

Alternatively, you can create the yaml file and then run kubectl create.

apiVersion: v1
kind: Pod
metadata:
   name: Tomcat
spec:
   containers:
   - name: Tomcat
    image: tomcat: 8.0
    ports:
containerPort: 7500
   imagePullPolicy: Always

As soon as the above yaml file is created, we’ll save it as tomcat.yml and run the create command.

$ kubectl create –f tomcat.yml

To describe the pod, use the describe command along with kubectl.

Multi Container Pod

A multi-container pod is created using yaml mail with the container definitions.

apiVersion: v1
kind: Pod
metadata:
   name: Tomcat
spec:
   containers:
   - name: Tomcat
    image: tomcat: 8.0
    ports:
containerPort: 7500
   imagePullPolicy: Always
   -name: Database
   Image: mongoDB
   Ports:
containerPort: 7501
   imagePullPolicy: Always

We’ve created one pod with two containers, one for Tomcat and one for MongoDB, in the above code.

 

Exit mobile version