Description: This template deploys a 2 node kubernetes cluster with spot instances in a VPC with a single public subnet in 1 AZ. The master node is t3a.small and worker node is t3a.micro Parameters: KeyName: Description: Name of an existing EC2 KeyPair to enable SSH access to the EC2 instances Type: AWS::EC2::KeyPair::KeyName ConstraintDescription: must be the name of an existing EC2 KeyPair. Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 EnableDnsSupport: true EnableDnsHostnames: true Tags: - Key: Name Value: k8s InternetGateway: Type: AWS::EC2::InternetGateway Properties: Tags: - Key: Name Value: k8s InternetGatewayAttachment: Type: AWS::EC2::VPCGatewayAttachment Properties: InternetGatewayId: !Ref InternetGateway VpcId: !Ref VPC PublicSubnet1: Type: AWS::EC2::Subnet Properties: VpcId: !Ref VPC AvailabilityZone: !Select [ 0, !GetAZs '' ] CidrBlock: 10.0.0.0/24 MapPublicIpOnLaunch: true Tags: - Key: Name Value: k8s public subnet PublicRouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref VPC Tags: - Key: Name Value: k8s public routes DefaultPublicRoute: Type: AWS::EC2::Route DependsOn: InternetGatewayAttachment Properties: RouteTableId: !Ref PublicRouteTable DestinationCidrBlock: 0.0.0.0/0 GatewayId: !Ref InternetGateway PublicSubnet1RouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: !Ref PublicRouteTable SubnetId: !Ref PublicSubnet1 SpotFleetMaster: Type: AWS::EC2::SpotFleet DependsOn: - SpotFleetRole - InstanceSecurityGroup Properties: SpotFleetRequestConfigData: IamFleetRole: Fn::GetAtt: - SpotFleetRole - Arn LaunchSpecifications: - ImageId: ami-04763b3055de4860b InstanceType: t3a.small KeyName: Ref: KeyName SecurityGroups: - GroupId: Ref: InstanceSecurityGroup SubnetId: !Ref PublicSubnet1 TagSpecifications: - ResourceType: instance Tags: - Key: Name Value: master UserData: Fn::Base64: | #!/bin/bash -xe hostnamectl set-hostname master echo master > /etc/hostname echo "127.0.0.1 master" >> /etc/hosts swapoff -a # Install Docker CE ## Set up the repository: ### Install packages to allow apt to use a repository over HTTPS apt-get update && apt-get install -y \ apt-transport-https ca-certificates curl software-properties-common ### Add Docker’s official GPG key curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - ### Add Docker apt repository. add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" ## Install Docker CE. apt-get update && apt-get install -y \ containerd.io=1.2.10-3 \ docker-ce=5:19.03.4~3-0~ubuntu-$(lsb_release -cs) \ docker-ce-cli=5:19.03.4~3-0~ubuntu-$(lsb_release -cs) # Setup daemon. cat > /etc/docker/daemon.json < $UBUNTU_HOME/join.txt kubeadm token create --print-join-command >> $UBUNTU_HOME/join.txt TargetCapacity: 1 TerminateInstancesWithExpiration: true Type: request SpotFleetWorker: Type: AWS::EC2::SpotFleet DependsOn: - SpotFleetRole - InstanceSecurityGroup Properties: SpotFleetRequestConfigData: IamFleetRole: Fn::GetAtt: - SpotFleetRole - Arn LaunchSpecifications: - ImageId: ami-04763b3055de4860b InstanceType: t3a.micro KeyName: Ref: KeyName SecurityGroups: - GroupId: Ref: InstanceSecurityGroup SubnetId: !Ref PublicSubnet1 TagSpecifications: - ResourceType: instance Tags: - Key: Name Value: node01 UserData: Fn::Base64: | #!/bin/bash -xe hostnamectl set-hostname node01 echo node01 > /etc/hostname echo "127.0.0.1 node01" >> /etc/hosts swapoff -a # Install Docker CE ## Set up the repository: ### Install packages to allow apt to use a repository over HTTPS apt-get update && apt-get install -y \ apt-transport-https ca-certificates curl software-properties-common ### Add Docker’s official GPG key curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - ### Add Docker apt repository. add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" ## Install Docker CE. apt-get update && apt-get install -y \ containerd.io=1.2.10-3 \ docker-ce=5:19.03.4~3-0~ubuntu-$(lsb_release -cs) \ docker-ce-cli=5:19.03.4~3-0~ubuntu-$(lsb_release -cs) # Setup daemon. cat > /etc/docker/daemon.json <