Hi All, I have created an EKS Cluster and exportin...
# python
g
Hi All, I have created an EKS Cluster and exporting the cluster object something like this in one of the stacks
Copy code
self.eks_cluster     = eks.Cluster()
pulumi.export('eks_cluster', self.eks_cluster)
From a different stack I am trying to get the cluster object to create ManagedNodeGroups
Copy code
eks_cluster: eks.Cluster = infrastructure.get_output("eks_cluster")
It gives me this error. It only returns a dict object.
Copy code
AttributeError: 'dict' object has no attribute 'urn'
Is is possible to get the exported values as Objects and can be casted? any thoughts?
m
I had the same problem a while ago. As far as I know, it's not possible to export and import the entire
eks.Cluster()
component resource. You can only export values. There is also no equivalent to
aws.eks.getCluster()
(docs) for the pulumi_eks module, see this issue. What you can do, however, is using
aws.eks.NodeGroup
(docs) to add node groups to your cluster. This only requires the cluster's name and will also create what EKS calls a managed node group. You can see in the source code that
eks.ManagedNodeGroup
wraps
aws.eks.NodeGroup
and doesn't do a whole lot more, aside from reading some details from the
eks.Cluster
resource rather than you having to pass them explicitly.
g
I was thinking of adding NodeGroups, but just wanted to leave the AMI for AWS to handle. I think this is the only way to workaround this problem. Let me try NodeGroup. Thank you
m
You don't have to specify an AMI when creating an
aws.eks.NodeGroup
, both
ami_type
and
release_version
are optional parameters. This is exactly the same as for
eks.ManagedNodeGroup
, which simply passes these parameters down to the underlying
aws.eks.NodeGroup
resource (here). The naming is unfortunately really misleading, you'll get the exact same kind of managed node group in both cases.
g
Seems like. wow, it worked!! Thank you!!
m
Glad I could help!
g
Hi @modern-zebra-45309, I need another help. I am exporting the kubeconfig from one stack something like this,
Copy code
pulumi.export('kubeconfig', self.eks_cluster.kubeconfig)
and then while deploying the helm chart on a different stack using the Stack reference to get this value and add a new provider:
Copy code
StackReference(                                stack_name = f"organization/core/{get_stack()}"
                                )
eks_kubeconfig            = _sync_await(infrastructure.get_output_details("kubeconfig")).value
Copy code
eks_cluster_provider    = Provider(
                cluster     = f"{get_stack()}-{subsystem_name}-core-{name}-cluster",
                kubeconfig  = eks_kubeconfig
        )
In the helm chart Release I am passing the following option:
Copy code
opts            = pulumi.ResourceOptions(
                                               
                                                provider    = eks_cluster_provider
                                        )
When I am doing the pulumi up, I am getting this error,
Copy code
can't create Helm Release with unreachable cluster: unable to load Kubernetes client configuration from kubeconfig file. Make sure you have:

         • set up the provider as per <https://www.pulumi.com/registry/packages/kubernetes/installation-configuration/>
Am I missing something here?
m
You don't show your imports and only some of the variable names, so it's a bit hard to tell. You do not have to specify the cluster when instantiating the provider. Handing over a kubeconfig is sufficient:
Copy code
import pulumi
import pulumi_eks as eks
import pulumi_kubernetes as k8s

# first program

cluster = eks.Cluster(...)
pulumi.export("kubeconfig", cluster.kubeconfig)

# second program

first_stack = pulumi.StackReference(...)
k8s_provider = k8s.Provider("k8s-provider", kubeconfig=first_stack.get_output("kubeconfig"))
Hope that helps!