Step 1: Create a Namespace
First, ensure that the namespace where you want to deploy the pods exists. Let’s create a namespace named example-namespace
:
kubectl create namespace example-namespace
Step 2: Prepare the YAML Configuration
Create a YAML file that will define the three pods. You can name this file three-pods.yaml
. Here’s the content you should put into this file:
apiVersion: v1 kind: Pod metadata: name: pod1 namespace: example-namespace spec: containers: - name: container1 image: nginx resources: requests: memory: "500Mi" cpu: "1" limits: memory: "2Gi" cpu: "2" --- apiVersion: v1 kind: Pod metadata: name: pod2 namespace: example-namespace spec: containers: - name: container2 image: nginx resources: requests: memory: "500Mi" cpu: "1" limits: memory: "2Gi" cpu: "2" --- apiVersion: v1 kind: Pod metadata: name: pod3 namespace: example-namespace spec: containers: - name: container3 image: nginx resources: requests: memory: "500Mi" cpu: "1" limits: memory: "2Gi" cpu: "2"
Step 3: Apply the YAML Configuration
Apply the YAML file to your Kubernetes cluster to create the pods:
kubectl apply -f three-pods.yaml
Step 4: Verify the Pods
Check that the pods have been created and have the correct resource allocations:
kubectl get pods -n example-namespace kubectl describe pods -n example-namespace
These commands will show you the status of each pod and detailed information, including the resource requests and limits set for CPU and memory.
Step 5: Monitoring and Management
Once your pods are running, you might want to monitor their performance and usage:
- Use
kubectl top pods -n example-namespace
to see the current CPU and memory usage. - Adjust the requests and limits as necessary based on the performance and requirements.
Notes:
- Image: In this example, the
nginx
image is used. You can replace this with any image suitable for your application. - Namespace: This setup assumes that you are working within the
example-namespace
. If you use a different namespace, make sure to replaceexample-namespace
with your specific namespace in all commands and configurations. - Resource Adjustment: If you find that the resource allocations are too high or too low based on actual usage, you can adjust the values in the YAML file and reapply it.
By following these steps, you can successfully set up and manage resource-limited pods in your Kubernetes cluster.
No comments:
Post a Comment