terraform-aws-eks

Terraform 模块,用于在 AWS 上创建 Elastic Kubernetes(EKS)集群和关联的工作器实例。「 A Terraform module to create an Elastic Kubernetes (EKS) cluster and associated worker instances on AWS.

Github stars Tracking Chart

terraform-AWS-EKS

用于在 AWS EKS上 创建托管 Kubernetes 集群的 terraform 模块。 可通过 Terraform registry 获得。 受 此文档 及其 源代码 的启发并改编而成。 阅读 EKS 上的 AWS 文档以连接到 k8s 仪表板

假设

  • 您希望为群集创建 EKS 群集和自动缩放工作组。
  • 您希望这些资源存在于允许通信和协调的安全组中。 这些可以是用户在模块内提供或创建的。
  • 您已经创建了一个虚拟私有云(VPC)和子网,您打算放置 EKS 资源。
  • 如果 manage_aws_auth = true,则需要同时安装 kubectl(>= 1.10)和 aws-iam-authenticator,并安装在您的 shell 路径上。

用法示例

examples/basic 目录中包含利用其他社区模块的完整示例。 以下是通过 Terraform registry 使用它的要点:

module "my-cluster" {
  source       = "terraform-aws-modules/eks/aws"
  cluster_name = "my-cluster"
  subnets      = ["subnet-abcde012", "subnet-bcde012a", "subnet-fghi345a"]
  vpc_id       = "vpc-1234556abcdef"
  worker_groups = [
    {
      instance_type = "m4.large"
      asg_max_size  = 5
      tags = [{
        key                 = "foo"
        value               = "bar"
        propagate_at_launch = true
      }]
    }
  ]
  tags = {
    environment = "test"
  }
}

其他文档

发布时间表

通常,维护人员会尝试每两周发布一次模块,以跟上 PR 的增加。 如果添加了特别紧迫的更改或维护人员提出空闲时间(哈!),有时可能会更频繁地发布。

作者

Brandon O'Connor 创建和维护 -- brandon@atscale.run. 多谢 这里列出的贡献者!

许可

MIT 许可。 有关详细信息,请参阅LICENSE。

Overview

Name With Ownerterraform-aws-modules/terraform-aws-eks
Primary LanguageHCL
Program languageHCL (Language Count: 2)
PlatformAmazon Elastic Kubernetes Service, Kubernetes
License:Apache License 2.0
Release Count221
Last Release Namev20.8.5 (Posted on )
First Release Namev0.1.0 (Posted on )
Created At2018-06-07 00:43:18
Pushed At2024-05-07 18:54:26
Last Commit At2024-04-08 22:46:19
Stargazers Count4.2k
Watchers Count89
Fork Count3.9k
Commits Count1k
Has Issues Enabled
Issues Count1878
Issue Open Count22
Pull Requests Count738
Pull Requests Open Count2
Pull Requests Close Count405
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

terraform-aws-eks

Lint Status
LICENSE

A terraform module to create a managed Kubernetes cluster on AWS EKS. Available
through the Terraform registry.
Inspired by and adapted from this doc
and its source code.
Read the AWS docs on EKS to get connected to the k8s dashboard.

Assumptions

  • You want to create an EKS cluster and an autoscaling group of workers for the cluster.
  • You want these resources to exist within security groups that allow communication and coordination. These can be user provided or created within the module.
  • You've created a Virtual Private Cloud (VPC) and subnets where you intend to put the EKS resources. The VPC satisfies EKS requirements.
  • If manage_aws_auth = true, it's required that both kubectl (>=1.10) and aws-iam-authenticator are installed and on your shell's PATH.

Usage example

A full example leveraging other community modules is contained in the examples/basic directory.

data "aws_eks_cluster" "cluster" {
  name = module.my-cluster.cluster_id
}

data "aws_eks_cluster_auth" "cluster" {
  name = module.my-cluster.cluster_id
}

provider "kubernetes" {
  host                   = data.aws_eks_cluster.cluster.endpoint
  cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
  token                  = data.aws_eks_cluster_auth.cluster.token
  load_config_file       = false
  version                = "~> 1.9"
}

module "my-cluster" {
  source          = "terraform-aws-modules/eks/aws"
  cluster_name    = "my-cluster"
  cluster_version = "1.14"
  subnets         = ["subnet-abcde012", "subnet-bcde012a", "subnet-fghi345a"]
  vpc_id          = "vpc-1234556abcdef"

  worker_groups = [
    {
      instance_type = "m4.large"
      asg_max_size  = 5
    }
  ]
}

Conditional creation

Sometimes you need to have a way to create EKS resources conditionally but Terraform does not allow to use count inside module block, so the solution is to specify argument create_eks.

Using this feature and having manage_aws_auth=true (the default) requires to set up the kubernetes provider in a way that allows the data sources to not exist.

data "aws_eks_cluster" "cluster" {
  count = var.create_eks ? 1 : 0
  name  = module.eks.cluster_id
}

data "aws_eks_cluster_auth" "cluster" {
  count = var.create_eks ? 1 : 0
  name  = module.eks.cluster_id
}

# In case of not creating the cluster, this will be an incompletely configured, unused provider, which poses no problem.
provider "kubernetes" {
  host                   = element(concat(data.aws_eks_cluster.cluster[*].endpoint, list("")), 0)
  cluster_ca_certificate = base64decode(element(concat(data.aws_eks_cluster.cluster[*].certificate_authority.0.data, list("")), 0))
  token                  = element(concat(data.aws_eks_cluster_auth.cluster[*].token, list("")), 0)
  load_config_file       = false
  version                = "~> 1.10"
}

# This cluster will not be created
module "eks" {
  source = "terraform-aws-modules/eks/aws"

  create_eks = false
  # ... omitted
}

Other documentation

Testing

This module has been packaged with awspec tests through kitchen and kitchen-terraform. To run them:

  1. Install rvm and the ruby version specified in the Gemfile.

  2. Install bundler and the gems from our Gemfile:

    gem install bundler && bundle install
    
  3. Ensure your AWS environment is configured (i.e. credentials and region) for test.

  4. Test using bundle exec kitchen test from the root of the repo.

For now, connectivity to the kubernetes cluster is not tested but will be in the
future. Once the test fixture has converged, you can query the test cluster from
that terminal session with

kubectl get nodes --watch --kubeconfig kubeconfig

(using default settings config_output_path = "./" & write_kubeconfig = true)

Doc generation

Code formatting and documentation for variables and outputs is generated using pre-commit-terraform hooks which uses terraform-docs.

Follow these instructions to install pre-commit locally.

And install terraform-docs with go get github.com/segmentio/terraform-docs or brew install terraform-docs.

Contributing

Report issues/questions/feature requests on in the issues section.

Full contributing guidelines are covered here.

Change log

The changelog captures all important release notes.

Authors

Created by Brandon O'Connor - brandon@atscale.run.
Maintained by Max Williams and Thierno IB. BARRY.
Many thanks to the contributors listed here!

License

MIT Licensed. See LICENSE for full details.

To the top