Open In App

How to Careate Static Pod in Kubernetes ?

Last Updated : 07 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Static pods in Kubernetes make it simple to run pods directly on individual cluster nodes without the Kubernetes API server being involved. Not at all like ordinary pods oversaw by the Kubernetes control plane, static pods are characterized and overseen straight by the Kubelet, the essential node agent answerable for overseeing units.

Creating a static pod involves defining a pod manifest file and placing it in a designated directory on the node’s file system. Upon startup, the Kubelet autonomously identifies and manages static pods based on the pod manifest files present in the specified directory. static means not movable and changing until external force applies static-pod servers like nginx, httpd, etc. Static pods are ideal for running infrastructure-related services, such as networking plugins or monitoring agents, that need to be tightly coupled with the node’s operation. Now, we are going to take you through the topics of Kubernetes, KOps, and Kubectl. In this guide, we will learn how to create a static pod in Kubernetes. In this article, we look forward to learning how to create a static pod in Kubernetes and how to access the pod.

What is Kubernetes?

As of now, many companies have already harnessed the power of Kubernetes. Kubernetes, also known as K8s,. In the digital world, managing applications efficiently is crucial. Kubernetes is an open-source container orchestration platform that excels at orchestrating containers, automating their deployment, scaling, and operations. Kubernetes offers advanced futures like auto-scaling, self-healing techniques, and load balancing. It simply handles the complex, containerized applications, making them manageable regardless of the infrastructure they reside on. In our own words, Kubernetes is a very powerful tool for managing containerized applications and can deploy containerized applications very simply and more securely. Here’s a breakdown of the key concepts and components of Kubernetes.

  • Control plane: It is the backbone and brain of operation, it manages the systems’ state, schedules applications, and configures the API server.
  • Pod: The smallest deployable unit in Kubernetes is a pod. A pod is a group of one or more containers that share resources and are deployed together on the same host. Containers within a pod share networking, storage, and unique IP addresses. They are ephemeral, meaning they can be replaced or scaled as needed
  • Static pod in Kubernetes: A static pod in Kubernetes is an extraordinary sort of pod that is overseen straight by the kubelet on a particular node, as opposed to being overseen by the Kubernetes programming interface server like a customary pod.
    • Static pods can be easily edited and deleted by navigating the static-pod path, which is /etc/kubernetes/manifest/.
    • Static pods are characterized by static pod manifests, which are YAML or JSON files put in a particular directory on the node where the kubelet is running.
  • Static-Pod Path: Static-pod path is an argument in Kubernetes configuration files only in Kubectl configuration files.
    • By default, this static-pod path is /etc/kubernetes/manifests/
  • API Server, Scheduler, and Controller Manager: These are components of the Kubernetes control plane that run on the master node. The API server provides the Kubernetes API, and the scheduler places pods on nodes. The controller manager verifies that the desired state of the cluster matches the actual state.
  • Flexibility: Kubernetes portability to host workloads on a single or multiple clouds It supports various container runtimes and can work with different infrastructures, be they public, private, or on-premises servers.

Static Pods vs. Demon Sets

Characteristics

Static Pods

Daemon Sets

Definition

Manually defined and managed by users

Automatically managed by Kubernetes

Pod Placement

Runs on specific nodes specified by user

Runs on all or specific nodes in the cluster

Management

managed by kubectl

managed by kubernetes API Automatically

Use Case

Testing, troubleshooting, specialized workloads

Running a single pod on every node, log collection, monitoring

Scaling

Not scalable

Scalable

Maintenance

Requires manual updates

Automatically updates

controlling

Not controlled by kubernetes master

Controlled by kubernetes master

Step by step to Create Static Pod in Kubernetes

Step 1: Login into AWS account

AWS management console

Step 2: Launch an EC2 instance

  • Navigate to ec2 dashboard.
  • Launch an ec2 instance with specifications AMI- amazonlinux2,type- t2.micro,8gb root volume- gp2 type.
  • Security groups – allow SSH(22),HTTPS(443),HTTP(80).
  • Connect this instance by using SSH secure shell.

Launch an EC2 instance

ssh -i "keypair" ec2-user2@<instance-public-ip address>compute-1.amazonaws.com

Step 3: Install kubectl and kubelet

  • Download the Kubelet and kubectl related packages and repositories from Kubernetes official site https://kops.sigs.k8s.io/getting_started/install/
    Install kubectl and kubelet
  • Successfully download kubectl and kubelet repos and keys then the install and setup the kubelet and the kubectl which is Kubernetes CLI tool.
sudo yum install -y kubectl

kubectl

sudo yum install -y kubelet

kubelet

Step 4: Create a YAML File to create static pod

  • Make the YAML file to create static case which will characterizes the determinations of the static pod. The YAML file ought to incorporate subtleties like the pod’s name, container determinations, labels, and some other arrangement required. Here is a example of YAML manifest for a NGINX static pod.
sudo vi static-pod.yml
apiVersion: v1
kind: Pod
metadata:
name: nginx-static-pod
spec:
containers:
- name: nginx
image: nginx:latest

static-pod.yml

Step 5: Move or Copy the Manifest

  • Here, we have to move our YAML file to manifest directory because the manifest directory directly controlled by kubectl and kubelet.
  • Settle on the node where you need to run the static pod. Every node in the Kubernetes cluster has a staticPodPath registry where static pods manifest are there. As a matter of course, this directory is /etc/kubernetes/manifest.
  • Move the YAML manifest file you made to create the staticPodPath registry on the chosen node. You can utilize the commands like scp or kubectl cp to copy or move files to the one. For example:
  • Here, We move the static-pod.yml record to the kubernetes manifest registry.
sudo mv static-pod.yml  /etc/kubernetes/manifest/

 /etc/kubernetes/manifest/

  • We can check the moved YAML file navigate to kubernetes’s manifest directory
cd /etc/kubernetes/manifest/
ls

Step 6: Verifying the created pod

  • When you have copy and moved the manifest YAML file to static-pod directory the Kubernetes will automatically detect and kubelet is going to run on the node to create the static pod according the specification you provide in manifest YAML file.
  • You can verify the running pod by execute the below command.
kubectl get pods

kubectl get pods

  • The command will list out the all the pods on kubernetes cluster
  • The output of created static pod is nginx-static-pod there you can see.

Step 7: Edit the static pod

  • You can edit the static-pod for this again you need to navigate to Kubernetes’s directory .
  • And there you see the previous static-pod.yml manifest file edit that file with the command.
sudo vi static-pod.yml

static-pod.yml

  • Configure this Yml file with your desired name and container name.
  • We configure with httpd static server
apiVersion: v1
kind: Pod
metadata:
name: httpd-static-pod
spec:
containers:
- name: httpd
image: httpd:latest

yaml

  • The kubernetes automatically detects the manifest file and kubelet runs the static-pod.
  • You can check the edited static-pod file.

list pods

Step 8: Delete the Static-pod

  • If you want to remove static-pod simple navigate to Kubernetes’s manifest directory where you place the static-pod manifest file simply remove the file.
  • The static-pod will be deleted
cd /etc/kubernetes/manifest/
sudo rm static-pod.yml

delete

  • Either simple execute the below command
kubectl delete pod <pod_name>

Static Pod in Kubernetes – FAQs

What is means static pod in kubernetes?

The smallest deployable unit in Kubernetes is a pod. Creating a static pod involves defining a pod manifest file and placing it in a designated directory on the node’s filesystem. Upon startup, the kubelet autonomously identifies and manages static pods based on the pod manifest files present in the specified directory.They are ephemeral,meaning they can be replaced or scaled as needed.

How do i create a static pod in kubernetes?

To create a static pod in kubernetes we need to download KOps and kubectl keys and repos from K8s official site and install kubectl in your system and then create a pod manifest file in a yaml format to describe your pod and finally apply this pod manifest file

How can i delete static pod in kubernetes?

we are able to delete static pod in kubernetes you need to remove its pod manifest file from the directory where the kubelet monitors for static pod definitions. after removing the manifest file the kubectl will stop managing the static pod.

Can we get the full information about the specified static pod in kubernetes?

Yes, we can get the all the about any specified pod or static pod in kubernetes by using.

  • kubectl describe pod <pod_name>
  • kubectl get pods –all-namespaces


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads