k8s - 为namespace设置内存最大限额和最小限额
作者:互联网
世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问:如何为namespace设置内存的最大限额和最小限额?
答:
为namespace设置最大和最小内存限制
创建namespace
- kubectl create namespace constraints-mem-example
创建LimitRange
- apiVersion: v1
kind: LimitRange
metadata:
name: mem-min-max-demo-lr
spec:
limits:- max:
memory: 1Gi
min:
memory: 500Mi
type: Container
- max:
- kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-constraints.yaml --namespace=constraints-mem-example
- kubectl get limitrange cpu-min-max-demo --namespace=constraints-mem-example --output=yaml
创建Pod
- apiVersion: v1
kind: Pod
metadata:
name: constraints-mem-demo
spec:
containers:- name: constraints-mem-demo-ctr
image: nginx
resources:
limits:
memory: “800Mi”
requests:
memory: “600Mi”
- name: constraints-mem-demo-ctr
- kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-constraints-pod.yaml --namespace=constraints-mem-example
- kubectl get pod constraints-mem-demo --namespace=constraints-mem-example
- kubectl get pod constraints-mem-demo --output=yaml --namespace=constraints-mem-example
标签:mem,demo,namespace,限额,--,memory,k8s,constraints 来源: https://blog.csdn.net/a13662080711/article/details/118080334