Skip to content

Instantly share code, notes, and snippets.

@iferca
Last active Apr 6, 2020
Embed
What would you like to do?
from aws_cdk import (
core,
aws_ec2 as ec2,
aws_eks as eks,
aws_iam as iam
)
class StackK8SStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
cluster_name = "SampleCluster"
eks_vpc_id = "XXX-foreign-vpc-id-YYY"
eks_vpc = ec2.Vpc.from_lookup(self, id="EKS_MSK_VPC",
vpc_id=eks_vpc_id,
vpc_name="stack-networking/EKS_MSK_VPC")
eks_admin_role = iam.Role(self, f"{cluster_name}-AdminRole",
assumed_by=iam.AccountPrincipal(account_id=self.account))
eks_cluster = eks.Cluster(self, f"{cluster_name}",
cluster_name=f"{cluster_name}",
masters_role=eks_admin_role,
kubectl_enabled=True,
version="1.15",
vpc=eks_vpc)
eks_cluster.add_capacity("ondemand-worker", instance_type=ec2.InstanceType("t3.large"),
min_capacity=1, max_capacity=3,
bootstrap_options=eks.BootstrapOptions(
kubelet_extra_args='--node-labels lifecycle=ondemand'
))
eks_cluster.add_resource("fargate-namespace", {
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "fargate",
"labels": {
"name": "fargate"
}
}
})
eks_cluster.add_capacity("spot-worker", instance_type=ec2.InstanceType("t3.large"),
min_capacity=1, max_capacity=3, spot_price='0.0912',
bootstrap_options=eks.BootstrapOptions(
kubelet_extra_args='--node-labels lifecycle=spot'
))
eks_cluster.add_fargate_profile("default-fargate-profile",
fargate_profile_name="default",
selectors=[eks.Selector(namespace="fargate")],
vpc=eks_cluster.vpc)
eks_cluster.add_chart("k8s-dashboard", chart="kubernetes-dashboard", namespace="fargate",
repository="https://kubernetes-charts.storage.googleapis.com/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment