Kube State Deployment Replicas Metrics

1.5k Views Asked by At

I'm new to K8s and Kubernetes. Could someone please explain me the difference between the following kube state metrics... I've included the best descriptions I could find but I need some more context:

  • kube_deployment_spec_replicas - Number of desired pods for a deployment.
  • kube_deployment_status_replicas - The number of replicas per deployment.
  • kube_deployment_status_replicas_available - The number of available replicas per deployment.
  • kube_deployment_status_replicas_unavailable - The number of unavailable replicas per deployment.

So my take away is:

  • kube_deployment_spec_replicas=desired
  • kube_deployment_status_replicas=current

Then of the current pods, some are available or not.

Does that mean that kube_deployment_status_replicas_unavailable = kube_deployment_status_replicas-kube_deployment_status_replicas_available

Would appreciate any deeper understanding of what exactly these metrics mean.

2

There are 2 best solutions below

0
MrE On

I think you answered your own question.

In k8s, you can scale up/down deployments, yet that ability depends on the node capacity.

So if you start with a deployment of some service and 2 replicas. This will liekly deploy right away and you'll have 2 pods available right away. 2 desired, 2 available, none unavailable.

Now, say you scale this deployment to 100 pods. You'll have 100 desired, but 2 actual replicas at first, 2 available, then the scheduler will 'schedule' the 100 pods, but the node may not have the capacity, so it may be able to deploy 20, and 80 will be 'pending' and therefore unavailable. Desired is 100, actual is 20, and unavailable is 80, until the cluster scales up (assuming you have autoscaler or you manually add a node), then the pods can be scheduled and will become available.

0
Siegfred V. On

So my take away is:

kube_deployment_spec_replicas=desired
kube_deployment_status_replicas=current

You are correct on this, kube_deployment_spec_replicas is the desired state and kube_deployment_status_replicas is the actual/current state

kube_deployment_status_replicas_unavailable - are ones that are not available yet (e.g. are failing pods).

kube_deployment_status_replicas_unavailable = kube_deployment_spec_replicas minus kube_deployment_status_replicas_available


minReadySeconds determines if the pod will be considered as available or unavailable.

spec.minReadySeconds is an optional field that specifies the minimum number of seconds for which a newly created Pod should be ready without any of its containers crashing, for it to be considered available.

If the minReadySeconds is set to 60, it needs to be up for 60 seconds without any crashes to be considered "available".