gpt4 book ai didi

kubernetes - Terraform:错误:Kubernetes 集群无法访问:配置无效

转载 作者:行者123 更新时间:2023-12-04 12:17:59 24 4
gpt4 key购买 nike

使用“terraform destroy”删除 kubernetes 集群后,我无法再创建它了。
“terraform apply”返回以下错误消息:

Error: Kubernetes cluster unreachable: invalid configuration: noconfiguration has been provided, try setting KUBERNETES_MASTERenvironment variable


这是地形配置:
terraform {
backend "s3" {
bucket = "skyglass-msur"
key = "terraform/backend"
region = "us-east-1"
}
}

locals {
env_name = "staging"
aws_region = "us-east-1"
k8s_cluster_name = "ms-cluster"
}

variable "mysql_password" {
type = string
description = "Expected to be retrieved from environment variable TF_VAR_mysql_password"
}

provider "aws" {
region = local.aws_region
}

data "aws_eks_cluster" "msur" {
name = module.aws-kubernetes-cluster.eks_cluster_id
}

module "aws-network" {
source = "github.com/skyglass-microservices/module-aws-network"

env_name = local.env_name
vpc_name = "msur-VPC"
cluster_name = local.k8s_cluster_name
aws_region = local.aws_region
main_vpc_cidr = "10.10.0.0/16"
public_subnet_a_cidr = "10.10.0.0/18"
public_subnet_b_cidr = "10.10.64.0/18"
private_subnet_a_cidr = "10.10.128.0/18"
private_subnet_b_cidr = "10.10.192.0/18"
}

module "aws-kubernetes-cluster" {
source = "github.com/skyglass-microservices/module-aws-kubernetes"

ms_namespace = "microservices"
env_name = local.env_name
aws_region = local.aws_region
cluster_name = local.k8s_cluster_name
vpc_id = module.aws-network.vpc_id
cluster_subnet_ids = module.aws-network.subnet_ids

nodegroup_subnet_ids = module.aws-network.private_subnet_ids
nodegroup_disk_size = "20"
nodegroup_instance_types = ["t3.medium"]
nodegroup_desired_size = 1
nodegroup_min_size = 1
nodegroup_max_size = 5
}

# Create namespace
# Use kubernetes provider to work with the kubernetes cluster API
provider "kubernetes" {
# load_config_file = false
cluster_ca_certificate = base64decode(data.aws_eks_cluster.msur.certificate_authority.0.data)
host = data.aws_eks_cluster.msur.endpoint
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
command = "aws-iam-authenticator"
args = ["token", "-i", "${data.aws_eks_cluster.msur.name}"]
}
}

# Create a namespace for microservice pods
resource "kubernetes_namespace" "ms-namespace" {
metadata {
name = "microservices"
}
}
附言0.14.7 的 terraform kubernetes provider 似乎存在问题
我在这个版本中不能使用“load_config_file”=false,所以我不得不评论它,这似乎是这个问题的原因。
P.P.S.也可能是 terraform 尝试使用的过时 cluster_ca_certificate 的问题:删除此证书可能就足够了,尽管我不确定它的存储位置。

最佳答案

在做一些激进的事情之前,比如直接操纵状态,尝试设置 KUBE_CONFIG_PATH 变量:

export KUBE_CONFIG_PATH=/path/to/.kube/config
在此之后重新运行 planapply命令。
这为我解决了这个问题。

关于kubernetes - Terraform:错误:Kubernetes 集群无法访问:配置无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66427129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com