容器的资源需求,资源限制 requests:需求,最低保障; limits:限制,硬限制; CPU: 1颗逻辑CPU 1=1000,millicores 500m=0.5CPU 内存: E、P、T、G、M、K Ei、Pi QoS: Guranteed:每个容器 同时设置CPU和内存的requests和limits. cpu.limits=cpu.requests memory.limits=memory.request Burstable: 至少有一个容器设置CPU或内存资源的requests属性 BestEffort:没有任何一个容器设置了requests或limits属性;最低优先级别;
官方文档对需求和限制的解释
spec.containers[].resources.limits.cpu spec.containers[].resources.limits.memory spec.containers[].resources.requests.cpu spec.containers[].resources.requests.memory
apiVersion: v1 kind: Pod metadata: name: frontend spec: containers: - name: db image: mysql env: - name: MYSQL_ROOT_PASSWORD value: "password" resources: requests: memory: "64Mi" cpu: "250m" limits: memory: "128Mi" cpu: "500m" - name: wp image: wordpress resources: requests: memory: "64Mi" cpu: "250m" limits: memory: "128Mi" cpu: "500m"
进行一个简单的压测
[root@master limit]# cat pod-demo.yml apiVersion: v1 kind: Pod metadata: name: pod-limit namespace: default labels: app: myapp 2sdlfj: dashazi spec: containers: - name: stress-ng image: ikubernetes/stress-ng command: ["/usr/bin/stress-ng","-m 1","-c 1","--metrics-brief"] resources: requests: cpu: "500m" memory: "256Mi" limit: cpu: "500m" memory: "256Mi" nodeSelector: location: slave1
kubectl exec pod-limit -- top
Mem: 1994208K used, 52860K free, 113228K shrd, 328K buff, 194776K cached
CPU: 18% usr 28% sys 0% nic 30% idle 11% io 0% irq 11% sirq
Load average: 8.07 6.10 3.87 6/740 123
PID PPID USER STAT VSZ %VSZ CPU %CPU COMMAND
6 1 root R 6892 0% 0 11% {stress-ng-cpu} /usr/bin/stress-ng
84 0 root R 1500 0% 0 0% top
123 7 root R 262m 13% 1 0% {stress-ng-vm} /usr/bin/stress-ng
7 1 root S 6244 0% 1 0% {stress-ng-vm} /usr/bin/stress-ng
1 0 root S 6244 0% 1 0% /usr/bin/stress-ng -m 1 -c 1 --met
21 0 root S 1504 0% 0 0% top
资源监控收集服务Heapster(已弃用)
[root@master limit]# kubectl top node Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)