首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检索EKS kubeconfig?

如何检索EKS kubeconfig?
EN

Stack Overflow用户
提问于 2020-11-13 12:34:04
回答 1查看 868关注 0票数 0

我将aws_eks_clusteraws_eks_node_group定义为:

代码语言:javascript
复制
resource "aws_eks_cluster" "example" {
  count = var.create_eks_cluster ? 1 : 0
  name     = local.cluster_name
  role_arn = aws_iam_role.example[count.index].arn

  vpc_config {
    subnet_ids = [
      aws_subnet.main2.id, 
      aws_subnet.main3.id
    ]
    security_group_ids = [
      module.network.security_group_allow_all_from_client_ip,
      module.network.security_group_main_id
    ]
    endpoint_private_access = true
    endpoint_public_access = false
  }

  # Ensure that IAM Role permissions are created before and deleted after EKS Cluster handling.
  # Otherwise, EKS will not be able to properly delete EKS managed EC2 infrastructure such as Security Groups.
  depends_on = [
    aws_iam_role_policy_attachment.example-AmazonEKSClusterPolicy,
    aws_iam_role_policy_attachment.example-AmazonEKSVPCResourceController,
  ]
}


resource "aws_eks_node_group" "example" {
  count = var.create_eks_cluster ? 1 : 0
  cluster_name    = aws_eks_cluster.example[count.index].name
  node_group_name = random_uuid.deployment_uuid.result
  node_role_arn   = aws_iam_role.eks-node-group-example[count.index].arn
  subnet_ids      = [
    aws_subnet.main2.id, 
    aws_subnet.main3.id
    ]

  scaling_config {
    desired_size = 1
    max_size     = 5
    min_size     = 1
  }

  # Ensure that IAM Role permissions are created before and deleted after EKS Node Group handling.
  # Otherwise, EKS will not be able to properly delete EC2 Instances and Elastic Network Interfaces.
  depends_on = [
    aws_iam_role_policy_attachment.example-AmazonEKSWorkerNodePolicy,
    aws_iam_role_policy_attachment.example-AmazonEKS_CNI_Policy,
    aws_iam_role_policy_attachment.example-AmazonEC2ContainerRegistryReadOnly,
  ]
}

如何检索KubeConfig?

我已经看到kubeconfig可以作为ek模块上的输出。

我是否需要用aws_eks_clusteraws_eks_node_group模块取代

EN

回答 1

Stack Overflow用户

发布于 2020-11-27 18:09:14

EKS模块构成基于模板的kubeconfig。

您可以将该模板与您的terraform代码放在一起。

您需要为模板函数调用中的所有变量提供默认值,并引用您自己的EKS资源名称。也可以删除所有的coalescelist函数。

例如:

代码语言:javascript
复制
locals {
  kubeconfig = templatefile("templates/kubeconfig.tpl", {
    kubeconfig_name                   = local.kubeconfig_name
    endpoint                          = aws_eks_cluster.example.endpoint
    cluster_auth_base64               = aws_eks_cluster.example.certificate_authority[0].data
    aws_authenticator_command         = "aws-iam-authenticator"
    aws_authenticator_command_args    = ["token", "-i", aws_eks_cluster.example.name]
    aws_authenticator_additional_args = []
    aws_authenticator_env_variables   = {}
  })
}

output "kubeconfig" { value = local.kubeconfig }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64820975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档