https://pulumi.com logo
Title
c

cuddly-dusk-95227

04/14/2021, 11:36 AM
does pulumi offer any functions to generate kubeconfig's ? I have an existing kubernetes cluster, and I want to try and connect to it using pulumi + typescript, the provider can accept a kubeconfig (https://www.pulumi.com/docs/reference/pkg/kubernetes/provider/) which is easy if i'd created the cluster using
pulumi-eks
. what am I missing?
b

billowy-army-68599

04/14/2021, 3:41 PM
There’s no built in function, but you can write one fairly easily - do you need some specific functionality
?
c

cuddly-dusk-95227

04/15/2021, 1:39 AM
it's more a quality-of-life thing; currently i just have:
const cluster = aws.eks.getCluster({name: "mycluster"})

export const kubeConfig = cluster.then(c => JSON.stringify({
    apiVersion: "v1",
    clusters: [
        {
            cluster: {
                "certificate-authority-data": c.certificateAuthority.data,
                server: c.endpoint,
            },
            name: "kubernetes",
        }
    ],
    contexts: [
        {
            context: {
                cluster: "kubernetes",
                user: "aws",
            },
            name: "aws",
        },
    ],
    "current-context": "aws",
    kind: "Config",
    users: [
        {
            name: "aws",
            user: {
                exec: {
                    apiVersion: "<http://client.authentication.k8s.io/v1alpha1|client.authentication.k8s.io/v1alpha1>",
                    args: [
                        "--region",
                        "us-west-2",
                        "eks",
                        "get-token",
                        "--cluster-name",
                        c.name,
                    ],
                    command: "aws",
                }
            }
        },
    ],
}));

const kubeClient = new k8s.Provider("mycluster", { kubeconfig: kubeConfig })

// do stuff
but it looks goofy 🙂