{"record":{"id":"af27fa643f0bb095","repo":"cilium/cilium","slug":"replicas-count-is-zero","errorCode":null,"errorMessage":"replicas count is zero","messagePattern":"replicas count is zero","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cilium-cli/k8s/client.go","lineNumber":285,"sourceCode":"}\n\nfunc (c *Client) CheckDeploymentStatus(ctx context.Context, namespace, deployment string) error {\n\td, err := c.GetDeployment(ctx, namespace, deployment, metav1.GetOptions{})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif d == nil {\n\t\treturn fmt.Errorf(\"deployment is not available\")\n\t}\n\n\tif d.Status.ObservedGeneration != d.Generation {\n\t\treturn fmt.Errorf(\"observed generation (%d) is older than generation of the desired state (%d)\",\n\t\t\td.Status.ObservedGeneration, d.Generation)\n\t}\n\n\tif d.Status.Replicas == 0 {\n\t\treturn fmt.Errorf(\"replicas count is zero\")\n\t}\n\n\tif d.Status.AvailableReplicas != d.Status.Replicas {\n\t\treturn fmt.Errorf(\"only %d of %d replicas are available\", d.Status.AvailableReplicas, d.Status.Replicas)\n\t}\n\n\tif d.Status.ReadyReplicas != d.Status.Replicas {\n\t\treturn fmt.Errorf(\"only %d of %d replicas are ready\", d.Status.ReadyReplicas, d.Status.Replicas)\n\t}\n\n\tif d.Status.UpdatedReplicas != d.Status.Replicas {\n\t\treturn fmt.Errorf(\"only %d of %d replicas are up-to-date\", d.Status.UpdatedReplicas, d.Status.Replicas)\n\t}\n\n\treturn nil\n}\n\nfunc (c *Client) CreateNamespace(ctx context.Context, namespace *corev1.Namespace, opts metav1.CreateOptions) (*corev1.Namespace, error) {","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/cilium-cli/k8s/client.go#L267-L303","documentation":"The Deployment reports status.replicas == 0, meaning no pods are currently part of the deployment. cilium-cli fails fast on this rather than proceeding with a deployment that has no backing pods.","triggerScenarios":"CheckDeploymentStatus reads a Deployment whose spec has 0 replicas or whose ReplicaSet produced no pods — e.g. during rollout, scale-to-zero, or scheduling failure.","commonSituations":"Cilium deployment scaled to 0 manually or by resource constraints; scheduling failures (taints, insufficient resources) preventing pod creation; rollout just started.","solutions":["Check deployment spec replicas: 'kubectl get deploy <name> -o jsonpath={.spec.replicas}' and scale back up if 0","Inspect pods/ReplicaSet events: 'kubectl describe deployment <name>' and 'kubectl get rs,pods -l <selector>'","Check node taints/resource limits that block pod scheduling","Wait for rollout if this is a transient state during upgrade"],"exampleFix":"// before\nkubectl scale deployment cilium -n kube-system --replicas=0\n// after\nkubectl scale deployment cilium -n kube-system --replicas=1","handlingStrategy":"validation","validationCode":"d, _ := clientset.AppsV1().Deployments(ns).Get(ctx, name, metav1.GetOptions{})\nif d != nil && (d.Spec.Replicas == nil || *d.Spec.Replicas == 0) {\n    return fmt.Errorf(\"deployment %s/%s is scaled to zero\", ns, name)\n}","typeGuard":"func hasReplicas(d *appsv1.Deployment) bool {\n    return d != nil && d.Status.Replicas > 0\n}","tryCatchPattern":"err := client.CheckDeploymentStatus(ctx, ns, name)\nif err != nil {\n    if err.Error() == \"replicas count is zero\" {\n        // scale deployment back up, then retry\n    }\n    return err\n}","preventionTips":["Never scale cilium deployments to 0 permanently","Check taints/resources so pods can schedule","Include replica checks in preflight validation"],"tags":["kubernetes","deployment","replicas"],"backgroundTag":"deployment-replicas-zero","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}