zoukankan      html  css  js  c++  java
  • k8s 资源限制QoS

    kubernetes 创建pod时就给他指定了下列一种 QoS 类:

    • Guaranteed
    • Burstable
    • BestEffort

    创建命名空间

    创建一个命名空间,以便将本练习所创建的资源与集群的其余资源相隔离。

    kubectl create namespace qos-example
    

    创建一个 QoS 类为 Guaranteed 的 Pod

    对于 QoS 类为 Guaranteed 的 Pod:

    • Pod 中的每个容器都必须指定内存限制和内存请求。
    • 对于 Pod 中的每个容器,内存限制必须等于内存请求。
    • Pod 中的每个容器都必须指定 CPU 限制和 CPU 请求。
    • 对于 Pod 中的每个容器,CPU 限制必须等于 CPU 请求。

    这些限制同样适用于初始化容器和应用程序容器。

    下面是包含一个容器的 Pod 配置文件。 容器设置了内存请求和内存限制,值都是 200 MiB。 容器设置了 CPU 请求和 CPU 限制,值都是 700 milliCPU:

    apiVersion: v1
    kind: Pod
    metadata:
      name: qos-demo
      namespace: qos-example
    spec:
      containers:
      - name: qos-demo-ctr
        image: nginx
        resources:
          limits:
            memory: "200Mi"
            cpu: "700m"
          requests:
            memory: "200Mi"
            cpu: "700m"
    

    创建 Pod:

    kubectl apply  -f -n qos-example
    

    查看 Pod 详情:

    kubectl get pod qos-demo --namespace=qos-example --output=yaml
    

    创建一个 QoS 类为 Burstable 的 Pod

    如果满足下面条件,将会指定 Pod 的 QoS 类为 Burstable:

    • Pod 不符合 Guaranteed QoS 类的标准。
    • Pod 中至少一个容器具有内存或 CPU 请求。

    面是包含一个容器的 Pod 配置文件。 容器设置了内存限制 200 MiB 和内存请求 100 MiB。

    apiVersion: v1
    kind: Pod
    metadata:
      name: qos-demo-2
      namespace: qos-example
    spec:
      containers:
      - name: qos-demo-2-ctr
        image: nginx
        resources:
          limits:
            memory: "200Mi"
          requests:
            memory: "100Mi"
    

    创建 Pod:

    kubectl apply -f qos-pod-2.yaml -n qos-example
    

    查看 Pod 详情:

    kubectl get pod qos-demo-2 --namespace=qos-example --output=yaml
    

    结果表明 Kubernetes 为 Pod 配置的 QoS 类为 Burstable。

    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: qos-demo-2-ctr
        resources:
          limits:
            memory: 200Mi
          requests:
            memory: 100Mi
      ...
    status:
      qosClass: Burstable
    

    创建一个 QoS 类为 BestEffort 的 Pod

    对于 QoS 类为 BestEffort 的 Pod,Pod 中的容器必须没有设置内存和 CPU 限制或请求。

    下面是包含一个容器的 Pod 配置文件。 容器没有设置内存和 CPU 限制或请求。

    apiVersion: v1
    kind: Pod
    metadata:
      name: qos-demo-3
      namespace: qos-example
    spec:
      containers:
      - name: qos-demo-3-ctr
        image: nginx
    

    创建 Pod:

    kubectl apply  -f  qos-pod-3.yaml -n qos-example
    

    查看 Pod 详情:

    kubectl get pod qos-demo-3 --namespace=qos-example --output=yaml
    

    结果表明 Kubernetes 为 Pod 配置的 QoS 类为 BestEffort。

    spec:
      containers:
        ...
        resources: {}
      ...
    status:
      qosClass: BestEffort
    

    创建包含两个容器的 Pod

    下面是包含两个容器的 Pod 配置文件。 一个容器指定了内存请求 200 MiB。 另外一个容器没有指定任何请求和限制。

    apiVersion: v1
    kind: Pod
    metadata:
      name: qos-demo-4
      namespace: qos-example
    spec:
      containers:
    
      - name: qos-demo-4-ctr-1
        image: nginx
        resources:
          requests:
            memory: "200Mi"
    
      - name: qos-demo-4-ctr-2
        image: redis
    

    注意此 Pod 满足 Burstable QoS 类的标准。 也就是说它不满足 Guaranteed QoS 类标准,因为它的一个容器设有内存请求。

    创建 Pod:

    kubectl apply  -f  qos-pod-4.yaml --n qos-example
    

    查看 Pod 详情:

    kubectl get pod qos-demo-4 --namespace=qos-example --output=yaml
    

    结果表明 Kubernetes 为 Pod 配置的 QoS 类为 Burstable:

    spec:
      containers:
        ...
        name: qos-demo-4-ctr-1
        resources:
          requests:
            memory: 200Mi
        ...
        name: qos-demo-4-ctr-2
        resources: {}
        ...
    status:
      qosClass: Burstable
    
  • 相关阅读:
    毕业设计:文献参考(六)
    毕业设计:文献参考(五)
    稀疏数组搜索(leetcode)
    寻找重复数(leetcode)
    联通网络的操作次数(leetcode)
    Flutter 混合开发基础
    浅谈 Serverless 开发和应用
    基于 Qt Quick Plugin 快速构建桌面端跨平台组件
    Android 设备音视频兼容性适配
    RTC 系统音频弱网对抗技术发展与实践
  • 原文地址:https://www.cnblogs.com/baozexu/p/15394308.html
Copyright © 2011-2022 走看看