我想创建一个 GKE 集群,然后将其作为现有集群导入 Rancher。第二步,我需要将一些 Kubernetes 资源安装到集群中。
集群创建工作正常。我设置
master_auth {
client_certificate_config {
issue_client_certificate = true
}
}
然后访问
provider "kubernetes" {
host = var.kubernetes_endpoint
client_certificate = var.kubernetes_client_certificate
client_key = var.kubernetes_client_key
cluster_ca_certificate = var.kubernetes_cluster_ca_certificate
}
但是,尝试在集群中创建 Kubernetes 资源时出现错误
Error: clusterroles.rbac.authorization.k8s.io is forbidden: User "client" cannot create resource "clusterroles" in API group "rbac.authorization.k8s.io" at the cluster scope
on modules/install-rancher/resources.tf line 1, in resource "kubernetes_cluster_role" "proxy-clusterrole-kubeapiserver":
1: resource "kubernetes_cluster_role" "proxy-clusterrole-kubeapiserver" {
有没有办法通过 Terraform 获取具有管理员权限的客户端证书?
答案1
这就是解决我的问题并链接不同的 Terraform 提供程序/部署的方法。
data "google_client_config" "client_config" {
provider = google-beta
}
provider "kubernetes" {
load_config_file = false
host = var.endpoint_from_created_cluster
token = data.google_client_config.client_config.access_token
cluster_ca_certificate = var.ca_certificate_from_created_cluster
}