如何在gcloud和minikube之间切换kubectl集群 [英] How to switch kubectl clusters between gcloud and minikube

查看:111
本文介绍了如何在gcloud和minikube之间切换kubectl集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让Kubernetes在两个不同的环境中都能很好地工作,即在我的本地环境(运行minikube的MacBook)和Google的Container Engine(GCE,Google Cloud上的Kubernetes)上都可以.我使用MacBook/本地环境开发和测试我的YAML文件,然后在完成后在GCE上尝试使用它们.

I have Kubernetes working well in two different environments, namely in my local environment (MacBook running minikube) and as well as on Google's Container Engine (GCE, Kubernetes on Google Cloud). I use the MacBook/local environment to develop and test my YAML files and then, upon completion, try them on GCE.

当前,我需要分别处理每个环境:我需要在我的本地环境中编辑YAML文件,并在准备好后,(git)将它们克隆到GCE环境中,然后使用/部署它们.这是一个繁琐的过程.

Currently I need to work with each environment individually: I need to edit the YAML files in my local environment and, when ready, (git) clone them to a GCE environment and then use/deploy them. This is a somewhat cumbersome process.

理想情况下,我想使用Macbook中的kubectl在本地minikube或GCE Kubernetes环境之间轻松切换,并轻松确定YAML文件的使用位置.有没有简单的方法可以切换上下文来做到这一点?

Ideally, I would like to use kubectl from my Macbook to easily switch between the local minikube or GCE Kubernetes environments and to easily determine where the YAML files are used. Is there a simple way to switch contexts to do this?

推荐答案

您可以从本地(minikube)切换到gcloud,然后返回:

You can switch from local (minikube) to gcloud and back with:

kubectl config use-context CONTEXT_NAME

列出所有上下文:

kubectl config get-contexts

您可以为本地和gcloud创建不同的环境,并将其放在单独的yaml文件中.

You can create different enviroments for local and gcloud and put it in separate yaml files.

这篇关于如何在gcloud和minikube之间切换kubectl集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆