简体   繁体   English

如何使用 terraform 创建具有公共和私有 su.net 的 EKS 集群?

[英]How to create an EKS cluster with public and private subnets using terraform?

I'm usin terraform to set up an EKS cluster i need to make sure that my worker nodes will be placed on private su.nets and that my public su.nets will be used for my load balancers but i don't actually know how to inject public and private su.nets in my cluster because i'm only using private ones.我正在使用 terraform 来设置 EKS 集群,我需要确保我的工作节点将放置在私有 su.net 上,并且我的公共 su.net 将用于我的负载均衡器,但我实际上不知道如何在我的集群中注入公共和私有 su.net,因为我只使用私有的。

resource "aws_eks_cluster" "master_node" {
    name     = "my-cluster"
    role_arn = aws_iam_role.master_iam_role.arn
    version  = "1.14"
    vpc_config {
        security_group_ids      = [aws_security_group.master_security_group.id]
        subnet_ids              = var.private_subnet_eks_ids
    }

    depends_on = [
        aws_iam_role_policy_attachment.main-cluster-AmazonEKSClusterPolicy,
        aws_iam_role_policy_attachment.main-cluster-AmazonEKSServicePolicy,
    ]
}

resource "aws_autoscaling_group" "eks_autoscaling_group" {
    desired_capacity     = var.desired_capacity
    launch_configuration = aws_launch_configuration.eks_launch_config.id
    max_size             = var.max_size
    min_size             = var.min_size
    name                 = "my-autoscaling-group"
    vpc_zone_identifier  = var.private_subnet_eks_ids
    depends_on = [
        aws_efs_mount_target.efs_mount_target
    ]
}

Give only private su.nets to your eks cluster but, before that, make sure you've tagged the public su.nets so:仅将私有 su.net 提供给您的 eks 集群,但在此之前,请确保您已将公共 su.net 标记为:

Key: kubernetes.io/role/elb
value: 1

as described here: https://aws.amazon.com/premiumsupport/knowledge-center/eks-vpc-su.net-discovery/如此处所述: https://aws.amazon.com/premiumsupport/knowledge-center/eks-vpc-su.net-discovery/

EKS will discover the public su.nets where to place the load balancer querying by tags. EKS 将通过标签查询发现公共 su.nets 在哪里放置负载均衡器。

I make use to create both public and private su.nets on the VPC using the vpc module .我利用vpc 模块在 VPC 上创建公共和私有 su.net。 Then I create the EKS cluster using the eks module and refere to the vpc-data.然后我使用 eks模块创建 EKS 集群并引用 vpc-data。

Example例子

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"

  name = "my-vpc"
  cidr = "10.0.0.0/16"

  azs             = ["eu-north-1a", "eu-north-1b", "eu-north-1c"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]

  enable_nat_gateway = true
  enable_vpn_gateway = true
}

And then EKS cluster where I refer to the VPC su.nets using module.vpc.private_su.nets and module.vpc.vpc_id :然后是 EKS 集群,我在其中使用module.vpc.private_su.netsmodule.vpc.vpc_id引用 VPC su.nets:

module "eks-cluster" {
  source               = "terraform-aws-modules/eks/aws"
  cluster_name         = "my-eks-cluster"
  cluster_version      = "1.17"
  subnets              = module.vpc.private_subnets
  vpc_id               = module.vpc.vpc_id

  worker_groups = [
    {
      instance_type = "t3.small"
      asg_max_size  = 2
    } 
  ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在没有 NAT 网关的情况下使用 CLI 创建 EKS 私有集群? - Create EKS private cluster using CLI without NAT gateway? 使用 Terraform 和 Helm 在 EKS 集群上安装 Istio - Install Istio on EKS cluster using Terraform and Helm 我想使用 terraform 在 GCP 中创建公共和私有 Su.net - I want to create Public and Private Subnet in GCP using terraform 如何使用 Fargate 创建 AWS Kube.netes 集群 (EKS)? - How to create a AWS Kubernetes cluster (EKS) using Fargate? 创建集群时 EKS Anywhere 超时 - EKS Anywhere timeout on create cluster 如何将弹性 IP 重用于一组专用于 Fargate 任务的私有和公共 su.net - How to reuse Elastic IPs for a set of private and public subnets dedicated to Fargate tasks Terraform中EKS集群的两个节点组如何使用同一个IAM角色? - How to use the same IAM role for two node groups in an EKS cluster in Terraform? 如何使用 Terraform 创建私有 S3 存储桶? - How to create private S3 bucket with Terraform? 即使禁用端点公共访问,如何使用 kubeconfig 访问 EKS 集群 - How to access EKS cluster with kubeconfig even when disabling endpoint public access 为什么 AWS 推荐带有 nat 网关的公共和私有 su.net? - Why do AWS recommend public and private subnets with a nat gateway?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM