1.Pod 设置容器的资源请求和约束
资源请求设置:spec.containers[].resources.limits.cpu
、spec.containers[].resources.limits.memory
、spec.containers[].resources.limits.hugepages-<size>
资源约束设置:spec.containers[].resources.requests.cpu
、spec.containers[].resources.requests.memory
、spec.containers[].resources.requests.hugepages-<size>
apiVersion: v1
kind: Pod
metadata:
name: frontend
spec:
containers:
- name: app
image: images.my-company.example/app:v4
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
① CPU 资源的单位:以数量为单位,例如,0.1=100m
② 内存资源的单位:以 E/Ei、P/Pi、T/Ti、G/Gi、M/Mi、k/Ki 为单位,例如,128M=128Mi
2.Deployment 设置容器的资源请求和约束
资源请求设置:spec.template.spec.containers[].resources.limits.cpu
、spec.template.spec.containers[].resources.limits.memory
、spec.template.spec.containers[].resources.limits.hugepages-<size>
资源约束设置:spec.template.spec.containers[].resources.requests.cpu
、spec.template.spec.containers[].resources.requests.memory
、spec.template.spec.containers[].resources.requests.hugepages-<size>
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
resources:
requests:
memory: "128Mi"
cpu: "500m"
limits:
memory: "128Mi"
cpu: "500m"
网友评论