EKS deployment using CDK showing Kubernetes version error

6/8/2021

I am trying to deploy my EKS cluster using Python CDK. I am following this(https://github.com/pahud/aws-cdk-python-workshop/tree/master/Lab6) link for implementation. Everything is working good, but when I do 'cdk deploy', it is showing following error: enter image description here

On Cloudformation console it is showing following error:

enter image description here

I tried changing version to 1.20, 1.20.4, 1.16, 1.16.5, etc(https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html) in cdk_pycon_eks_stack.py in following way,

...................

# create the cluster
        cluster = aws_eks.Cluster(self, 'cluster',
                                  masters_role=eks_admin_role,
                                  vpc=vpc,
                                  default_capacity=0,
                                  version='1.20',
                                  output_cluster_name=True
                                  )

...........................................

, but then it shows following error:

enter image description here

Any help would be appreciated!! Thanks


Edit:

Additional images for reference in comments/Answers: for version = aws_eks.KubernetesVersion.of("v1_20") enter image description here

for version = aws_eks.KubernetesVersion().V1_20

enter image description here

-- Hetul Sheth
amazon-cloudformation
amazon-eks
aws-cdk
kubernetes
python

2 Answers

6/8/2021

The code here is looking for a full KubernetesVersion object, not a string.
Take a look at: https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_eks/KubernetesVersion.html#aws_cdk.aws_eks.KubernetesVersion
So you could do something like (forgive me this is untested, as I usually use TypeScript for CDK):

version = aws_eks.KubernetesVersion().V1_20

or maybe:

version = aws_eks.KubernetesVersion.of("v1_20") #string may be something else, try it and see
-- jonlegend
Source: StackOverflow

6/9/2021
        # Create EKS cluster
        self.eks_cluster = eks.Cluster(
            scope=self, id='EKSDevCluster',
            vpc=eks_private_vpc,
            default_capacity=0,
            cluster_name='eks-dev',
            masters_role=eks_admin_role,
            core_dns_compute_type=eks.CoreDnsComputeType.EC2,
            version=eks.KubernetesVersion.V1_20,
            role=node_role
        )
-- vumdao
Source: StackOverflow