内存限制示例:
vim pod.yaml
apiVersion: v1 kind: Pod metadata: name: memory-demo spec: containers: - name: memory-demo image: stress args: - --vm - "1" - --vm-bytes - 200M resources: requests: memory: 50Mi limits: memory: 100Mi
vim pod1.yaml
apiVersion: v1 kind: Pod metadata: name: cpu-demo spec: containers: - name: cpu-demo image: stress resources: limits: cpu: "0.5" requests: cpu: "0.1" args: - -c - "2"
vim limitrange.yaml
apiVersion: v1 kind: LimitRange metadata: name: limitrange-memory spec: limits: - default: cpu: 0.5 memory: 512Mi defaultRequest: cpu: 0.1 memory: 256Mi max: cpu: 1 memory: 1Gi min: cpu: 0.1 memory: 100Mi type: Container
将这些代码加入到刚刚建立的
vim limitrange.yaml
apiVersion: v1 kind: ResourceQuota metadata: name: mem-cpu-demo spec: hard: requests.cpu: "1" requests.memory: 1Gi limits.cpu: "2" limits.memory: 2Gi
然后把pod,pod1启动,查看实验效果
设定一下pods
还是写入刚刚的文件
vim limitrange.yaml
apiVersion: v1 kind: ResourceQuota metadata: name: mem-cpu-demo spec: hard: requests.cpu: "1" requests.memory: 1Gi limits.cpu: "2" limits.memory: 2Gi pods: "4"