Skip to content

Instantly share code, notes, and snippets.

@fracalo
Created July 24, 2022 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fracalo/50f825460ad4f7a2070b8cacdcbba162 to your computer and use it in GitHub Desktop.
Save fracalo/50f825460ad4f7a2070b8cacdcbba162 to your computer and use it in GitHub Desktop.
cloudformation template for minimal k8s cluster
AWSTemplateFormatVersion: 2010-09-09
Description: cloudformation template for minimal k8s cluster
Parameters:
SSHLocation:
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
Default: 0.0.0.0/0
Description: The IP address range that can be used to SSH to the EC2 instances
MaxLength: '18'
MinLength: '9'
Type: String
KeyName:
ConstraintDescription: must be the name of an existing EC2 KeyPair.
Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
Type: AWS::EC2::KeyPair::KeyName
Ami:
Type: String
Default: ami-0440e5026412ff23f
Instance:
Type: String
Default: t3.large
Resources:
CpInstance:
Type: 'AWS::EC2::Instance'
Properties:
ImageId:
Ref: Ami
InstanceType:
Ref: Instance
KeyName:
Ref: KeyName
BlockDeviceMappings:
- DeviceName: /dev/sdm
Ebs:
VolumeType: io1
Iops: 200
DeleteOnTermination: true
VolumeSize: 20
SecurityGroups:
- Ref: WebServerSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
hostnamectl set-hostname ctrl1
curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
apt-get update && sudo apt-get upgrade -y
apt-get install -y apt-transport-https ca-certificates curl
# apt-get install -y kubeadm kubelet kubectl docker.io
apt-get install -y kubeadm=1.22.1-00 kubelet=1.22.1-00 kubectl=1.22.1-00 docker.io
apt-mark hold kubelet kubeadm kubectl
Tags:
- Key: "Name"
Value: "Ctrl1"
- Key: "Role"
Value: "ctrl"
- Key: "Scope"
Value: "lfs"
WrkInstance:
Type: 'AWS::EC2::Instance'
Properties:
ImageId:
Ref: Ami
InstanceType:
Ref: Instance
KeyName:
Ref: KeyName
BlockDeviceMappings:
- DeviceName: /dev/sdm
Ebs:
VolumeType: io1
Iops: 200
DeleteOnTermination: true
VolumeSize: 20
SecurityGroups:
- Ref: WebServerSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
hostnamectl set-hostname wrk1
curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
apt-get update && sudo apt-get upgrade -y
apt-get install -y apt-transport-https ca-certificates curl
# apt-get install -y kubeadm kubelet kubectl docker.io
apt-get install -y kubeadm=1.22.1-00 kubelet=1.22.1-00 kubectl=1.22.1-00 docker.io
apt-mark hold kubelet kubeadm kubectl
Tags:
- Key: "Name"
Value: "Wrk1"
- Key: "Role"
Value: "wrk"
- Key: "Scope"
Value: "lfs"
WebServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "All open"
SecurityGroupIngress:
- CidrIp: !Ref SSHLocation
FromPort: 0
IpProtocol: "-1"
ToPort: 65535
Outputs:
PublicIpCp:
Value: !GetAtt CpInstance.PublicIp
Description: 'CP public ip'
PublicIpWrk:
Value: !GetAtt WrkInstance.PublicIp
Description: 'Wrk public ip'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment