Pod configuration of the QoS kubernetes

Brief introduction

This article describes how to configure the Pod's QoS (Quality of Service) ie quality of service. Kubernetes use QoS class to make decisions about scheduling and the expulsion of the Pod.

NOTE: This document is to be understood with reference to their official documents, and. If misleading, please criticism.

QoS class

When Kubernetes create Pod, it will be assigned to one of the following categories QoS these Pod:

  • Guaranteed
  • Burstable
  • best-effort delivery

Create a Guaranteed QoS class assigned to the Pod

Create a namespace

# kubectl create namespace qos-example

Guaranteed QoS class for providing conditions for Pod:

  • Pod in each container must have a memory request and memory restrictions, but they must be the same
  • Pod Each container must request a CPU and CPU limitations, but they must be the same

Create a Pod, the Pod is only one container. The container custom memory requests and the inch limits are equal 200MiB, CPU requests are equal, and CPU limitations 700 milliCPU. file name:qos-pod.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 apply -f /root/k8s-example/pods/qos-pod.yaml --namespace=qos-example

View details Pod resources

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

Seen from the output, Kubernetes Guaranteed QoS class is provided for the Pod. The output also verify its memory limits the memory request matches Pod container, and CPU requests which match their CPU limit.

spec:
  containers:
    ...
    resources:
      limits:
        cpu: 700m
        memory: 200Mi
      requests:
        cpu: 700m
        memory: 200Mi
...
  qosClass: Guaranteed

NOTE: If the container customize its own memory limit, but does not define the memory request, Kubernetes automatically default memory limit number is set to change the container number of memory requests; If the container customized CPU limit, but does not define the CPU requests, Kubernetes the CPU automatically default limit is set to the number of containers CPU requests.

Delete change Pod

# kubectl delete pod qos-demo --namespace=qos-example

Creating a QoS level Burstable assigned the Pod

If the following conditions are satisfied, for the Pod provide burstableQoS classes:

  • Pod does not meet the criteria to ensure QoS category.
  • Pod container having at least a CPU or memory request.

Create a Pod, which Pod a memory limit only the container, the container number 200 MiB, the number of requests for the memory 100 MiB. file name: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"
# kubectl apply -f /root/k8s-example/pods/qos-pod-2.yaml --namespace=qos-example

View details Pod resources

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

Pod Kubernetes to output display provides a QoS class burstable

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

Delete Pod

# kubectl delete pod qos-demo-2 --namespace=qos-example

Create a Pod BestEffort QoS class assigned

In order to obtain a QoS class BestEffort the Pod, Pod in the container can not have any memory or CPU limit or request.

Create a Pod, Pod only one container. Container and no memory request or CPU limits

apiVersion: v1
kind: Pod
metadata:
  name: qos-demo-3
  namespace: qos-example
spec:
  containers:
  - name: qos-demo-3-ctr
    image: nginx
# kubectl apply -f /root/k8s-example/pods/qos-pod-3.yaml --namespace=qos-example  

View details Pod resources

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

Pod Kubernetes to output display provides BestEfforta QoS class.

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

Delete Pod

# kubectl delete pod qos-demo-3 --namespace=qos-example

Create two containers in a Pod

Create a Pod consists of two containers. A container custom memory request 200 MiB. Another container does not define or limit any request resources. file name:qos-pod-4.yaml

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
# kubectl apply -f /root/k8s-example/pods/qos-pod-4.yaml --namespace=qos-example

View details Pod resources

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

Note that this accord Pod QoS class Burstablestandards. In other words, it does not meet Guaranteed的QoSthe standard category, and one of its "container" with a memory request.

spec:
  containers:
    ...
    name: qos-demo-4-ctr-1
    resources:
      requests:
        memory: 200Mi
    ...
    name: qos-demo-4-ctr-2
    resources: {}
    ...
  qosClass: Burstable

Delete Pod

# kubectl delete pod qos-demo-4 --namespace=qos-example

Delete namespace

# kubectl delete namespace qos-example

to sum up

1, Pod the three QoS classes Guaranteed, Burstable, BestEffort.

2, to provide a QoS class for the Guaranteed Pod conditions:

  • Pod in each container must have a memory request and memory restrictions, but they must be the same
  • Pod Each container must request a CPU and CPU limitations, but they must be the same

3, to provide a Pod burstableQoS classes conditions:

  • Pod does not meet the criteria Guaranteed QoS category.
  • Pod container having at least a CPU or memory request.

4, to provide a Pod BestEffortconditions of QoS classes: Pod in the container can not have any memory or CPU limit or request.

Guess you like

Origin www.cnblogs.com/mcsiberiawolf/p/12214554.html