Hello, would anyone know of a Pulumi mechanism tha...
# kubernetes
f
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
Is there an HPA involved? I think generally you would want your scaling to be dynamic, not driven by pulumi
d
You might need to do a
pulumi refresh
first, so that the pulumi state is updated based on changes in k8s
f
@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
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
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
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
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
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.