Kubernetes Pod Yml Example | Kubernetes Pod Template

Kubernetes Pod Yml Example

A pod is the smallest building block of Kubernetes. Pod is a collection of containers. Pod can have one or more containers. in this blog post i will show you how to create a pod with yml file in kubernetes. this yml file is the template for pod in kubernetes.

cat mypod.yml

apiVersion: v1
kind: Pod
metadata:
  name: mypod
  labels:
    name: nginx
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80

save this above code in one yml file. above code is the template for kubernetes pod.

to create a pod with yml we have to define few properties in yml file. those are

  • apiVersion
  • kind
  • metadata
  • spec

apiVersion represents which version api you are using

kind represents what you are going to create with this yml. Here we can mention pod, replication controller, deployment, replication set...etc.

in metadata we can add name to this pod and we can add labels to this pod

in spec we have to add the docker image information. using this docker image pod will be created.

Create pod with Yml file

Using above yml file we can create pod. To create pods using yml file we use kubectl commands.

kubectl apply -f mypod.yml

this command will create pod name called mypod using above yml file.

Create pod with commands

 kubectl run mypod --generator=run-pod/v1 --image nginx

using this command you can create kubernetes pod.

Here mypod is the pod name and - -image nginx represents the docker image. so here using nginx docker image we are creating kubernetes pod

  • Kubernetes Pod Yml Example
  • kubernetes pod example yml
  • pod yml file
  • kubernetes pod yml file
  • create pod with yml file
  • how to create pod in kubernetes
  • Pod Template
  • kubernetes Pod Template

Leave a Reply

Your email address will not be published. Required fields are marked *