https://pulumi.com logo
#kubernetes
Title
# kubernetes
f

freezing-rainbow-69763

08/04/2023, 10:59 AM
Hello, would anyone know of a Pulumi mechanism that can detect via
pulumi up
the different number of pods running in a kubernetes cluster compared to the pods defined in the Helm Release and apply the required number of pods? The idea behind this approach is to automatically correct unexpected manual changes in the kubernetes cluster. Example:
Copy code
const nginxIngress = new k8s.helm.v3.Release("nginx-ingress", {
        chart: "ingress-nginx",
        version: "4.0.6",
        repositoryOpts: {
            repo: "<https://kubernetes.github.io/ingress-nginx>",
        },
        values: {
            controller: {
                replicaCount: 2,
                metrics: {
                    enabled: true,
                },
            }
        },
    }, { provider}
);
Nginx is running on 2 pods, I'll scale to 1 pod via kluster IDE.
Pulumi up
does not detect any changes.
c

cuddly-computer-18851

08/04/2023, 11:03 AM
Is there an HPA involved? I think generally you would want your scaling to be dynamic, not driven by pulumi
d

dry-keyboard-94795

08/04/2023, 11:07 AM
You might need to do a
pulumi refresh
first, so that the pulumi state is updated based on changes in k8s
f

freezing-rainbow-69763

08/04/2023, 12:45 PM
@cuddly-computer-18851 HPA is not involved in this example. Scaling in general should be involved. This was just one specific case under special circumstances. @dry-keyboard-94795 I tried
pulumi refresh
and network and cluster changes were detected, but no pod count changes. I have applied
pulumi refresh
but
pulumi up
is still not detecting the changes.
d

dry-keyboard-94795

08/04/2023, 12:52 PM
hmm. I'm not sure if Pulumi tries to do drift detection for the Helm Release resource, then. I think if you were to do the same deploy using helm cli, it also won't update the replicaCount in this case
f

full-eve-52536

08/04/2023, 2:15 PM
I think you are running into one of the limitations described here, @freezing-rainbow-69763 : https://www.pulumi.com/registry/packages/kubernetes/how-to-guides/choosing-the-right-helm-resource-for-your-use-case/#helm-release-resource
image.png
b

bitter-father-26598

08/05/2023, 3:54 PM
Some creativity is likely needed. I have never tried this, but one thing you could try is using pulumi.Command.local to run kubectl get pods, parse and count them, then maybe do a .apply on the output then continue defining pulumi stuff within that apply function based on that output.
And thats if you are able to get the and parse the stdout of a localCommand. https://www.pulumi.com/registry/packages/command/api-docs/local/command/
you can also get the name of pod release resources from the Release object if you care about those
f

freezing-rainbow-69763

08/08/2023, 11:02 AM
Thank you all for responses. The main purpose was to check if there is some mechanism on Pulumi side designed for this purpose. I have concluded from your answers that there is no such mechanism.
b

bitter-father-26598

08/13/2023, 6:00 PM
A key take away is that Pulumi’s helm release is no different from running helm install. If no such mechanism exists naturally in helm, then it wouldn’t in Pulumi….not without a little resource-list-grepping creativity.