Kubernetes Pod 资源限制

Kubernetes Pod 资源限制

官方文档:https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/

Pod和Container的资源请求和限制:
• spec.containers[].resources.limits.cpu
• spec.containers[].resources.limits.memory
• spec.containers[].resources.requests.cpu
• spec.containers[].resources.requests.memory

1、创建测试实例
vim pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: frontend
spec:
  containers:
  - name: db
    image: mysql
    env:
    - name: MYSQL_ROOT_PASSWORD
      value: "password"
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"
  - name: wp
    image: wordpress
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"

2、查看pod创建实例

NAME                              READY   STATUS    RESTARTS   AGE
frontend                          2/2     Running   1          63s
kubectl get pods

3、查看pod详情,找到分配到的Node

kubectl describe pod frontend

4、Node 跑的Pod资源利用率

kubectl describe nodes 192.168.1.111

.....
 Kube-Proxy Version:         v1.12.1
Non-terminated Pods:         (4 in total)
  Namespace                  Name                               CPU Requests  CPU Limits  Memory Requests  Memory Limits
  ---------                  ----                               ------------  ----------  ---------------  -------------
  default                    frontend                           500m (12%)    1 (25%)     128Mi (9%)       256Mi (18%)
  default                    nginx-7b67cfbf9f-p8d69             0 (0%)        0 (0%)      0 (0%)           0 (0%)
  default                    nginx-7b67cfbf9f-xlvnz             0 (0%)        0 (0%)      0 (0%)           0 (0%)
  default                    nginx-deployment-d55b94fd-rpsgm    0 (0%)        0 (0%)      0 (0%)           0 (0%)
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
# 限制说明 
  Resource                       Requests    Limits
  --------                       --------    ------
  cpu                            500m (12%)  1 (25%)
  memory                         128Mi (9%)  256Mi (18%)
  attachable-volumes-azure-disk  0           0
Events:                          <none>
详情

 

注:limits是对资源的总限制、requests是最低分配的资源。requests一般要比limits要小一些。

注:250m/单核CPU的白分之25/0.25

注:资源限制 cpu可以直接设置为数字 “1”为1核“2”为2核。

posted @ 2019-08-26 15:44  kevin.Xiang  阅读(3236)  评论(0编辑  收藏  举报