Hi let us understand some additional detail about pods. Already we do have
minikube installed and we do have the kubectl client. I'm going to start a pod and
see how I can leverage kubectl to explore the functionalities available as a part of
pod. I do have the system where the minikube is installed and everything is
running fine and kubectl is also very well configured. Now I'm going to start a
sample pod and there are n number of ways to start the pod I'm going to use the
easiest way to start the pod by providing an image name. I will use the kubectl
run command and I will give a name of the pod and generator I will mention it as
run pod version 1. The api what we are going to use over here don't worry
as of now we will have a detailed discussion, this is to have little more
understanding on the pod, so that we can explore various objects available as a
part of kubernetes. I'm using the run command of kubectl and I'm providing
a name and generator that is the api version and image I wanted to use is
nginx. So the pod will get created, I'm going to use the command
kubectl, get pods. That's going to list all the pods available as a part of the default
namespace. Now I am introducing another terminology namespace
namespace is nothing but a logical consolidation of objects together. I can
create my own custom namespace or use the default namespace as of now I
am going to use the default namespace and there is a system namespace
already available where all the system related objects will be running within this
system namespace. Here I do have the name of the pod and the status that is
one pod needs to run and it's getting ready the status container it is getting
created and it was created 8 seconds ago. Let me go ahead and list the pods
yes, it is up and running and it did not get restarted any time from the beginning
and it is up and running for 74 seconds. Now I can get more details about this
particular pod by providing the command describe. kubectl describe
pods and the name of the pod. I will have all the information about the pod in
terms of what is the IP address in which node it is running and it's going to run in
only one node as I do have minikube and it will be running in one single node, the IP
address of the pod and what is the container running within it, as we
discussed earlier one pod can have n number of containers, what is the idea of
the container what image it is using and what is the state of that specific
container, what are all the ports it is exposing and different parameters for that
particular container and it is going to provide the output in yaml format
and I do have different events in terms of how that particular pod got started what
are all the events happened within that particular pod I can get those details. Now to have better understanding visually
I am going to draw the pod unit over here, so what happened on top of minikube a
pod got created, within pod a container got created, that got an IP address as
this. So what did we do we created a pod quickly using the kubectl run command
where the pod got created and a container is running within it. We do not
have much control in terms of what port to expose how to label this pods and it's
all going to be much difficult where I can go ahead and use a yaml file with
declaratively I can define how that particular pod should behave what are all
its properties and how to communicate with the pod using the kubectl. Let me go
ahead and delete this specific pod and create a new pod using yaml file. I'm
going to delete the pod, kubectl delete pod and the name of the pod. The pod is
getting deleted. Now let me go ahead and list the pods there are no pods available
as a part of default namespace, now let me go ahead and create a yaml file so
that I can create the entire resources available as a part of the yaml file. I'm
going to name the file as, I will be adding this specific yaml file as it is within the
resources so that you can download and use it as it is. As we discussed earlier as a
part of the yaml discussion we are going to have four important keys api version,
kind, metadata and spec. I'm going to create an object called pod and the api
version I'm going to use is version 1 and metadata I'm giving name of this
particular pod that I wanted to create as nginx yaml and within specifications
I'm going to have containers and within containers, I do have only one element
which will have an image nginx and it will have the name nginx and I'm going
to expose the port 80. I can get more details about the pod and it's a syntax
within the reference of kubernetes website. I can get into the kubernetes api
the latest version is version 1.18 within that you can get into pod v1 core, here
I do have the information on what are all the fields it can have api version, kind
metadata, spec and status. So here I'm going to have the spec as pod
specifications, if I get into the pod spec I will have details on what are all fields it
can have. The fields I'm going to have is containers and container is going to have
detail about the container and it is going to be of type array. If I check the details
about the container it will have information on what are all the fields it
can have, the fields that we have is about images and what are all ports it can open
again container port it's going to be of type array I can get into the container
port and get the details on what are all the fields it can have. So the api is having
the complete details on how the yaml file can be constructed and what are all
informations or the fields it can have. So if I get into this pod nginx, I do have the
specifications within that I had containers and I have the details about
image, name, ports and ports going to have details about the container port
name and other information. So that's what it's mentioned over here, container
port name and in case if you wanted to specify the protocol or any host
IP address to which I wanted to bind, I can mention all this information. Now I do
have the pod definition using a yaml file, now I am going to create a pod, I will
be using the command apply, kubectl apply and use the file, pod nginx.yaml
The pod will get created, now let me go ahead and list the pods, kubectl get pods. So I do
have one pod with a name nginx-yaml up and running. Let me go ahead and
describe the pod, kubectl describe pods nginx yaml. So I will be having all the
information about how I requested the pod to get created. So it got created
within the default namespace and this is the IP address and it is using the image
nginx and the port 80 is exposed from the container. So this nginx is exposing
the port 80. In the next lecture we will see how to access this particular port and
delete the pod using the file and what are all its advantages. So in a quick
summary we saw how to create a pod using the run command as well as using
the apply command and what are all its differences and how to get
the details about the pod using the describe command.