2017-09-18 07:50:55 +02:00
# AWS
2018-04-24 06:36:20 +02:00
!!! danger
Typhoon for Fedora Atomic is alpha. Expect rough edges and changes.
2017-09-18 07:50:55 +02:00
2018-10-28 00:47:57 +02:00
In this tutorial, we'll create a Kubernetes v1.12.2 cluster on AWS with Fedora Atomic.
2017-09-18 07:50:55 +02:00
2018-06-24 00:15:57 +02:00
We'll declare a Kubernetes cluster using the Typhoon Terraform module. Then apply the changes to create a VPC, gateway, subnets, security groups, controller instances, worker auto-scaling group, network load balancer, and TLS assets. Instances are provisioned on first boot with cloud-init.
2018-04-24 06:36:20 +02:00
2018-07-02 04:41:57 +02:00
Controllers are provisioned to run an `etcd` peer and a `kubelet` service. Workers run just a `kubelet` service. A one-time [bootkube ](https://github.com/kubernetes-incubator/bootkube ) bootstrap schedules the `apiserver` , `scheduler` , `controller-manager` , and `coredns` on controllers and schedules `kube-proxy` and `calico` (or `flannel` ) on every node. A generated `kubeconfig` provides `kubectl` access to the cluster.
2017-09-18 07:50:55 +02:00
## Requirements
* AWS Account and IAM credentials
* AWS Route53 DNS Zone (registered Domain Name or delegated subdomain)
2018-04-24 06:36:20 +02:00
* Terraform v0.11.x installed locally
2017-09-18 07:50:55 +02:00
## Terraform Setup
2018-01-12 15:56:08 +01:00
Install [Terraform ](https://www.terraform.io/downloads.html ) v0.11.x on your system.
2017-09-18 07:50:55 +02:00
```sh
$ terraform version
2018-04-24 06:36:20 +02:00
Terraform v0.11.7
2017-09-18 07:50:55 +02:00
```
2018-10-07 19:57:16 +02:00
Read [concepts ](/architecture/concepts/ ) to learn about Terraform, modules, and organizing resources. Change to your infrastructure repository (e.g. `infra` ).
2017-09-18 07:50:55 +02:00
```
cd infra/clusters
```
## Provider
Login to your AWS IAM dashboard and find your IAM user. Select "Security Credentials" and create an access key. Save the id and secret to a file that can be referenced in configs.
```
[default]
aws_access_key_id = xxx
aws_secret_access_key = yyy
```
Configure the AWS provider to use your access key credentials in a `providers.tf` file.
```tf
provider "aws" {
2018-05-02 23:41:38 +02:00
version = "~> 1.13.0"
2018-01-12 15:56:08 +01:00
alias = "default"
2017-09-18 07:50:55 +02:00
region = "eu-central-1"
shared_credentials_file = "/home/user/.config/aws/credentials"
}
2018-01-12 15:56:08 +01:00
provider "local" {
version = "~> 1.0"
alias = "default"
}
provider "null" {
version = "~> 1.0"
alias = "default"
}
provider "template" {
version = "~> 1.0"
alias = "default"
}
provider "tls" {
version = "~> 1.0"
alias = "default"
}
2017-09-18 07:50:55 +02:00
```
Additional configuration options are described in the `aws` provider [docs ](https://www.terraform.io/docs/providers/aws/ ).
!!! tip
Regions are listed in [docs ](http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region ) or with `aws ec2 describe-regions` .
## Cluster
2018-04-24 06:36:20 +02:00
Define a Kubernetes cluster using the module `aws/fedora-atomic/kubernetes` .
2017-09-18 07:50:55 +02:00
```tf
module "aws-tempest" {
2018-10-28 00:47:57 +02:00
source = "git::https://github.com/poseidon/typhoon//aws/fedora-atomic/kubernetes?ref=v1.12.2"
2017-09-18 07:50:55 +02:00
2018-01-12 15:56:08 +01:00
providers = {
aws = "aws.default"
local = "local.default"
null = "null.default"
template = "template.default"
tls = "tls.default"
}
2017-09-18 07:50:55 +02:00
# AWS
2018-03-26 05:41:52 +02:00
cluster_name = "tempest"
dns_zone = "aws.example.com"
dns_zone_id = "Z3PAABBCFAKEC0"
# configuration
2017-09-18 07:50:55 +02:00
ssh_authorized_key = "ssh-rsa AAAAB3Nz..."
2018-03-26 05:41:52 +02:00
asset_dir = "/home/user/.secrets/clusters/tempest"
2017-09-18 07:50:55 +02:00
2018-03-26 05:41:52 +02:00
# optional
worker_count = 2
worker_type = "t2.medium"
2017-09-18 07:50:55 +02:00
}
```
2018-04-24 06:36:20 +02:00
Reference the [variables docs ](#variables ) or the [variables.tf ](https://github.com/poseidon/typhoon/blob/master/aws/fedora-atomic/kubernetes/variables.tf ) source.
2017-09-18 07:50:55 +02:00
## ssh-agent
Initial bootstrapping requires `bootkube.service` be started on one controller node. Terraform uses `ssh-agent` to automate this step. Add your SSH private key to `ssh-agent` .
```sh
ssh-add ~/.ssh/id_rsa
ssh-add -L
```
## Apply
Initialize the config directory if this is the first use with Terraform.
```sh
terraform init
```
Plan the resources to be created.
```sh
$ terraform plan
2018-04-24 06:36:20 +02:00
Plan: 106 to add, 0 to change, 0 to destroy.
2017-09-18 07:50:55 +02:00
```
Apply the changes to create the cluster.
```sh
$ terraform apply
...
2017-11-06 07:36:50 +01:00
module.aws-tempest.null_resource.bootkube-start: Still creating... (4m50s elapsed)
module.aws-tempest.null_resource.bootkube-start: Still creating... (5m0s elapsed)
2017-09-18 07:50:55 +02:00
module.aws-tempest.null_resource.bootkube-start: Creation complete after 11m8s (ID: 3961816482286168143)
2018-04-24 06:36:20 +02:00
Apply complete! Resources: 106 added, 0 changed, 0 destroyed.
2017-09-18 07:50:55 +02:00
```
2018-04-24 06:36:20 +02:00
In 5-10 minutes, the Kubernetes cluster will be ready.
2017-09-18 07:50:55 +02:00
## Verify
[Install kubectl ](https://coreos.com/kubernetes/docs/latest/configure-kubectl.html ) on your system. Use the generated `kubeconfig` credentials to access the Kubernetes cluster and list nodes.
```
2018-01-07 01:55:06 +01:00
$ export KUBECONFIG=/home/user/.secrets/clusters/tempest/auth/kubeconfig
2017-09-18 07:50:55 +02:00
$ kubectl get nodes
NAME STATUS AGE VERSION
2018-10-28 00:47:57 +02:00
ip-10-0-12-221 Ready 34m v1.12.2
ip-10-0-19-112 Ready 34m v1.12.2
ip-10-0-4-22 Ready 34m v1.12.2
2017-09-18 07:50:55 +02:00
```
List the pods.
```
$ kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-node-1m5bf 2/2 Running 0 34m
kube-system calico-node-7jmr1 2/2 Running 0 34m
kube-system calico-node-bknc8 2/2 Running 0 34m
2018-07-02 04:41:57 +02:00
kube-system coredns-1187388186-wx1lg 1/1 Running 0 34m
2017-09-18 07:50:55 +02:00
kube-system kube-apiserver-4mjbk 1/1 Running 0 34m
kube-system kube-controller-manager-3597210155-j2jbt 1/1 Running 1 34m
kube-system kube-controller-manager-3597210155-j7g7x 1/1 Running 0 34m
kube-system kube-proxy-14wxv 1/1 Running 0 34m
kube-system kube-proxy-9vxh2 1/1 Running 0 34m
kube-system kube-proxy-sbbsh 1/1 Running 0 34m
kube-system kube-scheduler-3359497473-5plhf 1/1 Running 0 34m
kube-system kube-scheduler-3359497473-r7zg7 1/1 Running 1 34m
kube-system pod-checkpointer-4kxtl 1/1 Running 0 34m
kube-system pod-checkpointer-4kxtl-ip-10-0-12-221 1/1 Running 0 33m
```
## Going Further
2018-10-07 19:57:16 +02:00
Learn about [maintenance ](/topics/maintenance/ ) and [addons ](/addons/overview/ ).
2017-09-18 07:50:55 +02:00
## Variables
2018-04-24 06:36:20 +02:00
Check the [variables.tf ](https://github.com/poseidon/typhoon/blob/master/aws/fedora-atomic/kubernetes/variables.tf ) source.
2017-09-18 07:50:55 +02:00
### Required
| Name | Description | Example |
|:-----|:------------|:--------|
| cluster_name | Unique cluster name (prepended to dns_zone) | "tempest" |
| dns_zone | AWS Route53 DNS zone | "aws.example.com" |
| dns_zone_id | AWS Route53 DNS zone id | "Z3PAABBCFAKEC0" |
2018-04-24 06:36:20 +02:00
| ssh_authorized_key | SSH public key for user 'fedora' | "ssh-rsa AAAAB3NZ..." |
2017-09-18 07:50:55 +02:00
| asset_dir | Path to a directory where generated assets should be placed (contains secrets) | "/home/user/.secrets/clusters/tempest" |
#### DNS Zone
2018-04-24 06:36:20 +02:00
Clusters create a DNS A record `${cluster_name}.${dns_zone}` to resolve a network load balancer backed by controller instances. This FQDN is used by workers and `kubectl` to access the apiserver(s). In this example, the cluster's apiserver would be accessible at `tempest.aws.example.com` .
2017-09-18 07:50:55 +02:00
2018-04-24 06:36:20 +02:00
You'll need a registered domain name or delegated subdomain on AWS Route53. You can set this up once and create many clusters with unique names.
2017-09-18 07:50:55 +02:00
```tf
resource "aws_route53_zone" "zone-for-clusters" {
name = "aws.example.com."
}
```
Reference the DNS zone id with `"${aws_route53_zone.zone-for-clusters.zone_id}"` .
!!! tip ""
2018-04-24 06:36:20 +02:00
If you have an existing domain name with a zone file elsewhere, just delegate a subdomain that can be managed on Route53 (e.g. aws.mydomain.com) and [update nameservers ](http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/SOA-NSrecords.html ).
2017-09-18 07:50:55 +02:00
### Optional
| Name | Description | Default | Example |
|:-----|:------------|:--------|:--------|
| controller_count | Number of controllers (i.e. masters) | 1 | 1 |
| worker_count | Number of workers | 1 | 3 |
2018-03-26 07:11:18 +02:00
| controller_type | EC2 instance type for controllers | "t2.small" | See below |
| worker_type | EC2 instance type for workers | "t2.small" | See below |
2017-09-18 07:50:55 +02:00
| disk_size | Size of the EBS volume in GB | "40" | "100" |
2018-03-29 09:24:07 +02:00
| disk_type | Type of the EBS volume | "gp2" | standard, gp2, io1 |
2018-10-15 16:59:35 +02:00
| disk_iops | IOPS of the EBS volume | "0" (i.e. auto) | "400" |
2018-04-29 22:19:00 +02:00
| worker_price | Spot price in USD for workers. Leave as default empty string for regular on-demand instances | "" | "0.10" |
2017-09-18 07:50:55 +02:00
| networking | Choice of networking provider | "calico" | "calico" or "flannel" |
| network_mtu | CNI interface MTU (calico only) | 1480 | 8981 |
2018-03-26 06:36:10 +02:00
| host_cidr | CIDR IPv4 range to assign to EC2 instances | "10.0.0.0/16" | "10.1.0.0/16" |
| pod_cidr | CIDR IPv4 range to assign to Kubernetes pods | "10.2.0.0/16" | "10.22.0.0/16" |
| service_cidr | CIDR IPv4 range to assign to Kubernetes services | "10.3.0.0/16" | "10.3.0.0/24" |
2018-07-02 04:41:57 +02:00
| cluster_domain_suffix | FQDN suffix for Kubernetes services answered by coredns. | "cluster.local" | "k8s.example.com" |
2017-09-18 07:50:55 +02:00
Check the list of valid [instance types ](https://aws.amazon.com/ec2/instance-types/ ).
2018-05-31 07:57:15 +02:00
!!! warning
Do not choose a `controller_type` smaller than `t2.small` . Smaller instances are not sufficient for running a controller.