Hi, I need to portForward my grafana/prom to be ab...
# kubernetes
a
Hi, I need to portForward my grafana/prom to be able to run some command with the grafana provider. Today I have portforward function and service, this works fine for a
up
but on delete or refresh this is not working. How can I make it work ? My portForward function:
Copy code
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";

export function forwardPrometheusService(
    service: pulumi.Input<k8s.core.v1.Service>,
    deployment: pulumi.Input<k8s.extensions.v1beta1.Deployment>,
    opts: PromPortForwardOpts,
): pulumi.Output<() => void> {
    if (pulumi.runtime.isDryRun()) {
        return pulumi.output(() => undefined);
    }

    return pulumi.all([service, deployment]).apply(([s, d]) => pulumi.all([s.metadata, d.urn])).apply(([meta]) => {
        return new Promise<() => void>((resolve, reject) => {
            const forwarderHandle = spawn("kubectl", [
                "port-forward",
                `service/${meta.name}`,
                `${opts.localPort}:${opts.targetPort || 80}`,
            ]);

            forwarderHandle.stdout.on("data", data => resolve(() => forwarderHandle.kill()));
            forwarderHandle.stderr.on("data", data => reject());
        });
    });
}
h
pulumi doesn’t execute your program during delete/refresh operations. can you say a little bit about what you’re trying to accomplish with this? are you trying to programmatically manage dashboards?
a
I want to manage, alert-rules and contactPoints
So I need to run kubectl port forward so my provider can access the service. A bit like in the doc here: https://www.pulumi.com/docs/using-pulumi/organizing-projects-stacks/#organizing-your-project-code
h
that’s an interesting example. it sounds like you’re already using the grafana provider? what url are you using to access grafana, and can you point the provider at that instead?
a
In pulumi up its working I’m using 127.0.0.1
127.0.0.1:3000 the port forwarding that target my service in the cluster
My only issue is in pulumi refresh or delete
h
do you not intend to expose grafana outside of your cluster (e.g. Ingress)? you are only going to use it with port forwarding?
a
Yes, but my DNS is not yet done and managed by another stack so I can’t use the URL exposed publicly
h
i would start there. as i already mentioned, your program isn’t executed during refresh or delete so your port forwarding won’t be invoked. once you have an address for grafana you can manage these things via the provider and everything will work like you would expect.
a
Hmm, and so I can’t make it work If I don’t want to expose it ? for example prometheus
h
yes, in order to manipulate things inside the cluster you’ll want to expose them somehow. this doesn’t necessarily mean they need to be public-internet facing. you could use something like tailscale operator to expose them behind a VPN for example.
a
Or I should otherwise run the port-forward in a script on side ?
h
that might also work.
a
Will try, but its annoying 😕