在 terraform 中创建一个新集群后,我可以写一些东西来编辑 /.kube/config 文件吗?

can I write something to edit the /.kube/config file as soon as create a new cluster in terraform?

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
  config_path = local.kubectl_config_path
  config_context =  data.aws_eks_cluster.cluster.arn
}
##################################################################


data "aws_availability_zones" "available" {
}

locals {
  cluster_name = "Cluster-${random_string.suffix.result}"
  kubectl_config_path = "C:/Users/User/.kube/config"
}

我想访问集群 无需自己编辑配置文件中的信息。

想知道我是否只能使用 terraform 来做到这一点 或者还有其他方法吗?

谢谢

您无需提供

  config_path = local.kubectl_config_path
  config_context =  data.aws_eks_cluster.cluster.arn

当您提供 hostcluster_ca_certificatetoken 时。因此,无需写入本地 kubeconfig 文件即可访问集群,以便 terraform kubernetes 提供程序正常工作。

如果您想手动将当前本地 kubeconfig 文件替换为 运行 kubectl 命令,您可以通过 null-resource.local-exec` reference