玩k8s? Pod的资源限制&重启策略

Pod 资源限制&重启策略

文章目录

  • Pod 资源限制&重启策略
    • 1.1: 资源限制
    • 1.2 重启策略
    • 1.3 健康检查

1.1: 资源限制

  • 官方文档

https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/

Pod资源配额有两种:

  • 申请配额:调度时使用,参考是否有节点满足该配置

    spec.containers[].resources.limits.cpu

    spec.containers[].resources.limits.memory

  • 限制配额:容器能使用的最大配置

    spec.containers[].resources.requests.cpu

    spec.containers[].resources.requests.memory

  • 容器资源限制:
    1、内存
    2、CPU

    limits:实际最大使用的配额

    requests:申请的配额,主要用于k8s做资源调度分配时参考值

    一般limits比requests大一些

  • 资源限制好处:避免某容器资源利用率异常突发影响其他容器,可能会产生雪崩效应!

  •   - name: wp
        image: wordpress
        resources:
          requests:
            memory: "64Mi"
            cpu: "250m"
          limits:
            memory: "128Mi"
            cpu: "500m"
    

示例:

[root@k8s-master1 demo]# vim resources.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" "请求内存64M"
        cpu: "250m" "一秒钟能够使用一个cpu核心资源的25%的资源"
      limits: "最大限制资源"
        memory: "128Mi" "最大限制内存128M"
        cpu: "500m" "一秒钟能够使用一个cpu核心资源的50%资源"
  - name: wp
    image: wordpress
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"
[root@k8s-master1 demo]# kubectl apply -f resources.yaml 
pod/frontend created
[root@k8s-master1 demo]# kubectl describe pod  frontend "查看创建过程"
[root@k8s-master1 demo]# kubectl get pods
NAME               READY   STATUS    RESTARTS   AGE
frontend           2/2     Running   0          2m39s
[root@k8s-master1 demo]# kubectl get pods -o wide
NAME       READY   STATUS    RESTARTS   AGE     IP            NODE        NOMINATED NODE   READINESS GATES
frontend   2/2     Running   0          3m55s   10.244.1.33   k8s-node1   <none>           <none>
[root@k8s-master1 demo]#  kubectl describe nodes k8s-node1
...
  Namespace                   Name                                          CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                   ----                                          ------------  ----------  ---------------  -------------  ---
  default                     frontend                                      500m (12%)    1 (25%)     128Mi (7%)       256Mi (14%)    4m42s
...
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests      Limits
  --------           --------      ------
  cpu                920m (23%)    1320m (33%)
  memory             1308Mi (76%)  1878Mi (109%)
  ephemeral-storage  0 (0%)        0 (0%)
  hugepages-1Gi      0 (0%)        0 (0%)
  hugepages-2Mi      0 (0%)        0 (0%)
Events:              <none>
[root@k8s-master1 demo]# kubectl get pods
NAME       READY   STATUS    RESTARTS   AGE
frontend   2/2     Running   0          6m9s
[root@k8s-master1 demo]# kubectl describe nodes 192.168.100.202 "查看节点信息"

[root@k8s-master1 demo]# kubectl get ns "查看命名空间"
NAME                   STATUS   AGE
default                Active   3d1h
ingress-nginx          Active   3d1h
kube-node-lease  

你可能感兴趣的:(Docker容器与K8s,kubernetes,docker,pod资源)