使用"terraform destroy"删除Kubernetes集群后,我无法再次创建它。
"terraform apply"返回以下错误消息:
Error: Kubernetes cluster unreachable: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
这是terraform的配置:
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"
}
}
附注:似乎terraform kubernetes提供程序0.14.7存在问题。
在此版本中,我无法使用“load_config_file”=false,因此不得不将其注释掉,这似乎是问题的原因。
另外可能也是过时的cluster_ca_certificate的问题,terraform试图使用它:删除此证书可能就足够了,尽管我不确定它存储在哪里。