ContainerCreating in Kubernetes

kubernetes

When updating a Kubernetes RollingUpdate deployment, kubectl get pods shows some of the pods spend a few minutes in the ContainerCreating state before moving to Running. Unfortunately, the official documentation on pod states doesn't include this as a documented state. Even the kubernetes codebase has only two mentions of the term, and neither has any sort of explanatory comment.

I've been doing some adjustments to the rolling update deployment configuration value (maxUnavailable and maxSurge) and the probe configuration (initialDelaySeconds), and I'm unsure if the container startup time that these values are affecting is part of ContainerCreating or another state.

Best Answer

The ContainerCreating state is applicable when the number of containers equals or is smaller than 0.

Comprehensive

According to the code snippet that is defined in the question the ContainerCreating status seems to be the default waiting state. Only if the hasInitContainers is true the defaultWaitingState will become PodInitializing. This is also indicated by the test that is mentioned as well in the question. In case of without-old-record, with-old-record or something else the ContainerState will be Reason: startWaitingReason, i.e. "ContainerCreating"

hasInitContainers

https://github.com/kubernetes/kubernetes/blob/427dfd5ce1483ead29568bf7c05a98c4c0ad081c/pkg/kubelet/kubelet_pods.go#L1256

  apiPodStatus.ContainerStatuses = kl.convertToAPIContainerStatuses(
      pod, podStatus,
      pod.Status.ContainerStatuses,
      pod.Spec.Containers,
      len(pod.Spec.InitContainers) > 0,
      false,
  )
  apiPodStatus.InitContainerStatuses = kl.convertToAPIContainerStatuses(
      pod, podStatus,
      pod.Status.InitContainerStatuses,
      pod.Spec.InitContainers,
      len(pod.Spec.InitContainers) > 0,
      true,
)