Set Limits for Resources in Kubernetes
Recently some of the performance issues were observed with some applications hosted on Kubernetes cluster. The Nautilus DevOps team has observed some resources constraints where some of the applications are running out of resources like memory, cpu etc., and some of the applications are consuming more resources than needed. Therefore, the team has decided to add some limits for resources utilization. Below you can find more details.
Create a pod named httpd-pod and a container under it named as httpd-container, use httpd image with latest tag only and remember to mention tag i.e httpd:latest and set the following limits:
Requests: Memory: 15Mi, CPU: 1
Limits: Memory: 20Mi, CPU: 2
Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.
[email protected]_host /$ cd /home/thor/ [email protected]_host ~$ vi podlimit.yml apiVersion: v1 kind: Pod metadata: name: httpd-pod spec: containers: - name: httpd-container image: httpd:latest resources: requests: memory: "15Mi" cpu: "1" limits: memory: "20Mi" cpu: "2"
[email protected]_host ~$ kubectl apply -f podlimit.yml pod/httpd-pod created [email protected]_host ~$ kubectl get pod NAME READY STATUS RESTARTS AGE httpd-pod 1/1 Running 0 8s [email protected]_host ~$ kubectl describe pod httpd-pod Name: httpd-pod Namespace: default Priority: 0 Node: node01/172.17.0.25 Start Time: Sat, 08 May 2021 02:29:40 +0000 Labels: <none> Annotations: <none> Status: Running IP: 10.244.1.2 IPs: IP: 10.244.1.2 Containers: httpd-container: Container ID: docker://bd0b509be028e06ed7bd09baa622634e896266875c49c0f1402f745a743d687f Image: httpd:latest Image ID: docker-pullable://[email protected]:79c67705b322b8284080d80fc825275d05ca48c5637a7302d3d92b79127b8df6 Port: <none> Host Port: <none> State: Running Started: Sat, 08 May 2021 02:29:47 +0000 Ready: True Restart Count: 0 Limits: cpu: 2 memory: 20Mi Requests: cpu: 1 memory: 15Mi Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-6b7f2 (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: default-token-6b7f2: Type: Secret (a volume populated by a Secret) SecretName: default-token-6b7f2 Optional: false QoS Class: Burstable Node-Selectors: <none> Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s node.kubernetes.io/unreachable:NoExecute op=Exists for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 27s default-scheduler Successfully assigned default/httpd-pod to node01 Normal Pulling 27s kubelet Pulling image "httpd:latest" Normal Pulled 22s kubelet Successfully pulled image "httpd:latest" in 4.763588155s Normal Created 21s kubelet Created container httpd-container Normal Started 21s kubelet Started container httpd-container [email protected]_host ~$