删除后,获取docker-for-windows Kuberentes kubeconfig文件

问题描述 投票:0回答:2

在设置对基于云的K8群集的访问权限时,我的Docker for Windows ~/.kube/config文件被替换。

有没有办法重新创建它而无需重新启动Docker for Windows Kubernetes?

更新我当前的~/.kube/config文件现在设置为GKE集群。我不想为Kubernetes重置Docker并破坏它。相反,我想为Docker for Windows创建一个单独的kubeconfig文件,即将其放在其他位置而不是~/.kube/config

kubernetes docker-for-windows
2个回答
2
投票

您可能想要为GKE备份~/.kube/config,然后在Docker for Windows上禁用/重新启用Kubernetes。拉起Windows命令提示符:

copy \<where-your-.kube-is\config \<where-your-.kube-is\config.bak

然后按照this。实质上,取消选中该框,等待几分钟再重新检查。

docker for windows

您可以重新创建而无需在Docker上禁用/重新启用Kubernetes,但您必须确切知道API服务器和凭据(证书等)的位置:

 kubectl config set-context ...
 kubectl config use-context ...

奇怪的是,你指定~/.kube/config,其中~(代字号)thingy是unix / linux的东西,但也许你的意思是$HOME


0
投票

您基本上想要访问多个群集。一种选择是使用KUBECONFIG环境变量。 Here is the documentation

KUBECONFIG环境变量是配置文件的路径列表。该列表以冒号分隔,适用于Linux和Mac,以分号分隔,适用于Windows。如果您有KUBECONFIG环境变量,请熟悉列表中的配置文件。

或者,您可以提供内联选项。

kubectl config --kubeconfig=config-demo set-context dev-frontend --cluster=development --namespace=frontend --user=developer
kubectl config --kubeconfig=config-demo set-context dev-storage --cluster=development --namespace=storage --user=developer
kubectl config --kubeconfig=config-demo set-context exp-scratch --cluster=scratch --namespace=default --user=experimenter

然后使用use-context

© www.soinside.com 2019 - 2024. All rights reserved.