In this demo, we're going to create a pod again
but this time, instead of making use of the kubectl run command,
we're going to create it using a YAML definition file.
Our goal is to create a YAML file with the pod specifications in it.
Now, there are many ways to do it.
You could just create one in any text editor.
If you're on windows, you could just use Notepad.
If you're on Linux as I am, just use a native editor like Vi or Vim.
An editor with support for YAML language
would be very helpful in getting the syntax right.
Instead of Notepad, a tool like Notepad++ in Windows
or Vim in Linux would be better.
Now, I'll talk more about tips and tricks and other tools and ideas
that can help with this more in the upcoming lectures.
For now, let's take with the very basic form of creating a YAML file
using a VI editor on my Linux system.
Here I am on my Linux terminal,
and I'm going to make use of a Vim text-based editor to create this pod definition file.
The name of the file, I'm going to call as pod.yaml,
and as seen in the lecture,
we will start off with the four root level elements
or the root level properties that we saw
which are API version kind metadata and spec.
We know that the value for API version for a pod is V1,
the kind is a Pod with a capital P.
It is case-sensitive, that's important.
Metadata is a dictionary and it can have values where we define the name of the pod.
I'm going to use name as NGINX
and we can have additional labels that we can specify under it.
Labels, again, is also a dictionary and it can have as many labels as you want under it.
We can specify a label which is a key-value pairs, just a app and NGINX.
We can also add more labels like tier and set it to front end,
anything that can help us group this particular pod.
Next, we have to define the spec. Spec is also a dictionary.
It has an object called containers.
Before we move on to that,
we have to make sure that we get the indentation right.
For example, the app and tier are children of the labels property.
It has to be in the same vertical line here.
Similarly, under metadata,
you have name and labels which are the children of metadata.
They both have to be within the same vertical line.
You have to make sure that the spacing is correct.
Typically, it would be two spaces or a tab, but it is recommended not to use tabs.
Always stick to two spaces and stick to that throughout.
The next thing that we're going to configure is the container.
A container is a list of objects.
Now, we first give it a name.
Note that this is the name of the container within the pod,
and there could be multiple containers and each can have a different name.
One container could be named app and another container could be named helper.
Any name that makes sense to you,
we're going to use the same name as that of the container image.
We will just name it, NGINX.
The second object that we're going to add here is the image name,
which is the Docker Hub image name of the container that we're going to create.
The image name is again, NGINX.
If you're using other registries than Docker Hub,
then make sure to specify the full path to that image repository here.
Now, remember that we can add additional containers to the pod as well.
If you have to do that, we have to declare the secondary element to the list,
which would be the second object in the list.
Here, I can, for example, add a BusyBox container using the BusyBox image,
and that would be the second element of theory.
In this case, we're going to stick to one single container.
I'm going to just delete that.
I'm now going to hit Escape:wq to save this file.
We will just use the cut command
to make sure that the file was created with the expected contents.
Make sure the format is correct.
The name and labels are children of metadata,
and you can see that they are on the same vertical line.
Similarly, labels have two children which are the two labels, app and tier.
Spec has a list, and we are defining it as a list with a hyphen followed by the objects.
We can make use of the kubectl create command or the kubectl apply command.
The create and apply command works the same.
If you're creating a new object, you can either use create or use apply.
It doesn't matter.
We passing the file name using the -f option.
Here, we can see that the pod has been created.
Let's check the status real quick.
You can see that it's in ContainerCreating state,
then when we check again, we see that it's in a running state.
As before, if you want to get more details about the pod,
you can always run the kubectl describe command and specify the name of the pod.
You should get a much more in-depth information about the pod.
That's it for this demo.
In the next section, we will learn some tips and tricks
of developing YAML files easily using IDEs.