Pulumi get kubernetes context at runtime

1/30/2020

Is there a way to get the current kubernetes context at runtime to prevent calling pulumi up with the incorrect context? I'd specifically like to make sure my local kubernetes deployment logic doesn't end up in anything other than a local cluster.

I've gone through the examples and don't see anything that does this: https://github.com/pulumi/examples/search?l=TypeScript&p=2&q=context&type= (maybe I'm thinking about my problem the wrong way).

-- Paymahn Moghadasian
kubernetes
pulumi
typescript

1 Answer

1/30/2020

As explained here, first you have to create a context for your cluster that will be used, for example:

kubectl config \
    set-context <my-context> \
    --cluster=<my-cluster> \
    --user=<my-user>

Then run pulumi stack init new-kube-stack where you will be asked to enter your access token and finally run pulumi config set kubernetes:context my-context to work in a cluster defined in previously created context.

-- KFC_
Source: StackOverflow