首页 > 解决方案 > 如何在 Google Kubernetes Engine 集群中启用客户端证书

问题描述

我正在尝试从 GKE 集群中检索集群客户端证书以使用 Kubernetes 服务器 API 进行身份验证。我正在使用 GKE API 检索集群信息,但响应中的客户端证书客户端密钥为空。经过进一步调查,我发现在 Google Kubernetes Engine 的最新版本中默认禁用客户端证书。现在,当我尝试从集群设置启用它时,它说

客户端证书是不可变的。

我的问题是如何为 GKE 集群启用客户端证书。

标签: javakubernetesgoogle-cloud-platformgoogle-kubernetes-engine

解决方案


根据gitlab从 1.12 开始,新集群不会颁发客户端证书。--[no-]issue-client-certificate您可以使用该标志手动启用(或禁用)客户端证书的颁发。默认情况下,集群将禁用基本身份验证和客户端证书颁发。

根据@Dawid,您可以使用以下命令创建具有客户端证书> 启用的集群,并且在该集群上无法进行修改。

gcloud container clusters create YOUR-CLUSTER --machine-type=custom-2-12288 --issue-client-certificate --zone us-central1-a

如果要在现有集群上启用客户端证书,作为一种解决方法,您可以使用命令行和 --issue-client-certificate 在命令末尾克隆 (DUPLICATE) 集群,如下所示:

gcloud beta container --project "xxxxxxxx" clusters create "high-mem-pool-clone-1" --zone "us-central1-f" --username "admin" --cluster-version "1.16.15-gke.6000" --release-channel "None" --machine-type "custom-2-12288" --image-type "COS" --disk-type "pd-standard" --disk-size "100" --metadata disable-legacy-endpoints=true --scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" --num-nodes "3" --enable-stackdriver-kubernetes --no-enable-ip-alias --network "projects/xxxxxxx/global/networks/default" --subnetwork "projects/xxxxxxxx/regions/us-central1/subnetworks/default" --no-enable-master-authorized-networks --addons HorizontalPodAutoscaling,HttpLoadBalancing --enable-autoupgrade --enable-autorepair --max-surge-upgrade 1 --max-unavailable-upgrade 0 --issue-client-certificate

推荐阅读