-
Notifications
You must be signed in to change notification settings - Fork 986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace EKS test-infra with example #1192
Merged
+189
−53,631
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.16 | ||
1.16.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,57 @@ | ||
# Amazon EKS Clusters | ||
# EKS test infrastructure | ||
|
||
You will need the standard AWS environment variables to be set, e.g. | ||
This directory contains files used for testing the Kubernetes provider in our internal CI system. See the [examples](https://github.com/hashicorp/terraform-provider-kubernetes/tree/master/_examples/eks) directory instead, if you're looking for example code. | ||
|
||
To run this test infrastructure, you will need the following environment variables to be set: | ||
|
||
- `AWS_ACCESS_KEY_ID` | ||
- `AWS_SECRET_ACCESS_KEY` | ||
|
||
See [AWS Provider docs](https://www.terraform.io/docs/providers/aws/index.html#configuration-reference) for more details about these variables | ||
and alternatives, like `AWS_PROFILE`. | ||
See [AWS Provider docs](https://www.terraform.io/docs/providers/aws/index.html#configuration-reference) for more details about these variables and alternatives, like `AWS_PROFILE`. | ||
|
||
## Versions | ||
Ensure that `KUBE_CONFIG_PATH` and `KUBE_CONFIG_PATHS` environment variables are NOT set, as they will interfere with the cluster build. | ||
|
||
You can set the desired version of Kubernetes via the `kubernetes_version` TF variable. | ||
``` | ||
unset KUBE_CONFIG_PATH | ||
unset KUBE_CONFIG_PATHS | ||
``` | ||
|
||
See https://docs.aws.amazon.com/eks/latest/userguide/platform-versions.html for currently available versions. | ||
To install the EKS cluster using default values, run terraform init and apply from the directory containing this README. | ||
|
||
You can set the desired version of Kubernetes via the `kubernetes_version` TF variable, like this: | ||
``` | ||
export TF_VAR_kubernetes_version="1.11" | ||
terraform init | ||
terraform apply | ||
``` | ||
Alternatively you can pass it to the `apply` command line, like below. | ||
|
||
## Worker node count and instance type | ||
## Kubeconfig for manual CLI access | ||
|
||
You can control the amount of worker nodes in the cluster as well as their machine type, using the following variables: | ||
The token contained in the kubeconfig expires in 15 minutes. The token can be refreshed by running `terraform apply` again. Export the KUBECONFIG to manually access the cluster: | ||
|
||
- `TF_VAR_workers_count` | ||
- `TF_VAR_workers_type` | ||
``` | ||
terraform apply | ||
export KUBECONFIG=$(terraform output -raw kubeconfig_path) | ||
kubectl get pods -n test | ||
``` | ||
|
||
Export values for them or pass them to the apply command line. | ||
## Optional variables | ||
|
||
## Build the cluster | ||
The Kubernetes version can be specified at apply time: | ||
|
||
``` | ||
terraform init | ||
terraform apply -var=kubernetes_version=1.11 | ||
terraform apply -var=kubernetes_version=1.18 | ||
``` | ||
|
||
## Exporting K8S variables | ||
To access the cluster you need to export the `KUBECONFIG` variable pointing to the `kubeconfig` file for the current cluster. | ||
``` | ||
export KUBECONFIG="$(terraform output kubeconfig_path)" | ||
``` | ||
See https://docs.aws.amazon.com/eks/latest/userguide/platform-versions.html for currently available versions. | ||
|
||
Now you can access the cluster via `kubectl` and you can run acceptance tests against it. | ||
|
||
To run acceptance tests, your the following command in the root of the repository. | ||
``` | ||
TESTARGS="-run '^TestAcc'" make testacc | ||
``` | ||
### Worker node count and instance type | ||
|
||
The number of worker nodes, and the instance type, can be specified at apply time: | ||
|
||
To run only a specific set of tests, you can replace `^TestAcc` with any regular expression to filter tests by name. | ||
For example, to run tests for Pod resources, you can do: | ||
``` | ||
TESTARGS="-run '^TestAccKubernetesPod_'" make testacc | ||
terraform apply -var=workers_count=4 -var=workers_type=m4.xlarge | ||
``` | ||
|
||
## Additional configuration of EKS | ||
|
||
To view all available configuration options for the EKS module used in this example, see [terraform-aws-modules/eks docs](https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
resource "kubernetes_config_map" "name" { | ||
metadata { | ||
name = "aws-auth" | ||
namespace = "kube-system" | ||
} | ||
|
||
data = { | ||
mapRoles = join( | ||
"\n", | ||
formatlist(local.mapped_role_format, var.k8s_node_role_arn), | ||
) | ||
} | ||
} | ||
|
||
# Optional: this kubeconfig file is only used for manual CLI access to the cluster. | ||
resource "null_resource" "generate-kubeconfig" { | ||
provisioner "local-exec" { | ||
command = "aws eks update-kubeconfig --name ${var.cluster_name} --kubeconfig ${path.root}/kubeconfig" | ||
} | ||
} | ||
|
||
resource "kubernetes_namespace" "test" { | ||
metadata { | ||
name = "test" | ||
} | ||
} | ||
|
||
resource "kubernetes_deployment" "test" { | ||
metadata { | ||
name = "test" | ||
namespace= kubernetes_namespace.test.metadata.0.name | ||
} | ||
spec { | ||
replicas = 2 | ||
selector { | ||
match_labels = { | ||
app = "test" | ||
} | ||
} | ||
template { | ||
metadata { | ||
labels = { | ||
app = "test" | ||
} | ||
} | ||
spec { | ||
container { | ||
image = "nginx:1.19.4" | ||
name = "nginx" | ||
|
||
resources { | ||
limits = { | ||
memory = "512M" | ||
cpu = "1" | ||
} | ||
requests = { | ||
memory = "256M" | ||
cpu = "50m" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource helm_release nginx_ingress { | ||
name = "nginx-ingress-controller" | ||
|
||
repository = "https://charts.bitnami.com/bitnami" | ||
chart = "nginx-ingress-controller" | ||
|
||
set { | ||
name = "service.type" | ||
value = "ClusterIP" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
variable "k8s_node_role_arn" { | ||
type = string | ||
} | ||
|
||
variable "cluster_name" { | ||
type = string | ||
} | ||
|
||
locals { | ||
mapped_role_format = <<MAPPEDROLE | ||
- rolearn: %s | ||
username: system:node:{{EC2PrivateDNSName}} | ||
groups: | ||
- system:bootstrappers | ||
- system:nodes | ||
MAPPEDROLE | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GP2 volumes are generally more expensive.
Is there a technical need for nodes to run on GP2 volumes? We're likely not putting much workload on the nodes during our tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gp2 was the default in the EKS module, but they recently updated it to gp3. I put it back to the old default because gp3 isn't available in all regions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the commit where it was added. terraform-aws-modules/terraform-aws-eks@76537d1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, if that's the case then disregard my comment. I must have based it on old information and likely GPx volumes are now the only choice. Sorry for the confusion :)