WEBVTT

00:00.000 --> 00:04.080
In this demo,
we're going to create a pod again

00:04.080 --> 00:08.820
but this time, instead of making use
of the kubectl run command,

00:08.820 --> 00:12.460
we're going to create it
using a YAML definition file.

00:12.460 --> 00:18.140
Our goal is to create a YAML file
with the pod specifications in it.

00:18.140 --> 00:20.620
Now, there are many ways to do it.

00:20.620 --> 00:24.820
You could just create one in any text editor.

00:25.010 --> 00:27.720
If you're on windows,
you could just use Notepad.

00:27.720 --> 00:33.200
If you're on Linux as I am,
just use a native editor like Vi or Vim.

00:33.200 --> 00:35.880
An editor with support for YAML language

00:35.880 --> 00:40.480
would be very helpful
in getting the syntax right.

00:40.480 --> 00:45.330
Instead of Notepad,
a tool like Notepad++ in Windows

00:45.330 --> 00:48.560
or Vim in Linux would be better.

00:48.560 --> 00:52.740
Now, I'll talk more about tips and tricks
and other tools and ideas

00:52.740 --> 00:57.890
that can help with this more
in the upcoming lectures.

00:57.890 --> 01:04.210
For now, let's take with the very basic form
of creating a YAML file

01:04.210 --> 01:07.680
using a VI editor on my Linux system.

01:07.680 --> 01:10.090
Here I am on my Linux terminal,

01:10.090 --> 01:15.960
and I'm going to make use of a Vim text-based
editor to create this pod definition file.

01:15.960 --> 01:20.090
The name of the file,
I'm going to call as pod.yaml,

01:20.090 --> 01:22.000
and as seen in the lecture,

01:22.000 --> 01:26.000
we will start off
with the four root level elements

01:26.000 --> 01:28.800
or the root level properties that we saw

01:28.800 --> 01:33.130
which are API version kind
metadata and spec.

01:33.650 --> 01:39.130
We know that the value
for API version for a pod is V1,

01:39.130 --> 01:42.970
the kind is a Pod with a capital P.

01:44.140 --> 01:47.930
It is case-sensitive, that's important.

01:47.930 --> 01:53.240
Metadata is a dictionary and it can have
values where we define the name of the pod.

01:53.240 --> 01:56.300
I'm going to use name as NGINX

01:56.300 --> 02:01.740
and we can have additional labels
that we can specify under it.

02:01.740 --> 02:08.480
Labels, again, is also a dictionary and it
can have as many labels as you want under it.

02:08.480 --> 02:14.420
We can specify a label which is
a key-value pairs, just a app and NGINX.

02:14.420 --> 02:21.140
We can also add more labels
like tier and set it to front end,

02:21.140 --> 02:24.890
anything that can help us group
this particular pod.

02:25.160 --> 02:30.540
Next, we have to define the spec.
Spec is also a dictionary.

02:30.540 --> 02:33.020
It has an object called containers.

02:33.020 --> 02:34.840
Before we move on to that,

02:34.840 --> 02:38.970
we have to make sure
that we get the indentation right.

02:38.970 --> 02:44.090
For example, the app and tier
are children of the labels property.

02:44.090 --> 02:48.040
It has to be in the same vertical line here.

02:48.040 --> 02:50.120
Similarly, under metadata,

02:50.120 --> 02:53.720
you have name and labels
which are the children of metadata.

02:53.720 --> 02:58.410
They both have to be
within the same vertical line.

02:58.410 --> 03:01.290
You have to make sure
that the spacing is correct.

03:01.290 --> 03:08.260
Typically, it would be two spaces or a tab,
but it is recommended not to use tabs.

03:08.260 --> 03:13.320
Always stick to two spaces
and stick to that throughout.

03:13.320 --> 03:17.400
The next thing that
we're going to configure is the container.

03:17.400 --> 03:20.320
A container is a list of objects.

03:20.320 --> 03:22.480
Now, we first give it a name.

03:22.480 --> 03:26.450
Note that this is the name
of the container within the pod,

03:26.450 --> 03:30.890
and there could be multiple containers
and each can have a different name.

03:30.890 --> 03:36.680
One container could be named app and
another container could be named helper.

03:36.680 --> 03:39.200
Any name that makes sense to you,

03:39.200 --> 03:42.720
we're going to use the same name
as that of the container image.

03:42.720 --> 03:45.650
We will just name it, NGINX.

03:46.900 --> 03:50.960
The second object that
we're going to add here is the image name,

03:50.960 --> 03:55.730
which is the Docker Hub image name
of the container that we're going to create.

03:56.420 --> 03:59.620
The image name is again, NGINX.

04:00.120 --> 04:02.780
If you're using other registries
than Docker Hub,

04:02.780 --> 04:08.400
then make sure to specify the full path
to that image repository here.

04:08.640 --> 04:13.120
Now, remember that we can add
additional containers to the pod as well.

04:13.120 --> 04:19.200
If you have to do that, we have to declare
the secondary element to the list,

04:19.200 --> 04:21.840
which would be the second object in the list.

04:21.840 --> 04:27.050
Here, I can, for example, add a BusyBox
container using the BusyBox image,

04:27.050 --> 04:29.890
and that would be
the second element of theory.

04:30.810 --> 04:35.080
In this case, we're going to stick
to one single container.

04:35.080 --> 04:37.760
I'm going to just delete that.

04:40.250 --> 04:45.440
I'm now going to hit Escape:wq
to save this file.

04:45.440 --> 04:47.570
We will just use the cut command

04:47.570 --> 04:52.570
to make sure that the file was created
with the expected contents.

04:52.690 --> 04:54.860
Make sure the format is correct.

04:54.860 --> 04:58.200
The name and labels
are children of metadata,

04:58.200 --> 05:02.850
and you can see that
they are on the same vertical line.

05:02.850 --> 05:07.610
Similarly, labels have two children
which are the two labels, app and tier.

05:07.610 --> 05:15.730
Spec has a list, and we are defining it as
a list with a hyphen followed by the objects.

05:18.250 --> 05:23.840
We can make use of the kubectl create command
or the kubectl apply command.

05:23.840 --> 05:27.970
The create and apply command works the same.

05:28.610 --> 05:33.660
If you're creating a new object,
you can either use create or use apply.

05:33.660 --> 05:35.130
It doesn't matter.

05:35.690 --> 05:40.160
We passing the file name using the -f option.

05:40.160 --> 05:43.690
Here, we can see
that the pod has been created.

05:43.690 --> 05:46.580
Let's check the status real quick.

05:47.120 --> 05:50.380
You can see that
it's in ContainerCreating state,

05:50.380 --> 05:53.610
then when we check again,
we see that it's in a running state.

05:53.610 --> 05:56.260
As before,
if you want to get more details about the pod,

05:56.260 --> 06:01.890
you can always run the kubectl describe
command and specify the name of the pod.

06:01.890 --> 06:06.500
You should get a much more
in-depth information about the pod.

06:06.500 --> 06:08.420
That's it for this demo.

06:08.420 --> 06:12.050
In the next section,
we will learn some tips and tricks

06:12.050 --> 06:17.260
of developing YAML files easily using IDEs.

