kubernetes之资源配额

1.说明
通过ResourceQuota对象, 可以为每个命名空间都提供一个总体的资源使用限制,
资源配额的支持在很多Kubernetes版本中是默认开启的。 当 apiserver 的 --admission-control= 参数中包含 ResourceQuota 时,资源配额会被启用。
当namespace中存在一个 ResourceQuota 对象时,该namespace即开始实施资源配额管理。 一个namespace中最多只应存在一个 ResourceQuota 对象
在Kuberners中,资源配额能够对计算资源(CPU和内存)、存储资源、以及对资源对象的数量进行管理。
https://www.kubernetes.org.cn/4905.html

计算资源管理

1.创建命名空间

kubectl create namespace myspace

2.定义管理计算资源配额的YAML文件,在此文件中,资源配额管理的名称为computer-resources,pod的数量为4,cpu的需求数量为1核,cpu的限制数量为2核;内存的需求大小为1Gi,内存的限制大小为2Gi。

cat >compute-resources.yaml<<EOF
apiVersion: v1 
kind: ResourceQuota 
metadata: 
  name: compute-resources 
spec: 
  hard: 
    pods: "4" 
    requests.cpu: "1" 
    requests.memory: 1Gi 
    limits.cpu: "2" 
    limits.memory: 2Gi
EOF

3.kubectl命令在myspaces命名空间下创建资源配额

kubectl apply -f ./compute-resources.yaml --namespace=myspace

4.在创建完资源配额后,通过执行下面的命令查看资源配额的详细信息:

kubectl describe quota compute-resources --namespace=myspace

5.定义pod资源管理文件

cat >nginx-deployment.yaml<<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.11
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: 256m
            memory: 256Mi
          limits:
            cpu: 512m
            memory: 512Mi
EOF

6.创建

kubectl apply -f nginx-deployment.yaml --namespace=myspace

7.在创建完资源配额后,通过执行下面的命令查看资源配额的详细信息:

kubectl describe quota compute-resources --namespace=myspace

猜你喜欢

转载自www.cnblogs.com/lovelinux199075/p/11278813.html