如何使用 gcp auth 插件删除 kubectl 中的警告?

How to remove warning in kubectl with gcp auth plugin?

当我 运行 任何 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

我已按照 the link 中的说明进行了多次操作,但警告不断出现,使 kubectl 输出难以阅读。

OS:

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 并重新 运行 获取凭证没有用。

我通过在 .bashrc

中添加正确的导出解决了这个问题
export USE_GKE_GCLOUD_AUTH_PLUGIN=True

在使用 . ~/.bashrc 采购 .bashrc 并重新加载集群配置后:

gcloud container clusters get-credentials staking

警告消失:

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>