Home > Software engineering >  Are the Kubernetes requested resources by a pod still allocated to it when it is in crashLoopBackOff
Are the Kubernetes requested resources by a pod still allocated to it when it is in crashLoopBackOff

Time:05-09

When a pod is in crashLoopBackOff state (for example), are the requested resources (CPU and MEMORY) still allocated to this pod ?

If you have the answer, please explain how did you do to make sure that it is or not still allocated to the pod <3

CodePudding user response:

I got the answer, here is the test:

However the number of nodes i got or the amount of resources they have, I will create a resourceQuota for the namespace where i will perform the test: resourceQuota.yaml:

apiVersion: v1
kind: ResourceQuota
metadata:
name: test-so
spec:
hard:
    cpu: "10m"
    memory: 10Mi
    pods: "10"

Lets create a busybox deployment that will CrashLoopBackOff with the maximum resource in the ResourceQuota allocated to it, 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

As expected its in CrashLoopBackOff state, however its deployed:

> 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>

lets now create a second deployment with the same ammount of resources, 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

No pods created and here is the status of the replicaset:

❯ 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

So that means that in fact, even if a pod is in CrashLoopBackOff state, it still blocks the requested ammount of memory. We know it now ! hahaha

Have a nice day, bguess

  • Related