How to create the POD in K8s?
In this blog, we will show you the steps to create your first POD in Google Kubernetes Environment.
- 2 Node Cluster ( 1 Master VM with 2 Nodes)
- Kubernetes Components
- Firstly, we need to install and configure the 2-node cluster in our environment. We had already installed and configured the 2 Node cluster in our demo environment. To learn more check our blog post.
Working with PODs
- The smallest unit of scheduling in the kubernetes world is POD.
- PODs can contain one or more containers.
- We deploy a POD in a cluster using the manifest file.
- We provide the manifest file to the API server. It will be scheduled to deploy in a node. Based on the manifest file, the POD will have one (or) more containers.
- irrespective of how many containers are inside a POD, the POD will get only a single IP. It’s like one IP to one POD relationship.
- Every container inside a POD shares a single Network Namespace.
- All the containers inside POD share the same CGROUP Limits, Volumes, Network and IPC namespaces.
Inter POD Communication
- All the POD addresses are fully routable on the POD Network.
- Every POD gets its own IP and it’s routable to that Network.
- PODs can communicate with each other without any port mapping.
Intra POD Communication
- Inside the POD, the multiple containers will communicate through a shared local network interface.
- The containers will be available outside the POD by exposing them through ports.
- Two containers cannot use the same port.
- Pods will either run as fully functional (or) it’s down completely.
- First, we will create a manifest file (YAML or JSON) about POD and container information.
- Provide the manifest file to the API server and it will get scheduled to a node.
- Once it’s scheduled, it goes into a Pending state. During this time it will be downloading the images and files.
- It will be in a pending state till all the containers are up and running.
- After the containers are up and running, They change to a running state.
- Once it’s completed its job, it changes the status to succeed.
- If it’s holding on to a pending state (or) Crashed for a long time, then it will be changed to a failed state.
- We cannot bring back the death POD. Need to replace them with a new one.
Creating a Manifest file
- Log in to the Kubernetes master server through Putty.
- Create a new manifest file using the vi editor.
Note: We are using the YAML type to create the manifest files
- We are using the Ngnix image for this demo purpose. Add the below code in the YAML file.
- name: hello-ctr
- Save and close the file.
Note: Make sure that the manifest will be on right YAML format. Or else, it will show the error during POD deployment.
Deploying the POD
kubectl create -f pod.yml
- A new POD will be created in a few seconds.
- We can get the PODs status using the below command.
kubectl get pods
- You can also get the POD events information through the describe command.
kubectl describe pods <pod name>
- You can find the POD IP using the wide option.
kubectl get pods -o wide
- We can able to browse the container using the POD IP inside the cluster.
curl -v http://<Pod IP>