Below is the Kubernetes YAML file for creating a simple pod.
~$ cat simple-pod.yaml apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80
Explanation of each field in YAML
Below is the explanation of each of the lines in the YAML file.
|kind: Pod||The field “kind” shows the api resource that is required to be created, when this YAML section is applied. The resource is of kind “Pod”.|
|containers:||The section “containers” is a list of containers that are executed in the pod. There is only one container.|
|name: nginx||The name section is in the container spec section and explains that name of the container is nginx.|
|image: nginx:latest||The image key explains that the container image is nginx and “latest” tag for the image will be downloaded.|
Running the YAML file
We have created a Kubernetes 2 node cluster with the client machine where we issue the kubectl command as below. We deploy the YAML file using “kubectl apply” and check the pods using the “kubectl get pods” command.
~$ kubectl apply -f simple-pod.yaml pod/nginx created ~$ kubectl get pods NAME READY STATUS RESTARTS AGE nginx 0/1 ContainerCreating 0 4s ~$ kubectl get pods NAME READY STATUS RESTARTS AGE nginx 1/1 Running 0 8s