Kubernetes cluster setup in AWS using Terraform and kubeadm
AWS Kubernetes is a Kubernetes cluster deployed using Kubeadm tool. It provides full integration with AWS. It is able to handle ELB load balancers, EBS disks, Route53 domains and other AWS resources.
AWS Kubernetes deploys into an existing VPC / public subnet. If you don't have your VPC / subnet yet, you can use this configuration to create one. To deploy AWS Kubernetes there are no other dependencies apart from Terraform. Kubeadm is used only on the EC2 hosts and doesn't have to be installed locally.
The configuration is done through Terraform variables. Example tfvars
file is part of this repo and is named example.tfvars
. Change the variables to match your environment / requirements before running terraform apply ...
.
Option | Explanation | Example |
---|---|---|
aws_region |
AWS region which should be used | eu-central-1 |
cluster_name |
Name of the Kubernetes cluster (also used to name different AWS resources) | my-aws-kubernetes |
master_instance_type |
AWS EC2 instance type for master | t2.medium |
worker_instance_type |
AWS EC2 instance type for worker | t2.medium |
ssh_public_key |
SSH key to connect to the remote machine | ~/.ssh/id_rsa.pub |
master_subnet_id |
Subnet ID where master should run | subnet-8d3407e5 |
worker_subnet_ids |
List of subnet IDs where workers should run | [ "subnet-8d3407e5" ] |
min_worker_count |
Minimal number of worker nodes | 3 |
max_worker_count |
Maximal number of worker nodes | 6 |
hosted_zone |
DNS zone which should be used | my-domain.com |
hosted_zone_private |
Is the DNS zone public or private | false |
addons |
List of add-ons which should be installed | [ "https://..." ] |
tags |
Tags which should be applied to all resources | see example.tfvars file |
tags2 |
Tags in second format which should be applied to AS groups | see example.tfvars file |
ssh_access_cidr |
List of CIDRs from which SSH access is allowed | [ "0.0.0.0/0" ] |
api_access_cidr |
List of CIDRs from which API access is allowed | [ "0.0.0.0/0" ] |
In order to run workers in additional / different subnet(s) than master you have to tag the subnets with kubernetes.io/cluster/{cluster_name}=shared
. For example kubernetes.io/cluster/my-aws-kubernetes=shared
. During the cluster setup, the bootstrapping script will automatically add these tags to the subnets specified in worker_subnet_ids
.
To create AWS Kubernetes cluster,
AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
terraform apply --var-file example.tfvars
To delete AWS Kubernetes cluster,
AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
terraform destroy --var-file example.tfvars
Currently, following add-ons are supported:
The add-ons will be installed automatically based on the Terraform variables.
Custom add-ons can be added if needed. For every URL in the addons
list, the initialization scripts will automatically call kubectl -f apply <Addon URL>
to deploy it. The cluster is using RBAC. So the custom add-ons have to be RBAC ready.
If you need to tag resources created by your Kubernetes cluster (EBS volumes, ELB load balancers etc.) check this AWS Lambda function which can do the tagging.
##Â Frequently Asked Questions
The Kubernetes Dashboard add-on is by default not exposed to the internet. This is intentional for security reasons (no authentication / authorization) and to save costs for Amazon AWS ELB load balancer.
You can access the dashboard easily fro any computer with installed and configured kubectl
:
kubectl proxy