Skip to content

Commit 6904a92

Browse files
authored
Add configuration for Typhoon based acceptance test environment (#807)
1 parent cb60600 commit 6904a92

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Typhoon Kubernetes clusters on AWS
2+
3+
This environment deploys a Kubernetes cluster using the Typhoon distribution. See here for details: https://github.com/poseidon/typhoon
4+
5+
You will need the standard AWS environment variables to be set, e.g.
6+
7+
- `AWS_ACCESS_KEY_ID`
8+
- `AWS_SECRET_ACCESS_KEY`
9+
10+
See [AWS Provider docs](https://www.terraform.io/docs/providers/aws/index.html#configuration-reference) for more details about these variables
11+
and alternatives, like `AWS_PROFILE`.
12+
13+
Additionally, a publicly accesible DNS domain registered as a Route53 managed zone is required.
14+
The name of the domain should be passed to terraform via the `base_domain` input variable.
15+
16+
Example:
17+
18+
```export TF_VAR_base_domain=k8s.myself.com```
19+
## Versions
20+
21+
You can set the desired version of Kubernetes by editing the `main.tf` configuration file and replacing the version in the source URL of the `typhoon-acc` module.
22+
23+
Example:
24+
```
25+
26+
module "typhoon-acc" {
27+
source = "git::https://github.com/poseidon/typhoon//aws/fedora-coreos/kubernetes?ref=v1.18.0" # set the desired Kubernetes version here
28+
...
29+
```
30+
## Worker node count and instance type
31+
32+
You can control the amount of worker nodes in the cluster as well as their machine type, using the following variables:
33+
34+
- `TF_VAR_controller_count`
35+
- `TF_VAR_controller_type`
36+
- `TF_VAR_workers_count`
37+
- `TF_VAR_workers_type`
38+
39+
Export values for them or pass them to the apply command line.
40+
41+
## Build the cluster
42+
43+
```
44+
terraform init
45+
terraform apply -var=cluster_name=typhoon
46+
```
47+
48+
## Exporting K8S variables
49+
To access the cluster you need to export the `KUBECONFIG` variable pointing to the `kubeconfig` file for the current cluster.
50+
```
51+
export KUBECONFIG="$(terraform output kubeconfig_path)"
52+
```
53+
54+
Now you can access the cluster via `kubectl` and you can run acceptance tests against it.
55+
56+
To run acceptance tests, your the following command in the root of the repository.
57+
```
58+
TESTARGS="-run '^TestAcc'" make testacc
59+
```
60+
61+
To run only a specific set of tests, you can replace `^TestAcc` with any regular expression to filter tests by name.
62+
For example, to run tests for Pod resources, you can do:
63+
```
64+
TESTARGS="-run '^TestAccKubernetesPod_'" make testacc
65+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
resource "tls_private_key" "typhoon-acc" {
2+
algorithm = "RSA"
3+
}
4+
5+
resource "local_file" "public_key_openssh" {
6+
content = tls_private_key.typhoon-acc.public_key_openssh
7+
filename = "${path.cwd}/${var.cluster_name}.pub"
8+
}
9+
10+
resource "local_file" "private_key_pem" {
11+
content = tls_private_key.typhoon-acc.private_key_pem
12+
filename = "${path.cwd}/${var.cluster_name}"
13+
}
14+
15+
resource "null_resource" "ssh-key" {
16+
provisioner "local-exec" {
17+
command = format("chmod 600 %v", local_file.private_key_pem.filename)
18+
working_dir = path.cwd
19+
}
20+
provisioner "local-exec" {
21+
command = format("ssh-add %v", local_file.private_key_pem.filename)
22+
working_dir = path.cwd
23+
}
24+
}
25+
26+
data "aws_route53_zone" "typhoon-acc" {
27+
name = var.base_domain
28+
}
29+
30+
module "typhoon-acc" {
31+
source = "git::https://github.com/poseidon/typhoon//aws/fedora-coreos/kubernetes?ref=v1.18.0" # set the desired Kubernetes version here
32+
33+
cluster_name = var.cluster_name
34+
dns_zone = var.base_domain
35+
dns_zone_id = data.aws_route53_zone.typhoon-acc.zone_id
36+
37+
# node configuration
38+
ssh_authorized_key = tls_private_key.typhoon-acc.public_key_openssh
39+
40+
worker_count = var.worker_count
41+
controller_count = var.controller_count
42+
worker_type = var.controller_type
43+
controller_type = var.worker_type
44+
}
45+
46+
resource "local_file" "typhoon-acc" {
47+
content = module.typhoon-acc.kubeconfig-admin
48+
filename = "kubeconfig"
49+
}
50+
51+
output "kubeconfig_path" {
52+
value = "${path.cwd}/${local_file.typhoon-acc.filename}"
53+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
variable "base_domain" {
2+
type = string
3+
}
4+
5+
variable "cluster_name" {
6+
type = string
7+
}
8+
9+
variable "controller_count" {
10+
default = 1
11+
}
12+
13+
variable "worker_count" {
14+
default = 4
15+
}
16+
17+
variable "controller_type" {
18+
default = "m5a.xlarge"
19+
}
20+
21+
variable "worker_type" {
22+
default = "m5a.large"
23+
}

0 commit comments

Comments
 (0)