- 一、介绍
- POD配额实验:
- 三、CPU、内存配额实验
前面namespace中说到,Namespace是一种将集群资源划分为多个用途(通过 resource quota)的方法。在k8s上准入控制器的模块有很多,其中比较常用的有LimitRanger、ResourceQuota、ServiceAccount、PodSecurityPolicy等等,对于前面三种准入控制器系统默认是启用的,我们只需要定义对应的规则即可
POD配额实验:1.创建namespace.yaml文件创建namespace
apiVersion: v1 kind: Namespace metadata: name: resourcequota
[root@iZbp16ke9g4qwtz7gw25fnZ ~]# kubectl create -f namespace.yaml namespace/resourcequota created [root@iZbp16ke9g4qwtz7gw25fnZ ~]# kubectl get ns | grep resourcequota resourcequota Active 17s
2.创建resourcequota为namespace设置pod数量限制
apiVersion: v1 kind: ResourceQuota metadata: name: pod-quota1 namespace: resourcequota spec: hard: pods: 2
spec:hard即资源配额列表,其各字段的含义和单位如表所示。
[root@iZbp16ke9g4qwtz7gw25fnZ ~]# kubectl create -f quota-pod.yaml resourcequota/pod-quota1 created [root@iZbp16ke9g4qwtz7gw25fnZ ~]# kubectl get resourcequota -n=resourcequota NAME CREATED AT pod-quota1 2021-12-16T01:51:39Z
3.创建deployment(3pod)
apiVersion: apps/v1beta1 kind: Deployment metadata: name: nginx-v1 namespace: resourcequota spec: replicas: 3 template: metadata: labels: app: nginx-v1 spec: containers: - name: nginx-quota image: hlqlinux/hlq-test:nginx-v3
由于做了pod资源限制,只有两个pod被创建
[root@iZbp16ke9g4qwtz7gw25fnZ ~]# kubectl get deploy -n=resourcequota NAME READY UP-TO-DATE AVAILABLE AGE nginx-v1 2/3 2 2 2m4s
限制成功
本实验展示了如何为某一名字空间内运行的所有容器配置CPU和内存配额。配额可以通过 ResourceQuota对象设置。
报错: 0/2 nodes are available: 1 Insufficient cpu, 1 node(s) had taints that the pod didn’t tolerate.
设置请求的POD数为3,node节点cpu资源为1,导致节点调度不上去。
resourcequota资源请求配置
apiVersion: v1 kind: ResourceQuota metadata: name: pod-quota1 namespace: resourcequota spec: hard: requests.cpu: 2 requests.memory: 2Gi limits.cpu: 2 limits.cpu: 2Gi
测试deployment
apiVersion: apps/v1beta1 kind: Deployment metadata: name: nginx-v1 namespace: resourcequota spec: replicas: 3 template: metadata: labels: app: nginx-v1 spec: containers: - name: nginx-quota image: hlqlinux/hlq-test:nginx-v3 resources: limits: cpu: 0.2 memory: 0.2Gi requests: cpu: 0.2 memory: 0.2Gi
kubectl describe pod nginx-v1-7759dc485b-4g8hf -nresourcequota Containers: nginx-quota: Limits: cpu: 200m memory: 214748364800m Requests: cpu: 200m memory: 214748364800m
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)