Kubernetes-Deploy your First Pod
Pods
• Basic scheduling unit in Kubernetes. Pods are often ephemeral
• Kubernetes doesn’t run containers directly; instead, it wraps one or more containers into a higher-level structure called a pod
• It is also the smallest deployable unit that can be created, scheduled, and managed on a Kubernetes cluster. Each pod is assigned a unique IP address within the cluster.
• Pods can hold multiple containers as well, but you should limit yourself when possible. Because pods are scaled up and down as a unit, all containers in a pod must scale together, regardless of their individual needs. This leads to wasted resources.
Ex: Nginx, MySQL, WordPress
• Any containers in the same pod will share the same storage volumes and network resources and communicate using localhost
• K8s uses YAML to describe the desired state of the containers in a pod. This is also called a Pod Spec. These objects are passed to the kubelet through the API server.
• Pods are used as the unit of replication in Kubernetes. If your application becomes too popular and a single pod instance can’t carry the load, Kubernetes can be configured to deploy new replicas of your pod to the cluster as necessary.
Scaling Pods
• All containers within the pod get scaled together.
• You cannot scale individual containers within the pods. The pod is the unit of scale in K8s.
• The recommended way is to have only one container per pod. Multi-container pods are very rare.
• In K8s, initcontainer is sometimes used as a second container inside pod.
Now we will understand How to deploy your first Pod:-
Firstly, we need to install the Minikube Cluster and start it. To install minikube cluster you can refer to my blog:
https://ketangrover.hashnode.dev/kubectl-and-minikube-cluster-installation
Now, we will start the cluster:
minikube start
Pods is just a YAML file in which we write the whole requirement. So, after starting our cluster we will create a new file pod.yml.
vim pod.yml
write the code inside your pod.yml file
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Here, in this file we have described some parameters accordingly to our needs like apiVersion, kind, name, image which describes the container image in our case we are using nginx and using container port as 80.
Now to run your pod use the command:
kubectl create -f pod.yml
Now, to check if your pod is created or not use the command:
kubectl get pods -o wide
Using this command you will get all the details of your pods like name, status, age, IP address, etc.
Now to curl your pod we will ssh or login to your minikube cluster for that:
minikube ssh
And then curl using your pod IP address :
curl 172.17.1.3
You will see a page "Thank you for using Nginx"
So Now your first ever Kubernetes application is created.
Now to delete the pod use the command:
kubectl delete pod nginx
That's a wrap................