Day 3: Why kubernetes pods and deploy your first pod using minikube and kubectl
When we had docker where we can run our containers successfully why do we need to install application using pod?
Because unlike docker where we pass arguments in command line, in kubernetes we put them in a YAML file which consist of specified information about the container.
But the question arises is why kubernetes has to deal with complexity of running YAML files?
Because kubernetes is enterprise level platform i.e. it will aim to bring declarative capabilities or standardization.
These pods act as a wrapper which consist of single container or multiple containers, but why we put group of containers in a single pod?
For e.g. Container 1 application wants to connect and read files from container 2 So, in such cases instead of creating 2 different pods one for each container they can be stored in a single pod which will give them some advantages, or we can say edge over containers in a multiple pod.
These advantages can be:
Shared networking
Shared storage etc.
This way container 1 & 2 within a single pod can communicate using local host.
Kubernetes allocates a cluster IP address provided by Kube proxy which can be used to access application inside this pod.
But why are these pods required?
Pods is basically a wrapper created for container which makes it easier to deal with the situation when there are 100’s of container in a production unit, this wrapper defines all the standardization in a YAML file.
Now than we know significance of pods lets create our first pod.
Just like how we need docker cli for our containers to run we need a runtime environment for kubernetes also.
Kubectl- it is a command line tool of kubernetes.
For creating our first pod we need to install kubectl for which you can visit Install Tools | Kubernetes and depending upon your system you can simply run the command given below in your terminal.
Once your kubectl is successfully installed verify by running kubectl version to know the version and successful installation.
After your kubectl you will require a tool called minikube install minikube from minikube start | minikube (k8s.io) and after successful installation run minikube version to verify the installation.
Right now, you only have minikube not a kubernetes cluster for that run
/minikube start
kubernetes cluster will be started. but the only difference is if you are just doing minikube start then the kubernetes cluster will by default use your Docker driver okay but docker driver.
After that run
/kubectl get nodes
when you do kubectl get notes you will notice that kubectl is already connected to your kubernetes cluster where you’ll be able to see your node by name ‘minikube’ along with its status and role.
Now you can start with the installation of pod from Pods | Kubernetes from here you copy the default pod.yml file. and save it.
after that run: kubectl create -f pod.yml
you’ll be able to your newly created pod.
To see your application inside a pod run kubectl get pods
and to know the entire details of your pod simply run: kubectl get pod -o wide
where you’ll get all the details such as IP address, status of your pod etc.
Now to login to your cluster run: minikube ssh
and inside your cluster simply run: curl [IP address]
of your pod, you’ll notice your application is running.
By this way your first beginner level kubernetes application is created.
Subscribe to my newsletter
Read articles from Divyanshi Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by