十二章:高级调度准入控制
1.为什么生产一定要用ResourceQuota
资源配额
ResourceQuota
2.1 ResourceQuota配置
# cat resource.yaml
========================================
apiVersion: v1
kind: ResourceQuota
metadata:
name: resource-test
labels:
app: resourcequota
spec:
hard:
pods: 50
requests.cpu: 0.5
requests.memory: 512Mi
limits.cpu: 5
limits.memory: 16Gi
configmaps: 20
requests.storage: 40Gi
persistentvolumeclaims: 20
replicationcontrollers: 20
secrets: 20
services: 50
services.loadbalancers: "2"
services.nodeports: "10"
============================================
pods: 限制最多启动Pod的个数
requests.cpu 限制最高的cpu请求数
requests.memory: 限制最高内存的请求数
limits.cpu 限制最高的cpu的limit上限
limits.memory 限制最高内存的limit上线
===========================================
上面resourcequota规则创建完成后,下面搞了一个deployment测试
[root@k8s-master01 ~]# cat nginxtest.yaml
apiVersion: apps/v1 ##版本号 ,pod资源
kind: Deployment ##类型/控制器
metadata: ##数据标签
name: nginx2-deployment
labels: ##子标签
app: nginx ##业务容器
spec:
replicas: 3 ##副本集
selector: ##选择器
matchLabels: ##匹配标签
app: nginx ##对应上面的业务容器
template: ##模板
metadata:
labels:
app: nginx
spec:
containers: ##容器
- name: nginx ##对应上面的业务容器
image: nginx:1.18.0 ##使用镜像信息
ports:
- containerPort: 80 ##容器端口信息
---
apiVersion: v1 ##版本号
kind: Service ##服务类型
metadata:
name: nginx2-service
labels:
app: nginx
spec:
type: NodePort ##端口映射
ports:
- port: 80 ##内部端口
targetPort: 80 ##映射端口
selector: ##选择器/
app: nginx ##选择业务进行发布
=====================================================
测试结果:有了resourcequota的限制,上面的deployment创建失败,删除限制则创建成功
LimitRange
3.1 引言
光靠ResourceQuota配置还是不行的,需要更细节化的限制;
那么LimitRange的出现就是在ResourceQuota的基础上更加细节化的限制资源使用。
只有ResourceQuota的限制还是不够
LimitRange做了什么
3.2配置示例
配置示例:
[root@k8s-master01 ResourceQuota]# cat limitrange.yaml
apiVersion: v1
kind: LimitRange
metadata:
name: cpu-mem-limit-range
spec:
limits:
- default:
cpu: 1
memory: 512Mi
defaultRequest:
cpu: 0.5
memory: 256Mi
type: Container
================================
➢ default:默认limits配置
➢ defaultRequest:默认requests配置
=========查看============================
[root@k8s-master01 ResourceQuota]# kubectl get LimitRange
NAME CREATED AT
cpu-mem-limit-range 2022-11-20T17:37:04Z
LimitRange配置示例:requests和limits的范围
3.3内存cpu限制
===================
[root@k8s-master01 ResourceQuota]# cat limitrange.yaml
apiVersion: v1
kind: LimitRange
metadata:
name: cpu-mem-limit-range
spec:
limits:
- default:
cpu: 1
memory: 512Mi
defaultRequest:
cpu: 0.5
memory: 256Mi
type: Container
max:
cpu: "1800m"
memory: 1Gi
min:
cpu: "200m"
memory: 200Mi
type: Container
================
➢ max:内存CPU的最大配置
➢ min:内存CPU的最小配置
3.4 存储卷限制
限制申请存储空间的大小
apiVersion: v1
kind: LimitRange
metadata:
name: storagelimits
spec:
limits:
- type: PersistentVolumeClaim
max:
storage: 2Gi
min:
storage: 1Gi
标签:limits,##,memory,调度,limitRange,LimitRange,ResourceQuota,Resourcequota,cpu
From: https://www.cnblogs.com/zongliang-ya/p/16910200.html