K8s – Question21

Use context: kubectl config use-context k8s-c3-CCC

Create a Static Pod named my-static-pod in Namespace default on cluster3-controlplane1. It should be of image nginx:1.16-alpine and have resource requests for 10m CPU and 20Mi memory.

Then create a NodePort Service named static-pod-service which exposes that static Pod on port 80 and check if it has Endpoints and if it’s reachable through the cluster3-controlplane1 internal IP address. You can connect to the internal node IPs from your main terminal.

Creating and Exposing a Static Pod in Kubernetes

In Kubernetes, static Pods are managed directly by the kubelet on a node, rather than the control plane. This makes them ideal for essential system components or services that need to run outside of Kubernetes’ usual orchestration process. In this guide, we’ll walk through the steps to create a static Pod, add resource requests, and expose it as a service.

Step 1: Creating the Static Pod

To create a static Pod, we first need to generate a Pod manifest and place it in the directory that the kubelet watches for static Pods. In most Kubernetes setups, this directory is /etc/kubernetes/manifests/. Start by SSHing into your control plane node:

Navigate to the /etc/kubernetes/manifests/ directory:

Create the Pod manifest using the following command:

This command generates a basic Pod YAML manifest named my-static-pod.yaml for a Pod running the nginx:1.16-alpine image.

Step 2: Adding Resource Requests

Next, we’ll edit the generated YAML file to include resource requests for CPU and memory. Open the file in your preferred text editor:

Modify the file to include the following resource requests:

Save and close the file. The kubelet will automatically detect this file and create the Pod.

Step 3: Verifying the Static Pod

To verify that the static Pod is running, use the following command:

Example output:

The Pod should now be up and running, managed directly by the kubelet.

Step 4: Exposing the Static Pod as a Service

To allow access to the static Pod, we need to expose it as a service. Run the following command to create a NodePort service:

This will create a service that exposes the static Pod on a specific port. The generated service YAML will look like this:

Verify the service and its associated endpoints:

You should see output similar to the following:

The static Pod is now accessible via the service.

Conclusion

In this guide, we demonstrated how to create a static Pod in Kubernetes, add resource requests, and expose the Pod as a service. Static Pods are useful for running essential components on specific nodes, and understanding how to manage them is crucial for maintaining a robust Kubernetes environment.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *