Kubernetes: Create simple Pod by manifest file

This post shows how to create pods on kubernetes cluster by manifest file.

Create manifest file

Create a yaml file app1.yaml like the following.

apiVersion: v1
kind: Pod
metadata:
  name: app1
spec:
  containers:
  - image: dockerhubuser/app1
    name: app1-container
    ports:
      - containerPort: 8080
        protocol: TCP

Kubernetes API version is v1 .

apiVersion: v1

The type of kubernetes object resource is Pod .

kind: Pod

Define a specification of pod in spec .

  image : container image to be use
  name  : name of container
  ports : container port number and protocol
spec:
  containers:
  - image: dockerhubuser/app1
    name: app1-container
    ports:
      - containerPort: 8080
        protocol: TCP

Apply manifest file and Create pod

Run the following command to apply manifest file and create pods.

kubectl apply -f app1.yaml

It shows the following.

pod/app1 created

Run the following command to confirm working pods.

kubectl get pods

It shows the following.

NAME   READY    STATUS     RESTARTS    AGE
app1   1/1      Running    0           5m14s

Run the following command to confirm pods information in yaml format.

kubectl get pods app1 -o yaml

It shows the following.

apiVersion: v1
kind: Pod
metadata:
....

Run the following command to confirm nodes on which pods are working and pods’ ip addresses.

kubectl get pods -o wide

It shows the following.

NAME   READY    STATUS     RESTARTS    AGE      IP           NODE     NOMINATED NODE    READINESS GATES
app1   1/1      Running    0           5m14s    10.45.0.3    node1    <none>            <none>

NOTE: If you create a pod according to this post, you can access the above ip address 10.45.0.3 from only within the cluster.

Delete Pod

Run the following command to delete pods.

kubectl delete pod app1

It shows the following.

pod "app1" deleted