标签:bsp memory yaml ever 退出 允许 roo 异常 pre
1、资源限制
Pod和Container的资源请求和限制:
spec.containers[].resources.limits.cpu
spec.containers[].resources.limits.memory
spec.containers[].resources.requests.cpu
spec.containers[].resources.requests.memory
limits:pod最大可使用的资源
requests:运行pod所分配的最小资源
0 <= request <= limit,如果limit=0表示不对资源进行限制, 这时可以小于request。
示例:
apiVersion: v1 kind: Pod metadata: name: frontend spec: containers: - name: db image: mysql env: - name: MYSQL_ROOT_PASSWORD value: "password" resources: requests: memory: "64Mi" #允许的内存64m cpu: "250m" #允许的CPU,单个CPU的0.25核 limits: memory: "128Mi" #允许的内存128m cpu: "500m" #允许的CPU,单个CPU的0.5核 - name: wp image: wordpress resources: requests: memory: "64Mi" cpu: "250m" limits: memory: "128Mi" cpu: "500m"
[root@k8s-master01-etcd01 yaml]# kubectl describe node k8s-node02|egrep "frontend|Namespace" Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits AGE default frontend 500m (12%) 1 (25%) 128Mi (7%) 256Mi (14%) 12m
2、LimitRange设置默认的资源限制及资源限制比例
LimitRange从字面意义上来看就是对范围进行限制,实际上是对cpu和内存资源使用范围的限制
资源配额是对整个名称空间的资源的总限制,是从整体上来限制的,而LimitRange则是对pod和container级别来做限制的
由于LimitRange是基于名称空间的,因此为了测试,我们先创建一个名称空间
kubectl create namespace example
示例:
apiVersion: v1 kind: LimitRange metadata: name: mem-limit-range namespace: example spec: limits: - default: # default limit memory: 512Mi cpu: 2 defaultRequest: # default request memory: 256Mi cpu: 0.5 max: # max limit memory: 800Mi cpu: 3 min: # min request memory: 100Mi cpu: 0.3 maxLimitRequestRatio: # 最小/最大 使用量的比率 memory: 5 cpu: 4 type: Container
[root@k8s-master01-etcd01 nginx]# kubectl describe limits -n example Name: mem-limit-range Namespace: example Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio ---- -------- --- --- --------------- ------------- ----------------------- Container cpu 300m 3 500m 1 4 Container memory 100Mi 800Mi 256Mi 512Mi 5
3、重启策略
Always:当容器终止退出后,总是重启容器,默认策略。
OnFailure:当容器异常退出(退出状态码非0)时,才重启容器。
Never::当容器终止推出,从不重启容器。
配置:
apiVersion: v1
kind: Pod
metadata:
name: foo
namespace: awesomeapps
spec:
containers:
- name: foo
image: janedoe/awesomeapp:v1
restartPolicy: Always #配置重启策略,和containers一个级别
标签:bsp memory yaml ever 退出 允许 roo 异常 pre
原文地址:https://www.cnblogs.com/xw115428/p/11957916.html