Let’s talk about how YAML configuration file can be used to deploy Kubernetes POD’S.
Kubernetes uses YAML files as inputs for creation of objects such as POD’S, Replicas, Services etc..
They all follow a similar structure, A Kubernetes definition file contains these 4 top level fields & are mandatory.
- apiVersion
- kind
- metadata
- spec
The API Version for deploying a POD is V1. This value varies on what we are trying to create. Here is a small table.
Kind | Version |
---|---|
POD | V1 |
Service | V1 |
ReplicaSet | apps/v1 |
Deployment | apps/v1 |
metadata is the data about the Object like its name, labels etc.. Unlike apiVersion & Kind, metadata is a dictionary. It is important to note that under metadata, you cannot have any property that you wish, only the once that are recognized by Kubernetes as metadata is allowed. However, under labels you can add any values that you wish to.
Spec is where is specify the information about the object, like the image that is needed to create the containter, name of the containter etc..
Once the file is created, run the command kubectl create -f {file-name}.yml & kubernetes will create the Object which is a POD in our case.
Let’s create a POD using the YAML File.
# the api version is v1 for a POD & the kind is Pod with capital P. it is case sensitive.
# metadata is a dictionary, we are defining the name of POD with the Name Keyword. labels is again a dictionary, which is just going to help us find stuff.
# Container is an Object & it has to have a name & the image is the one on dockerhub. a Pod can have more than one container.
apiVersion: v1
kind: Pod
metadata
name: nginx
labels:
app: nginx
tier: frontend
spec:
containers:
- name: nginx
image: nginx
- name: busybox
image: busybox
I already have an nginix pod running & this is yaml file I created.

Now we are going to use the kubectl create command & pass in the file name Also, I had to modify my pod name to nginx1 as I already have a pod running on that name.
