pulumi-kubernetes icon indicating copy to clipboard operation
pulumi-kubernetes copied to clipboard

Allow `k8s.core.v1.Namespace` accepts kubeconfig from code source

Open thepabloaguilar opened this issue 2 years ago • 3 comments

Allow k8s.core.v1.Namespace accepts kubeconfig from code source

Issue details

Hello, I'm using Pulumi to create a EKS cluster and after that I'd like to create the namespaces too. Now I'm unable to do that since the K8S operator expects the Kube Config on $KUBECONFIG, ~/.kube/config, and kubernetes:kubeconfig. It'll be great if I can pass through the code!

Affected area/feature

Pulumi Kubernetes package!

thepabloaguilar avatar Mar 02 '22 03:03 thepabloaguilar

The solution I'm trying to do right now is:

def export_kubeconfig(config: str) -> pulumi.Output[str]:
    config_file_path = Path.home().joinpath('.kube', 'config')
    with open(config_file_path, 'w') as config_file:
        config_file.write(config)

    return pulumi.Output.from_input(config)


kubeconfig = generate_kube_config(default_eks_cluster).apply(export_kubeconfig)
pulumi.export('my-cluster-config', kubeconfig)

And putting my Namespace creation as dependent of EKS creation

thepabloaguilar avatar Mar 02 '22 03:03 thepabloaguilar

Hi @thepabloaguilar - thank you for the suggestion! As always, feel free to try your hand at implementation.

I've transferred this issue to our kubernetes provider repo in the meantime. 😃

guineveresaenger avatar Mar 07 '22 23:03 guineveresaenger

You can initialize new kubernetes.Provider and pass kubeconfig from your cluster to it. Pass the initialized provider to the Namespace resource options.

Example (in TypeScript):

import * as k8s from '@pulumi/kubernetes'

const myProvider = new k8s.Provider('my-provider', {
  kubeconfig: 'insert string or kubeconfig as output from EKS cluster'
})

new k8s.core.v1.Namespace('my-namespace',
  { /* your namespace options */ },
  { provider: myProvider }
)

covik avatar Mar 09 '22 09:03 covik