1

我有一个 terraform 配置,它将创建一个 GKE 集群、节点池,然后调用 kubernetes 来设置我的应用程序。当我在尚未创建集群的新项目上运行此配置时,kubernetes 提供程序会抛出以下错误

Error: Kubernetes cluster unreachable: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable


Error: Get "http://localhost/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/cluster-admin-binding": dial tcp [::1]:80: connect: connection refused


Error: Get "http://localhost/api/v1/namespaces/rabbitmq": dial tcp [::1]:80: connect: connection refused

如果我注释掉所有 kubernetes 部分,运行 terraform apply 来创建集群,然后取消注释 kubernetes 部分并尝试它工作正常并创建所有 kubernetes 资源。

我检查了 Kubernetes 提供者的文档,它说集群应该已经存在。

k8s 入门

There are at least 2 steps involved in scheduling your first container on a Kubernetes cluster. You need the Kubernetes cluster with all its components running somewhere and then schedule the Kubernetes resources, like Pods, Replication Controllers, Services etc.

如何告诉 terraform 在规划 kubernetes 之前等待集群创建?

我的配置如下 main.tf

.
.
.

module "gke" {
  source = "./modules/gke"

  name                     = var.gke_cluster_name
  project_id               = data.google_project.project.project_id
  gke_location             = var.gke_zone
  .
  .
  .
}

data "google_client_config" "provider" {}

provider "kubernetes" {
  version                = "~> 1.13.3"
  alias                  = "my-kuber"
  host                   = "https://${module.gke.endpoint}"
  token                  = data.google_client_config.provider.access_token
  cluster_ca_certificate = module.gke.cluster_ca_certificate
  load_config_file       = false
}

resource "kubernetes_namespace" "ns" {
  provider = kubernetes.my-kuber
  depends_on = [module.gke]

  metadata {
    name = var.namespace
  }
}
4

0 回答 0