terraform-provider-kubernetes/_examples/eks
2023-10-18 15:47:12 +02:00
..
eks-cluster Example module for configuring EKS for OIDC authentication (#2287) 2023-09-14 23:40:04 +02:00
eks-oidc Add ClusterRoleBinding and small corrections to GKE OIDC config (#2323) 2023-10-18 15:47:12 +02:00
kubernetes-config [COMPLIANCE] Add Copyright and License Headers (#1982) 2023-03-03 10:15:24 +01:00
output.tf [COMPLIANCE] Add Copyright and License Headers (#1982) 2023-03-03 10:15:24 +01:00
README.md Update EKS example to use two applies (#1260) 2021-05-13 16:52:52 -07:00
variables.tf [COMPLIANCE] Add Copyright and License Headers (#1982) 2023-03-03 10:15:24 +01:00

EKS (Amazon Elastic Kubernetes Service)

This example demonstrates the most reliable way to use the Kubernetes provider together with the AWS provider to create an EKS cluster. By keeping the two providers' resources in separate Terraform states (or separate workspaces using Terraform Cloud), we can limit the scope of changes to either the EKS cluster or the Kubernetes resources. This will prevent dependency issues between the AWS and Kubernetes providers, since terraform's provider configurations must be known before a configuration can be applied.

You will need the following environment variables to be set:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY

See AWS Provider docs for more details about these variables and alternatives, like AWS_PROFILE.

Create EKS cluster

Choose a name for the cluster, or use the terraform config in the current directory to create a random name.

terraform init
terraform apply --auto-approve
export CLUSTERNAME=$(terraform output -raw cluster_name)

Change into the eks-cluster directory and create the EKS cluster infrastructure.

cd eks-cluster
terraform init
terraform apply -var=cluster_name=$CLUSTERNAME
cd -

Optionally, the Kubernetes version can be specified at apply time:

terraform apply -var=cluster_name=$CLUSTERNAME -var=kubernetes_version=1.18

See https://docs.aws.amazon.com/eks/latest/userguide/platform-versions.html for currently available versions.

Create Kubernetes resources

Change into the kubernetes-config directory to apply Kubernetes resources to the new cluster.

cd kubernetes-config
terraform init
terraform apply -var=cluster_name=$CLUSTERNAME

Deleting the cluster

First, delete the Kubernetes resources as shown below. This will give Ingress and Service related Load Balancers a chance to delete before the other AWS resources are removed.

cd kubernetes-config
terraform destroy -var=cluster_name=$CLUSTERNAME
cd -

Then delete the EKS related resources:

cd eks-cluster
terraform destroy -var=cluster_name=$CLUSTERNAME
cd -