Hi, I am working on my first Pulumi project (TS). ...
# kubernetes
f
Hi, I am working on my first Pulumi project (TS). I just deployed an EKS cluster with the AWS provider. Now I'm trying to deploy Helm charts on it. I'm more used to Terraform when it comes to configuring Kubernetes or Helm providers for deployment on the cluster. With Pulumi, I'm a little confused. I need a kubeconfig to define the Kubernetes provider, but I can't seem to dynamically retrieve this kubeconfig file. So I tried to write this kubeconfig, but I'm not sure if this is the right way to do it.
s
Copy code
# create cluster via pulumi_eks provider
aws_cluster = pulumi_eks.Cluster(SETTINGS HERE)
# Create a Kubernetes provider using the generated kubeconfig
kubeconfig = aws_cluster.kubeconfig_json
k8s_provider = k8s.Provider(
    f"{local_name}_k8s_provider",
    kubeconfig=kubeconfig,
    opts=pulumi.ResourceOptions(
        depends_on=[
            aws_cluster,
        ]
    ),
)
# DATADOG
datadog_agent_chart = k8s.helm.v3.Release(
    f"{local_name}_datadog_agent_chart",
    k8s.helm.v3.ReleaseArgs(
        name="datadog-agent",
        chart="datadog",
        version=datadog_helm_version,
        repository_opts=k8s.helm.v3.RepositoryOptsArgs(
            repo="<https://helm.datadoghq.com>",
        ),
        namespace="datadog",
        create_namespace=True,
        wait_for_jobs=True,
        skip_await=False,
        values=datadog_values,
    ),
    opts=pulumi.ResourceOptions(provider=k8s_provider),
)
if you want to do it via the generic aws provider:
Copy code
# Create an EKS Cluster with AWS Provider
karmada_cluster = aws.eks.Cluster(CONFIGURATION)

# Create a Kubernetes provider using the generated kubeconfig
kubeconfig = pulumi.Output.all(
    cluster_name=karmada_cluster.name,
    endpoint=karmada_cluster.endpoint,
    cert=karmada_cluster.certificate_authority,
).apply(
    lambda args: json.dumps(
        {
            "apiVersion": "v1",
            "clusters": [
                {
                    "cluster": {
                        "server": args["endpoint"],
                        "certificate-authority-data": args["cert"]["data"],
                    },
                    "name": args["cluster_name"],
                }
            ],
            "contexts": [
                {
                    "context": {
                        "cluster": args["cluster_name"],
                        "user": args["cluster_name"],
                    },
                    "name": args["cluster_name"],
                }
            ],
            "current-context": args["cluster_name"],
            "kind": "Config",
            "users": [
                {
                    "name": args["cluster_name"],
                    "user": {
                        "exec": {
                            "apiVersion": "<http://client.authentication.k8s.io/v1beta1|client.authentication.k8s.io/v1beta1>",
                            "command": "aws",
                            "args": [
                                "eks",
                                "get-token",
                                "--cluster-name",
                                args["cluster_name"],
                            ],
                        }
                    },
                }
            ],
        }
    )
)
k8s_provider = k8s.Provider(
    f"{local_name}_k8s_provider",
    kubeconfig=kubeconfig,
    opts=pulumi.ResourceOptions(
        depends_on=[
            eks_identity_provider,
            karmada_workers,
        ]
    ),
)

# NVME
nvme_provisioner_chart = k8s.helm.v3.Release(
    f"{local_name}_nvme_provisioner_chart",
    k8s.helm.v3.ReleaseArgs(
        name="nvme-provisioner",
        chart="./clouds/aws/operators/eks_nvme_ssd_provisioner/helm/eks-nvme-ssd-provisioner",
        namespace="kube-system",
        create_namespace=True,
        wait_for_jobs=True,
        skip_await=False,
        values=pulumi.Output.all(
            repo_url=nvme_provisioner_repo.repository_url,
            image_url=nvme_provisioner_image,
        ).apply(
            lambda args: {"image": {"repository": args["repo_url"], "tag": "latest"}},
        ),
    ),
    opts=pulumi.ResourceOptions(provider=k8s_provider),
)
👍 1