世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问:如何为namespace配置最大和最小限额?
答:
为namespace配置cpu最大和最小限额
创建namespace
- kubectl create namespace constraints-cpu-example
创建LimitRange
- apiVersion: v1
kind: LimitRange
metadata:
name: cpu-min-max-demo-lr
spec:
limits: - max:
cpu: “800m”
min:
cpu: “200m”
type: Container
- kubectl create -f https://k8s.io/docs/tasks/administer-cluster/cpu-constraints.yaml --namespace=constraints-cpu-example
- kubectl get limitrange cpu-min-max-demo-lr --output=yaml --namespace=constraints-cpu-example
创建Pod
- apiVersion: v1
kind: Pod
metadata:
name: constraints-cpu-demo
spec:
containers: - name: constraints-cpu-demo-ctr
image: nginx
resources:
limits:
cpu: “800m”
requests:
cpu: “500m”
- kubectl create -f https://k8s.io/docs/tasks/administer-cluster/cpu-constraints-pod.yaml --namespace=constraints-cpu-example
- kubectl get pod constraints-cpu-demo --namespace=constraints-cpu-example
- kubectl get pod constraints-cpu-demo --output=yaml --namespace=constraints-cpu-example
删除
- kubectl delete namespace constraints-cpu-example