要件:クラスタ管理の設定は、各ポッドの制限および制約を要求面倒で、
溶液:kubernetesはLimitRange要求と制限ポッドと容器制限する機構を提供
デフォルトの最小および最大範囲、または要求の制限:LimitRangeいくつかの制限を上限値、制限および要求の最大割合
1.名前空間を作成します
kubectl create namespace limitrange-example
2.LimitRangeリソースオブジェクト
apiVersion: v1
kind: LimitRange
metadata:
name: mylimits
namespace: limitrange-example
spec:
limits:
- max:
cpu: "2"
memory: 4Gi
min:
cpu: 200m
memory: 6Mi
maxLimitRequestRatio:
cpu: 2
memory: 2
type: Pod
- default:
cpu: 300m
memory: 200Mi
defaultRequest:
cpu: 200m
memory: 100Mi
min:
cpu: 100m
memory: 3Mi
max:
cpu: "2"
memory: 1Gi
maxLimitRequestRatio:
cpu: 5
memory: 4
type: Container
3.オブジェクト情報limitrangeをチェック
kubectl describe limitrange mylimits -n limitrange-example
説明
type为Pod:
min表示是pod中所有容器的requests值的总和下限
max表示pod中所有容器的limits值的总和上限
maxLimitRequestRatio表示是pod中所有容器的Limits值总和与Requests值总和的比例上限
type为Requests:
min表示是pod中的容器的requests值的下限
max表示pod中容器的limits值的上限
defaultRequest: pod中未指定Requests值的容器的默认Requests值
default表示pod中未指定Limits值的容器的默认Limits值
maxLimitRequestRatio表示是pod中所有容器的Limits值总和与Requests值比例上限
4.ポッドを作成します。
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: limitrange-example
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.11
ports:
- containerPort: 80
説明:ポッドとして要求とデフォルト値が定義されたように、配置されない範囲の要求と制限
5.リソースの制約よりもポッドを設定し、結果を作成することはできません
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: limitrange-example
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.11
ports:
- containerPort: 80
resources:
limits:
cpu: "3"
memory: 2Gi