Pod 处于 crashLoopBackOff 状态时,Kubernetes 请求的资源是否仍然分配给它?
Are the Kubernetes requested resources by a pod still allocated to it when it is in crashLoopBackOff state?
当一个 pod 处于 crashLoopBackOff 状态时(例如),请求的 资源(CPU 和 MEMORY)是否仍然分配给这个 pod?
如果您有答案,请解释您是如何确保它仍然分配给 pod <3
我得到了答案,这是测试:
无论我获得的节点数量或它们拥有的资源数量如何,我都会为我将执行测试的命名空间创建一个 resourceQuota:
resourceQuota.yaml
:
apiVersion: v1
kind: ResourceQuota
metadata:
name: test-so
spec:
hard:
cpu: "10m"
memory: 10Mi
pods: "10"
让我们创建一个 busybox 部署,它将使用分配给它的 ResourceQuota 中的最大资源进行 CrashLoopBackOff:
deployment1.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test-so
name: test-so
spec:
replicas: 1
selector:
matchLabels:
app: test-so
template:
metadata:
labels:
app: test-so
spec:
containers:
- image: busybox
name: busybox
resources:
requests:
cpu: 10m
memory: 10Mi
正如预期的那样,它处于 CrashLoopBackOff 状态,但是它已部署:
> kubectl get pods -o wide:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/test-so-57f76ccb9b-2w5vk 0/1 CrashLoopBackOff 3 (63s ago) 2m23s 10.244.5.2 so-cluster-1-worker2 <none> <none>
现在让我们使用相同数量的资源创建第二个部署:
deployment2.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test-so2
name: test-so2
spec:
replicas: 1
selector:
matchLabels:
app: test-so2
template:
metadata:
labels:
app: test-so2
spec:
containers:
- image: busybox
name: busybox
resources:
requests:
cpu: 10m
memory: 10Mi
未创建 pods,这是副本集的状态:
❯ k describe rs test-so2-7dd9c65cbd
Name: test-so2-7dd9c65cbd
Namespace: so-tests
Selector: app=test-so2,pod-template-hash=7dd9c65cbd
Labels: app=test-so2
pod-template-hash=7dd9c65cbd
Annotations: deployment.kubernetes.io/desired-replicas: 1
deployment.kubernetes.io/max-replicas: 2
deployment.kubernetes.io/revision: 1
Controlled By: Deployment/test-so2
Replicas: 0 current / 1 desired
Pods Status: 0 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: app=test-so2
pod-template-hash=7dd9c65cbd
Containers:
busybox:
Image: busybox
Port: <none>
Host Port: <none>
Requests:
cpu: 10m
memory: 10Mi
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
ReplicaFailure True FailedCreate
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-7x8qm" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-kv9m4" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-7w7wz" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-8gcnp" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-vllqf" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-2jhnb" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-gjtvw" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-qdq44" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 30s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-69rn7" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 11s (x4 over 29s) replicaset-controller (combined from similar events): Error creating: pods "test-so2-7dd9c65cbd-jjjl4" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
所以这意味着实际上,即使 pod 处于 CrashLoopBackOff 状态,它仍然会阻塞请求的内存量。
我们现在知道了!哈哈哈
祝你有愉快的一天,bguess
当一个 pod 处于 crashLoopBackOff 状态时(例如),请求的 资源(CPU 和 MEMORY)是否仍然分配给这个 pod?
如果您有答案,请解释您是如何确保它仍然分配给 pod <3
我得到了答案,这是测试:
无论我获得的节点数量或它们拥有的资源数量如何,我都会为我将执行测试的命名空间创建一个 resourceQuota:
resourceQuota.yaml
:
apiVersion: v1
kind: ResourceQuota
metadata:
name: test-so
spec:
hard:
cpu: "10m"
memory: 10Mi
pods: "10"
让我们创建一个 busybox 部署,它将使用分配给它的 ResourceQuota 中的最大资源进行 CrashLoopBackOff:
deployment1.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test-so
name: test-so
spec:
replicas: 1
selector:
matchLabels:
app: test-so
template:
metadata:
labels:
app: test-so
spec:
containers:
- image: busybox
name: busybox
resources:
requests:
cpu: 10m
memory: 10Mi
正如预期的那样,它处于 CrashLoopBackOff 状态,但是它已部署:
> kubectl get pods -o wide:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/test-so-57f76ccb9b-2w5vk 0/1 CrashLoopBackOff 3 (63s ago) 2m23s 10.244.5.2 so-cluster-1-worker2 <none> <none>
现在让我们使用相同数量的资源创建第二个部署:
deployment2.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test-so2
name: test-so2
spec:
replicas: 1
selector:
matchLabels:
app: test-so2
template:
metadata:
labels:
app: test-so2
spec:
containers:
- image: busybox
name: busybox
resources:
requests:
cpu: 10m
memory: 10Mi
未创建 pods,这是副本集的状态:
❯ k describe rs test-so2-7dd9c65cbd
Name: test-so2-7dd9c65cbd
Namespace: so-tests
Selector: app=test-so2,pod-template-hash=7dd9c65cbd
Labels: app=test-so2
pod-template-hash=7dd9c65cbd
Annotations: deployment.kubernetes.io/desired-replicas: 1
deployment.kubernetes.io/max-replicas: 2
deployment.kubernetes.io/revision: 1
Controlled By: Deployment/test-so2
Replicas: 0 current / 1 desired
Pods Status: 0 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: app=test-so2
pod-template-hash=7dd9c65cbd
Containers:
busybox:
Image: busybox
Port: <none>
Host Port: <none>
Requests:
cpu: 10m
memory: 10Mi
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
ReplicaFailure True FailedCreate
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-7x8qm" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-kv9m4" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-7w7wz" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-8gcnp" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-vllqf" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-2jhnb" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-gjtvw" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 31s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-qdq44" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 30s replicaset-controller Error creating: pods "test-so2-7dd9c65cbd-69rn7" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
Warning FailedCreate 11s (x4 over 29s) replicaset-controller (combined from similar events): Error creating: pods "test-so2-7dd9c65cbd-jjjl4" is forbidden: exceeded quota: test-so, requested: cpu=10m,memory=10Mi, used: cpu=10m,memory=10Mi, limited: cpu=10m,memory=10Mi
所以这意味着实际上,即使 pod 处于 CrashLoopBackOff 状态,它仍然会阻塞请求的内存量。
我们现在知道了!哈哈哈
祝你有愉快的一天,bguess