DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 50

Creating a Kubernetes Pod with Resource Limits

This article outlines the steps to create a Kubernetes pod named httpd-pod with a container named httpd-container that has specific resource requests and limits for CPU and memory.

Step 1: Create the Pod Configuration File

First, you need to create a YAML file that defines the pod's specification, including its resource constraints. Use a text editor like vi to create a file named pod-resource-limits.yaml.

thor@jumphost ~$ vi pod-resource-limits.yaml
Enter fullscreen mode Exit fullscreen mode

Paste the following content into the file:

apiVersion: v1
kind: Pod
metadata:
  name: httpd-pod
spec:
  containers:
  - name: httpd-container
    image: httpd:latest
    resources:
      requests:
        memory: "15Mi"
        cpu: "100m"
      limits:
        memory: "20Mi"
        cpu: "100m"
Enter fullscreen mode Exit fullscreen mode
  • requests: This specifies the minimum amount of resources the container needs. The Kubernetes scheduler uses these values to decide which node is suitable to run the pod.
  • limits: This sets the maximum amount of resources the container can consume. If the container exceeds the memory limit, it will be terminated. If it exceeds the CPU limit, its processing will be throttled.

Step 2: Apply the Configuration

Use the kubectl apply command to apply the YAML file to your Kubernetes cluster. This command reads the configuration and creates the pod.

thor@jumphost ~$ kubectl apply -f pod-resource-limits.yaml
pod/httpd-pod created
Enter fullscreen mode Exit fullscreen mode

The output pod/httpd-pod created confirms that the pod has been successfully submitted to the cluster.

Step 3: Verify the Pod's Status

Finally, verify that the pod is running correctly by using the kubectl get pods command. This command shows the current state of pods in your cluster.

thor@jumphost ~$ kubectl get pods httpd-pod
NAME        READY   STATUS    RESTARTS   AGE
httpd-pod   1/1     Running   0          72s
Enter fullscreen mode Exit fullscreen mode

The output shows that the pod's status is Running and the READY state is 1/1, indicating that its container is ready and operational. This confirms the successful completion of the task.

Top comments (0)