记得以前看过一篇文章(现在找不到了),那篇文章讲到了申请memory
的单位M
,它认为1M=1024K=1024x1024字节
,但在k8s中的M
表示的意义是不同的,今天特意看了一下官方文档,并实验了一把,特此记录。
官网解释:Meaning of memory,Mi
表示(1Mi=1024x1024),M
表示(1M=1000x1000)(其它单位类推, 如Ki/K Gi/G
)
创建两个pod
, 一个申请1Mi
, 另一个申请1M
, 通过log来查看他们的区别。
nginx1.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx1
image: nginx:test
ports:
- containerPort: 80
resources:
limits:
cpu: 200m
memory: 128Mi
requests:
cpu: 0.1
memory: 1Mi
nginx2.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx2
spec:
containers:
- name: nginx2
image: nginx:test
ports:
- containerPort: 80
resources:
limits:
cpu: 200m
memory: 128Mi
requests:
cpu: 0.1
memory: 1M
nginx1.yaml(Mi
)申请资源的信息如下,可以看到Memory=1024*1024
I0716 11:05:43.555791 31331 factory.go:469] About to try and schedule pod nginx
I0716 11:05:43.555804 31331 scheduler.go:165] Attempting to schedule pod: default/nginx
I0716 11:05:43.555866 31331 predicates.go:565] Predicate: MilliCPU=100 Memory=1048576 NvidiaGPU=0 OpaqueIntResources=map[]
nginx2.yaml(M
)申请资源的信息如下,Memory=1000*1000
I0716 11:05:58.404826 31331 factory.go:469] About to try and schedule pod nginx2
I0716 11:05:58.404840 31331 scheduler.go:165] Attempting to schedule pod: default/nginx2
I0716 11:05:58.404904 31331 predicates.go:565] Predicate: MilliCPU=100 Memory=1000000 NvidiaGPU=0 OpaqueIntResources=map[]
网友评论