K8S LimitRange and ResourceQuota

ResourceQuota

resourceQuota 可以限制一个ns下可以创建的资源数量和资源的limit

1
2
3
4
5
6
7
8
9
10
11
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-resources
spec:
hard:
pods: "4"
requests.cpu: "1"
requests.memory: 1Gi
limits.cpu: "2"
limits.memory: 2Gi

LimitRange

k8s 使用limit range开控制一个命名空间下的不同type(pod, container)类型资源限制,参考下面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
apiVersion: v1
kind: Namespace
metadata:
name: test-limit-range

---
apiVersion: v1
kind: LimitRange
metadata:
name: limit-mem-cpu-per-container
spec:
limits:
- max:
cpu: "800m"
memory: "1Gi"
min:
cpu: "100m"
memory: "100Mi"
default:
cpu: "700m"
memory: "900Mi"
defaultRequest:
cpu: "110m"
memory: "200Mi"
type: Container

---
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
containers:
- name: t01
image: busybox
command: [ "sleep", "60"]

- name: t02
image: busybox
command: [ "sleep", "60"]
resources:
limits:
cpu: "200m"
memory: "300Mi"

- name: t03
image: busybox
command: [ "sleep", "60"]
resources:
requests:
cpu: "300m"
memory: "400Mi"

- name: t04
image: busybox
command: [ "sleep", "60"]
resources:
limits:
cpu: "444m"
memory: "444Mi"
requests:
cpu: "444m"
memory: "444Mi"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
➜  limitRange git:(master) ✗ k get pod
NAME READY STATUS RESTARTS AGE
test 4/4 Running 0 20s
➜ limitRange git:(master) ✗ k describe pod test
Name: test
Namespace: test-limit-range
Priority: 0
Node: ip-10-200-1-57.ap-northeast-1.compute.internal/10.200.1.57
Start Time: Mon, 24 Feb 2020 10:17:19 +0800
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"test","namespace":"test-limit-range"},"spec":{"containers":[{"command...
kubernetes.io/limit-ranger:
LimitRanger plugin set: cpu, memory request for container t01; cpu, memory limit for container t01; cpu, memory limit for container t03
kubernetes.io/psp: eks.privileged
Status: Running
IP: 10.200.1.207
IPs: <none>
Containers:
t01:
Container ID: docker://b3d8927e0654e7be5f9d826ae14244c9c191d9a9bdb505a9a0b552f8502730e9
Image: busybox
Image ID: docker-pullable://busybox@sha256:6915be4043561d64e0ab0f8f098dc2ac48e077fe23f488ac24b665166898115a
Port: <none>
Host Port: <none>
Command:
sleep
60
State: Running
Started: Mon, 24 Feb 2020 10:17:23 +0800
Ready: True
Restart Count: 0
Limits:
cpu: 700m
memory: 900Mi
Requests:
cpu: 110m
memory: 200Mi
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-vjjds (ro)
t02:
Container ID: docker://ca64d1db5597e14e4009c34febd4fd97e0a2858605dbcee5d2f4fa6e0d98342b
Image: busybox
Image ID: docker-pullable://busybox@sha256:6915be4043561d64e0ab0f8f098dc2ac48e077fe23f488ac24b665166898115a
Port: <none>
Host Port: <none>
Command:
sleep
60
State: Running
Started: Mon, 24 Feb 2020 10:17:27 +0800
Ready: True
Restart Count: 0
Limits:
cpu: 200m
memory: 300Mi
Requests:
cpu: 200m
memory: 300Mi
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-vjjds (ro)
t03:
Container ID: docker://21891b99b6ebd54eadc4ceed63c451e0eb58392dec19679793a141fbadf22491
Image: busybox
Image ID: docker-pullable://busybox@sha256:6915be4043561d64e0ab0f8f098dc2ac48e077fe23f488ac24b665166898115a
Port: <none>
Host Port: <none>
Command:
sleep
60
State: Running
Started: Mon, 24 Feb 2020 10:17:30 +0800
Ready: True
Restart Count: 0
Limits:
cpu: 700m
memory: 900Mi
Requests:
cpu: 300m
memory: 400Mi
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-vjjds (ro)
t04:
Container ID: docker://21e59b648db7aec5d345fc1d6b9998de3c924070c18fcc4e4627a45703401b9c
Image: busybox
Image ID: docker-pullable://busybox@sha256:6915be4043561d64e0ab0f8f098dc2ac48e077fe23f488ac24b665166898115a
Port: <none>
Host Port: <none>
Command:
sleep
60
State: Running
Started: Mon, 24 Feb 2020 10:17:33 +0800
Ready: True
Restart Count: 0
Limits:
cpu: 444m
memory: 444Mi
Requests:
cpu: 444m
memory: 444Mi
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-vjjds (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-vjjds:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-vjjds
Optional: false
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 29s default-scheduler Successfully assigned test-limit-range/test to ip-10-200-1-57.ap-northeast-1.compute.internal
Normal Pulling 28s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal pulling image "busybox"
Normal Created 25s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Created container
Normal Started 25s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Started container
Normal Pulled 25s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Successfully pulled image "busybox"
Normal Pulling 24s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal pulling image "busybox"
Normal Pulling 21s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal pulling image "busybox"
Normal Pulled 21s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Successfully pulled image "busybox"
Normal Created 21s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Created container
Normal Started 21s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Started container
Normal Pulled 19s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Successfully pulled image "busybox"
Normal Created 19s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Created container
Normal Started 18s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Started container
Normal Pulling 18s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal pulling image "busybox"
Normal Pulled 16s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Successfully pulled image "busybox"
Normal Created 16s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Created container
Normal Started 15s kubelet, ip-10-200-1-57.ap-northeast-1.compute.internal Started container