Hi, In the earlier lecture we saw how to create a pod using a yaml file. Now
I do have the pod up and running and I'm going to see the options how to access
these pods. As we did the describe of this particular pod, it is exposing the port 80
from the container. Now let us see how to access this particular port from the
host. I do have this host and I'm going to run a command port forward, so that
whenever the host is receiving any request from the port 80 it will be
forwarded to the port 80 of this specific pod. So I'm going to use the command
port forward and I'm going to mention address as 0.0.0.0 that means the
request coming from any host and whenever it is getting the request in
port 80 it will be forwarded to the port 80 of this specific pod and this is not the
right way to forward the request, I'm doing it so that to get an understanding
how the port mapping going to happen. So what I have done I have started a
small port forward requests, so any requests that is coming in port 80 will be
forwarded to this particular container into port 80. Now I can access this
particular host and check whether it's serving in port 80 or not. So the host IP
address is 192.168.0.51 and in port 80, so I'm getting the welcome page of nginx.
and as I mentioned earlier this is not the right way to forward the request for that
we will be creating something called services and it will be having a load
balancer in the front end and only that specific load balancer IP address will be
exposed to the outside world. We will be having all the pods in the abstracted
layer, we will be discussing more in detail about how to expose the pods to the
outside world later when we are discussing about services. Now let us see
the other options of how to access the specific pod using the bash shell I can
use the exec command kubectl exec and I wanted to do it in the interactive mode
and provide the pod name and I want to execute the bash shell within it. So now
I am into the bash shell and these are all the content available within
the bash shell within the pod I can get into the location this is having
index.html and this is what it is getting served by default whenever I am
accessing the homepage of nginx this is just to quickly show how I can access
the pod and pod is nothing but it is just another container where it is running with
some base image and it is abstract container by itself. Now in case if I wanted
to copy any specific file from my local file system to the container or the
specific pod I can go ahead and do that. Generally this is also not recommended
the reason because most of the time I will be expecting the container to be in
the immutable state any change to be done I will be making the change to the
image and create a new container or deploy a new container but for
debugging purposes or for some reason if I wanted to copy some file I can go
ahead and do that, let me create a file within the container, so I'm going to get
into the container, let me create a directory get in to the directory and
create a file called 1.txt and within that I do have a text like file copy test
So what I have done within the container I created a text file with the name 1.txt
I'm going to copy this particular file from the container to the host storage or the
host hard disk. I can do the other way as well I can copy any files from the host to
the container also. Only difference will be within the copy command the source and
destination will be different. Now using the kubectl command I am going to copy
the file from the container to the host, I will be mentioning the container file
1.txt as the source and target within the host. If I want to copy the file from the
host to the container I will be mentioning the hosts file as the source and target as
within the container by providing the container name. Let me issue the
command using the kubectl, kubectl copy and then the name of the pod and
the location where the file is available within the pod and the target. The file
should get copied, let me check this specific location I do have the file one.txt
same content is available, don't worry about this specific error message, it's not
even error message it's just a warning because I am doing the copy being within
that specific location, so it is providing that info message, now what I have done
I have copied a file from the container to the host location. So in a quick summary
we had seen how to expose a port from the container to the host and how to
access that specific port and how to access the pod using the bash shell as
well how to copy a file between the container and the host file system.