82eedbd622
This trigger ensures the inventory file is kept up-to-date. Otherwise, if the file exists and you've made changes to your terraform-managed infra without having deleted the file, it would never get updated. For example, consider the case where you've destroyed and re-applied the terraform resources, none of the IPs would get updated, so ansible would be trying to connect to the old ones. |
||
---|---|---|
.. | ||
docs | ||
modules | ||
templates | ||
.gitignore | ||
create-infrastructure.tf | ||
credentials.tfvars.example | ||
output.tf | ||
README.md | ||
terraform.tfvars | ||
terraform.tfvars.example | ||
variables.tf |
Kubernetes on AWS with Terraform
Overview:
This project will create:
- VPC with Public and Private Subnets in # Availability Zones
- Bastion Hosts and NAT Gateways in the Public Subnet
- A dynamic number of masters, etcd, and worker nodes in the Private Subnet
- even distributed over the # of Availability Zones
- AWS ELB in the Public Subnet for accessing the Kubernetes API from the internet
Requirements
- Terraform 0.8.7 or newer
How to Use:
- Export the variables for your AWS credentials or edit
credentials.tfvars
:
export AWS_ACCESS_KEY_ID="www"
export AWS_SECRET_ACCESS_KEY ="xxx"
export AWS_SSH_KEY_NAME="yyy"
export AWS_DEFAULT_REGION="zzz"
-
Rename
contrib/terraform/aws/terraform.tfvars.example
toterraform.tfvars
-
Update
contrib/terraform/aws/terraform.tfvars
with your data -
Allocate new AWS Elastic IPs: Depending on # of Availability Zones used (2 for each AZ)
-
Create an AWS EC2 SSH Key
-
Run with
terraform apply --var-file="credentials.tfvars"
orterraform apply
depending if you exported your AWS credentials -
Terraform automatically creates an Ansible Inventory file called
hosts
with the created infrastructure in the directoryinventory
-
Once the infrastructure is created, you can run the kubespray playbooks and supply inventory/hosts with the
-i
flag.
Troubleshooting
Remaining AWS IAM Instance Profile:
If the cluster was destroyed without using Terraform it is possible that
the AWS IAM Instance Profiles still remain. To delete them you can use
the AWS CLI
with the following command:
aws iam delete-instance-profile --region <region_name> --instance-profile-name <profile_name>
Ansible Inventory doesnt get created:
It could happen that Terraform doesnt create an Ansible Inventory file automatically. If this is the case copy the output after inventory=
and create a file named hosts
in the directory inventory
and paste the inventory into the file.
Architecture
Pictured is an AWS Infrastructure created with this Terraform project distributed over two Availability Zones.