You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.1 KiB

  1. ## Kubernetes on AWS with Terraform
  2. **Overview:**
  3. This project will create:
  4. * VPC with Public and Private Subnets in # Availability Zones
  5. * Bastion Hosts and NAT Gateways in the Public Subnet
  6. * A dynamic number of masters, etcd, and worker nodes in the Private Subnet
  7. * even distributed over the # of Availability Zones
  8. * AWS ELB in the Public Subnet for accessing the Kubernetes API from the internet
  9. **Requirements**
  10. - Terraform 0.8.7 or newer
  11. **How to Use:**
  12. - Export the variables for your AWS credentials or edit `credentials.tfvars`:
  13. ```
  14. export AWS_ACCESS_KEY_ID="www"
  15. export AWS_SECRET_ACCESS_KEY ="xxx"
  16. export AWS_SSH_KEY_NAME="yyy"
  17. export AWS_DEFAULT_REGION="zzz"
  18. ```
  19. - Rename `contrib/terraform/aws/terraform.tfvars.example` to `terraform.tfvars`
  20. - Update `contrib/terraform/aws/terraform.tfvars` with your data
  21. - Allocate new AWS Elastic IPs: Depending on # of Availability Zones used (2 for each AZ)
  22. - Create an AWS EC2 SSH Key
  23. - Run with `terraform apply --var-file="credentials.tfvars"` or `terraform apply` depending if you exported your AWS credentials
  24. - Terraform automatically creates an Ansible Inventory file called `hosts` with the created infrastructure in the directory `inventory`
  25. - Once the infrastructure is created, you can run the kubespray playbooks and supply inventory/hosts with the `-i` flag.
  26. **Troubleshooting**
  27. ***Remaining AWS IAM Instance Profile***:
  28. If the cluster was destroyed without using Terraform it is possible that
  29. the AWS IAM Instance Profiles still remain. To delete them you can use
  30. the `AWS CLI` with the following command:
  31. ```
  32. aws iam delete-instance-profile --region <region_name> --instance-profile-name <profile_name>
  33. ```
  34. ***Ansible Inventory doesnt get created:***
  35. 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.
  36. **Architecture**
  37. Pictured is an AWS Infrastructure created with this Terraform project distributed over two Availability Zones.
  38. ![AWS Infrastructure with Terraform ](docs/aws_kubespray.png)