Get an existing EKS cluster's kubeconfig and create a pulumi_kubernetes Provider from it
PythonIn order to fetch the kubeconfig from an existing EKS cluster, we can utilize the
eks.Cluster
class with theget
method. This will allow us to reference the EKS cluster within our Pulumi program. From there, we can retrieve the kubeconfig usinggetKubeconfig
.After we have fetched kubeconfig, we provide it to
pulumi_kubernetes.Provider
to generate a kubernetes provider.Here's a starting point for your Pulumi program:
import pulumi from pulumi_aws import eks from pulumi_kubernetes import Provider # Get an existing EKS Cluster by its cluster name. # Replace cluster_name with the real name. cluster = eks.Cluster.get("existing_cluster", "cluster_name") # Get kubeconfig of the existing cluster cluster_kubeconfig = cluster.get_kubeconfig() # Create a Kubernetes provider instance using the kubeconfig obtained from the EKS cluster k8s_provider = Provider("k8s-provider", kubeconfig=cluster_kubeconfig) # export the kubeconfig pulumi.export("kubeconfig", cluster_kubeconfig)
The first part of the script retrieves an existing EKS Cluster given its name, and the second part generates a kubeconfig. The kubeconfig is then used to create a new Kubernetes provider instance.
For more information, refer to the following resources in the Pulumi Registry:
- eks.Cluster.get
- eks.Cluster.getKubeconfig
- [pulumi_kubernetes.Provider](https://www.pulumi.com/registry/packages/kubernetess/provider/Please replace " when using this program.