如何在使用gcp授权插件的kubectl中移除警告?

35
当我运行任何 kubectl 命令时,会出现以下警告:
W0517 14:33:54.147340   46871 gcp.go:120] WARNING: the gcp auth plugin is deprecated in v1.22+, unavailable in v1.25+; use gcloud instead.
To learn more, consult https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke

我已经多次按照这个链接中的指示进行操作,但是警告信息仍然会出现,导致kubectl输出难以阅读。

操作系统:

cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"

kubectl版本:

Client Version: v1.24.0
Kustomize Version: v4.5.4

gke-gcloud-auth-plugin:

Kubernetes v1.23.0-alpha+66064c62c6c23110c7a93faca5fba668018df732

gcloud版本:

Google Cloud SDK 385.0.0
alpha 2022.05.06
beta 2022.05.06
bq 2.0.74
bundled-python3-unix 3.9.12
core 2022.05.06
gsutil 5.10

我使用以下方式进行“登录”:

gcloud init

接着:

gcloud container clusters get-credentials cluster_name --region my-region

最后:

myyser@mymachine:/$ k get pods -n madeupns
W0517 14:50:10.570103   50345 gcp.go:120] WARNING: the gcp auth plugin is deprecated in v1.22+, unavailable in v1.25+; use gcloud instead.
To learn more, consult https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke
No resources found in madeupns namespace.

如何解决警告或修复问题?

删除我的.kube/config并重新运行get-credentials没有起作用。


5
在再次运行 gcloud container clusters get-credentials 前,你是否设置/导出了 USE_GKE_GCLOUD_AUTH_PLUGIN=True?你应该能够在 ${HOME}/.kube/configusers 部分中检测到更改。我还没有尝试确认我的配置是否已更新,但明天创建集群时会查看。可能 kubectl 警告是静态的,并且本身不会检查您是否已更新插件。 - DazWilkin
你是对的 @DazWilkin,我的bashrc中有一个错别字,修复后警告消失了。 - Alexander Meise
1
我很高兴听到你解决了这个问题。今天早上我会尝试自己解决它。 - DazWilkin
1
@AlexanderMeise 做得好,找到了自己问题的解决方案。您能否将您的答案发布为正式答案,以帮助其他遇到类似问题的用户? - Rogelio Monter
1
我想补充一下,我使用的是Windows系统,并遇到了同样的问题。该问题已通过以下步骤解决:1.将USE_GKE_GCLOUD_AUTH_PLUGIN=True添加到环境变量中,2.重新启动Windows终端,3.运行gcloud container clusters get-credentials CLUSTER_NAME,如@DazWilkin所述。由于我没有重新启动终端,导致第一次运行gcloud container...时未能更新环境变量,这是我困惑的根本原因。 - Adrian Wiik
4个回答

44

我通过在.bashrc中添加正确的导出来解决了这个问题。

export USE_GKE_GCLOUD_AUTH_PLUGIN=True

使用 . ~/.bashrc 命令重新加载集群配置后,可以通过以下方式获取 .bashrc 文件:

gcloud container clusters get-credentials clustername

警告消失了:

user@laptop:/$ k get svc -A
NAMESPACE     NAME                   TYPE           CLUSTER-IP     EXTERNAL-IP    
kube-system   default-http-backend   NodePort       10.10.13.157   <none>         
kube-system   kube-dns               ClusterIP      10.10.0.10     <none>         
kube-system   kube-dns-upstream      ClusterIP      10.10.13.92    <none>         
kube-system   metrics-server         ClusterIP      10.10.2.191    <none>         

4
在我们的GCP管理器上,它成功地解决了我的Dockerfile版本问题。重要的是要使用"export USE_GKE_GCLOUD_AUTH_PLUGIN=True"而不是GCP文章建议的"USE_GKE_GCLOUD_AUTH_PLUGIN=True"。 - Gonzalo Cao
感谢您的评论,值得10个赞。 :) - OpenBSDNinja
"gcloud container clusters get-credentials clustername" 是我需要的唯一东西,让它正常工作。 - FrankyHollywood

10

我遇到了类似的问题,当连接到一个新的Kubernetes集群时,其版本为 v1.22.10-gke.600

gcloud container clusters get-credentials my-cluster --zone europe-west6-b --project project

我遇到了以下错误,似乎是因为新版本出现了错误

Fetching cluster endpoint and auth data.
CRITICAL: ACTION REQUIRED: gke-gcloud-auth-plugin, which is needed for continued use of kubectl, was not found or is not executable. Install gke-gcloud-auth-plugin for use with kubectl by following https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke

在此输入图片描述

我的解决方法

gcloud components install gke-gcloud-auth-plugin
export USE_GKE_GCLOUD_AUTH_PLUGIN=True
gcloud container clusters get-credentials my-cluster --zone europe-west6-b --project project


10
你需要执行以下操作,从而避免现在和将来出现的错误,并消除此警告信息。
  1. Add the correct export in .bashrc. I am using .zshrc instead of .bashrc so added export in .zshrc

    export USE_GKE_GCLOUD_AUTH_PLUGIN=True
    
  2. Reload .bashrc

    source ~/.bashrc
    
  3. Update gcloud to the latest version.

    gcloud components update
    
  4. Run the following command. Replace the CLUSTER_NAME with the name of your cluster. This will force the kubeconfig for this cluster to be updated to the Client-go Credential Plugin configuration.

    gcloud container clusters get-credentials CLUSTER_NAME
    
  5. Check kubeconfig file by enter the following command. Now you should be able to detect the changes(gke-gcloud-auth-plugin) in the kubeconfig file in the users section in the Root/Home directory

    cat ~/.kube/config
    
原因是:

从v1.26开始,kubectl将不再拥有GKE的内置身份验证机制。因此,GKE用户需要下载并使用单独的身份验证插件来生成GKE特定的令牌以支持GKE的身份验证。请阅读这里获取更多详细信息。


1
升级到GKE Gcloud身份验证插件后,我所有的kubectl命令都开始超时。
事实证明,我忘记在get-credentials命令中添加--internal-ip标志,这在我的情况下是必需的。
gcloud container clusters get-credentials CLUSTER_NAME --internal-ip

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接