首页 > 其他分享 >配置Pod的服务质量

配置Pod的服务质量

时间:2023-07-24 17:22:36浏览次数:30  
标签:qos 服务质量 demo 配置 namespace Pod 04T03 name

QoS类

QoS(Quality of Service class,Qos class):服务质量类

Kubernetes创建Pod时,会将如下Qos类之一设置到Pod上:

  • Guaranteed
  • Burstable
  • BestEffort

先创建一个qos-example命名空间方便测试

kubectl create namespace=qos-example

创建一个Qos为Guaranteed的Pod

Qos类为Guaranted的Pod满足的条件:

  • Pod中每个容器都限制内存和内存请求
  • 每个容器内存限制和内存请求必须相等
  • 每个容器必须指定cpu限制和请求,且二者必须相等

反映到yaml配置文件中则表示必须有limitsrequests字段,且两字段中的子类值必须相等

kubectl apply -f qos-demo.yaml --namespace=qos-example

#qos-demo.yaml
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"

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

root@lxt-master:~/podTest# kubectl get pod qos-demo --namespace=qos-example --output=yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"qos-demo","namespace":"qos-example"},"spec":{"containers":[{"image":"nginx","name":"qos-demo-ctr","resources":{"limits":{"cpu":"700m","memory":"200Mi"},"requests":{"cpu":"700m","memory":"200Mi"}}}]}}
  creationTimestamp: "2023-05-04T03:06:54Z"
  name: qos-demo
  namespace: qos-example
  resourceVersion: "4878778"
  uid: 8b60daeb-95eb-4a33-99ab-d8ea508e1ad9
spec:
  containers:
  - image: nginx
    imagePullPolicy: Always
    name: qos-demo-ctr
    resources:
      limits:
        cpu: 700m
        memory: 200Mi
      requests:
        cpu: 700m
        memory: 200Mi
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-w8nhz
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: lxt-master
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: kube-api-access-w8nhz
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:06:54Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:07:11Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:07:11Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:06:54Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: docker://bfd07210d64cf4b3dfb7deef4eba1ee5691c9d011d51fe863738b4affba14c26
    image: nginx:latest
    imageID: docker-pullable://nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
    lastState: {}
    name: qos-demo-ctr
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2023-05-04T03:07:11Z"
  hostIP: 192.168.20.113
  phase: Running
  podIP: 10.44.0.7
  podIPs:
  - ip: 10.44.0.7
  qosClass: Guaranteed
  startTime: "2023-05-04T03:06:54Z"

创建一个QoS类为Burstable的Pod

满足条件

  • Pod不符合Guaranted标准
  • Pod中至少一个container有内存或者cpu的请求或限制
#qos-pod-2.yaml
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 get pod qos-demo-2 --namespace=qos-example --output=yaml

root@lxt-master:~/podTest# kubectl get pod qos-demo-2 --namespace=qos-example --output=yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"qos-demo-2","namespace":"qos-example"},"spec":{"containers":[{"image":"nginx","name":"qos-demo2-ctr","resources":{"limits":{"memory":"200Mi"},"requests":{"memory":"100Mi"}}}]}}
  creationTimestamp: "2023-05-04T03:13:34Z"
  name: qos-demo-2
  namespace: qos-example
  resourceVersion: "4879998"
  uid: d9fd5928-ade3-4624-958f-376842aaeb23
spec:
  containers:
  - image: nginx
    imagePullPolicy: Always
    name: qos-demo2-ctr
    resources:
      limits:
        memory: 200Mi
      requests:
        memory: 100Mi
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-jcgnn
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: lxt-master
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: kube-api-access-jcgnn
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:13:34Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:13:52Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:13:52Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:13:34Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: docker://2bc5fcd44b649d13c266842f82978f78f474ba577eddb7f6e460fefa21b213e1
    image: nginx:latest
    imageID: docker-pullable://nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
    lastState: {}
    name: qos-demo2-ctr
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2023-05-04T03:13:51Z"
  hostIP: 192.168.20.113
  phase: Running
  podIP: 10.44.0.8
  podIPs:
  - ip: 10.44.0.8
  qosClass: Burstable
  startTime: "2023-05-04T03:13:34Z"

创建一个QoS类为Best Effort的Pod

条件:Pod中的Container必须没有设置内存和cpu限制或请求

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

Pod详情:

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

root@lxt-master:~/podTest# kubectl get pod qos-demo-3 --namespace=qos-example --output=yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"qos-demo-3","namespace":"qos-example"},"spec":{"containers":[{"image":"nginx","name":"qos-demo-3-ctr"}]}}
  creationTimestamp: "2023-05-04T03:21:08Z"
  name: qos-demo-3
  namespace: qos-example
  resourceVersion: "4881388"
  uid: a7046c5c-298e-4b38-a950-6e3df583e949
spec:
  containers:
  - image: nginx
    imagePullPolicy: Always
    name: qos-demo-3-ctr
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-gsvf7
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: lxt-master
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: kube-api-access-gsvf7
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:21:08Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:21:27Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:21:27Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:21:08Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: docker://c7bdfbb070ed8f0aa374bc1ae416569c6abddeb0c4ba81a041c1117dbfa13bf7
    image: nginx:latest
    imageID: docker-pullable://nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
    lastState: {}
    name: qos-demo-3-ctr
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2023-05-04T03:21:27Z"
  hostIP: 192.168.20.113
  phase: Running
  podIP: 10.44.0.9
  podIPs:
  - ip: 10.44.0.9
  qosClass: BestEffort
  startTime: "2023-05-04T03:21:08Z"

创建包含两个容器的Pod

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的标准,因为它的Container之一有内存请求

Pod详情:

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

root@lxt-master:~# kubectl get pod qos-demo-4 --namespace=qos-example --output=yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"qos-demo-4","namespace":"qos-example"},"spec":{"containers":[{"image":"nginx","name":"qos-demo-4-ctr-1","resources":{"requests":{"memory":"200Mi"}}},{"image":"redis","name":"qos-demo-4-ctr-2"}]}}
  creationTimestamp: "2023-05-04T03:25:05Z"
  name: qos-demo-4
  namespace: qos-example
  resourceVersion: "4882050"
  uid: 03e3bb85-1c6e-428f-9a6b-98cbfd315193
spec:
  containers:
  - image: nginx
    imagePullPolicy: Always
    name: qos-demo-4-ctr-1
    resources:
      requests:
        memory: 200Mi
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-hxwxb
      readOnly: true
  - image: redis
    imagePullPolicy: Always
    name: qos-demo-4-ctr-2
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-hxwxb
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: node1
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: kube-api-access-hxwxb
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:25:05Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:25:05Z"
    message: 'containers with unready status: [qos-demo-4-ctr-1 qos-demo-4-ctr-2]'
    reason: ContainersNotReady
    status: "False"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:25:05Z"
    message: 'containers with unready status: [qos-demo-4-ctr-1 qos-demo-4-ctr-2]'
    reason: ContainersNotReady
    status: "False"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2023-05-04T03:25:05Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - image: nginx
    imageID: ""
    lastState: {}
    name: qos-demo-4-ctr-1
    ready: false
    restartCount: 0
    started: false
    state:
      waiting:
        reason: ContainerCreating
  - image: redis
    imageID: ""
    lastState: {}
    name: qos-demo-4-ctr-2
    ready: false
    restartCount: 0
    started: false
    state:
      waiting:
        reason: ContainerCreating
  hostIP: 192.168.20.221
  phase: Pending
  qosClass: Burstable
  startTime: "2023-05-04T03:25:05Z"

检查Pod的Qos类

kubectl --namespace=qos-example get pod qos-demo-4 -o jsonpath='{ .status.qosClass}{"\n"}'

image-20230504141557778

标签:qos,服务质量,demo,配置,namespace,Pod,04T03,name
From: https://www.cnblogs.com/pr1s0n/p/17577793.html

相关文章

  • DNS解析常见问题:如何为网站配置负载均衡?
    DNS解析常见问题:如何为网站配置负载均衡?早期的互联网应用,由于用户流量比较小,业务逻辑也比较简单,往往一个单服务器就能满足负载需求。随着现在互联网的流量越来越大,系统功能也越来越复杂,单台服务器就算将性能优化得再好,也不足以支撑太大流量的访问压力了,这个时候就需要使用多台机器,......
  • 图形工作站电脑配置推荐
    对于很多人来说,电脑一般就是用来简单办公,玩游戏,影音娱乐等。但是市面上基于对一些特殊行业的高层次需求,也有一种高配置的电脑叫做工作站。一、图形工作站和普通电脑的区别图形工作站,是为某种特殊作业目的制作出来的专业级别的电脑。它能做的事情太多了,可以用于气候分析、石油勘......
  • AI绘图电脑主机需要什么配置
    AI绘图的出现给设计界带来了很多的便利性,利用stablediffusion这种工具一秒将2D转化成为3D、1分钟做出10张海报图片等。虽然AI绘图工具效率非常高,但是如果经常玩AI绘图的朋友,基本上都经历过这种情况。为了训练一张不错的AI图片,有时候我们需要打开stablediffusion挂机一个多小时......
  • JetLinks前端配置
    JetLinks前端配置只需要修改vite.config.ts文件的这两个地方,config.ts文件不用修改: 图1:增加注释;图2:修改为jetlinks后端服务启动所在服务器的IP地址和端口号 备注:https://hanta.yuque.com/px7kg1/yfac2l/fwqriw24lp3cy2lwJetLinks-IOT是一个开源的、企业级的物联网平台,它......
  • 经典!H3C交换机基本配置请收好
    下午好,我的网工朋友。思科和华为的交换机配置命令,一些交换机应用配置案例,给你们说过不少,可以根据关键词搜索直达哈。部分网工新人表示,有些配置文章不好理解,看不明白命令。思来想去,正好华三的交换机配置也没给你系统讲过,今天来一篇华三的,给你整一整H3C交换机配置相关内容。恢复出厂......
  • Spring中propagation的7种事务配置及说明
     http://www.zhano.cn/index.php/Java/40878.html Springpropagation7种事务配置1、简述在声明式的事务处理中,要配置一个切面,其中就用到了propagation,表示打算对这些方法怎么使用事务,是用还是不用,其中propagation有七种配置,REQUIRED、SUPPORTS、MANDATORY、REQUIRES_NEW、......
  • .net core 6.0 获得配置文件
    .NETCore6.0获得配置文件在.NETCore应用程序中,配置文件是一个非常重要的组成部分。它允许我们将应用程序的设置和属性与代码分离,以便在不修改代码的情况下更改应用程序的行为。在本文中,我们将探讨如何在.NETCore6.0中获取和使用配置文件。什么是配置文件?配置文件是一个文......
  • vue3.0 外部配置文件一 (导入json文件方式)
    vue3.0外部配置文件,重点是打包后也可以修改配置参数 注:js文件中必须是标准的json格式一、在public中创建static文件夹,在static文件夹中创建config.json  文件 config.json (必须是标准的json格式){"webSocketUrl":"ws://192.168.1.120:5011/chat/","......
  • jadx安装与配置,hook框架frida
    jadx1.下载jadx反编译工具,安装(解压即用)#下载地址:https://github.com/skylot/jadx/releases2.打开jadx反编译工具:3.抓包与代码定位3.1抓包#1.安装apk#2.打开chaarles,打开app,定位到登录请求3.2.反编译定位代码的位置#抓包#想去反编译代码中的位置......
  • 记录windows、vs2019、c++、cuda环境配置
    原文链接:   (45条消息)CUDA+Windows+VS环境配置_cudavs_哈哈哈哈哈嗝哈哈哈的博客-CSDN博客            VS2019--c++CUDA环境配置与编程实例-知乎(zhihu.com)测试代码:.cu文件中:#include"stdio.h"#include<cuda_runtime.h>#include<devi......