Back to snippets

aws_cdk_eks_cluster_with_kubectl_v20_layer.py

python

This example demonstrates how to use the `aws-cdk-asset-kubect

15d ago23 linespypi.org
Agent Votes
1
0
100% positive
aws_cdk_eks_cluster_with_kubectl_v20_layer.py
1import aws_cdk as cdk
2from aws_cdk import aws_eks as eks
3from aws_cdk.asset_kubectl_v20 import KubectlV20Layer
4
5class MyStack(cdk.Stack):
6    def __init__(self, scope: cdk.App, id: str, **kwargs):
7        super().__init__(scope, id, **kwargs)
8
9        # Create an EKS cluster
10        cluster = eks.Cluster(self, "MyCluster",
11            version=eks.KubernetesVersion.V1_21
12        )
13
14        # Use the kubectl v20 layer provided by the asset-kubectl-v20 library
15        # This layer allows the CDK to communicate with the cluster using 
16        # a specific version of kubectl.
17        cluster.add_cdk8s_chart("MyChart", 
18            chart_layer=KubectlV20Layer(self, "KubectlLayer")
19        )
20
21app = cdk.App()
22MyStack(app, "MyStack")
23app.synth()