0
0
Kubernetesdevops~30 mins

Cost optimization in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Cost optimization in Kubernetes
📖 Scenario: You are managing a Kubernetes cluster for a small company. The company wants to reduce cloud costs by optimizing resource usage of pods running in the cluster.You will create a simple Kubernetes pod manifest, add resource requests and limits, and then check the pod's resource usage to ensure cost optimization.
🎯 Goal: Build a Kubernetes pod manifest with resource requests and limits to optimize cost and ensure efficient resource usage.
📋 What You'll Learn
Create a pod manifest YAML file named cost-optimized-pod.yaml with a container named app-container running the image nginx:latest.
Add resource requests and limits for CPU and memory in the container spec.
Use kubectl commands to apply the manifest and check the pod's resource usage.
Print the pod's resource usage summary.
💡 Why This Matters
🌍 Real World
Cloud providers charge based on resource usage. Setting resource requests and limits in Kubernetes helps control costs by preventing pods from using more resources than needed.
💼 Career
DevOps engineers and site reliability engineers often optimize Kubernetes workloads to reduce cloud expenses while maintaining performance and reliability.
Progress0 / 4 steps
1
Create the initial pod manifest
Create a YAML file named cost-optimized-pod.yaml with a pod named cost-optimizer that has one container named app-container running the image nginx:latest. Include the apiVersion, kind, and metadata fields as shown.
Kubernetes
Need a hint?

Remember to include apiVersion, kind, metadata, and spec sections in your YAML.

2
Add resource requests and limits
In the cost-optimized-pod.yaml file, add resource requests and limits under the container app-container. Set CPU request to 100m, CPU limit to 200m, memory request to 128Mi, and memory limit to 256Mi.
Kubernetes
Need a hint?

Indent resource requests and limits correctly under the container spec.

3
Apply the pod manifest to the cluster
Use the kubectl apply -f cost-optimized-pod.yaml command to create the pod in the Kubernetes cluster.
Kubernetes
Need a hint?

Use kubectl apply -f cost-optimized-pod.yaml to create or update the pod.

4
Check and print pod resource usage
Run the command kubectl top pod cost-optimizer to display the CPU and memory usage of the pod. Then print the output exactly as shown.
Kubernetes
Need a hint?

Use kubectl top pod cost-optimizer to see current CPU and memory usage.