我有Kubernetes在两个不同的环境中工作得很好,即在我的本地环境(MacBook运行minikube)和谷歌的容器引擎(GCE, Kubernetes在谷歌云上)。我使用MacBook/local环境来开发和测试我的YAML文件,然后,完成后,在GCE上尝试它们。
目前我需要单独使用每个环境:我需要在我的本地环境中编辑YAML文件,当准备就绪时,(git)将它们克隆到GCE环境中,然后使用/部署它们。这是一个有点麻烦的过程。
理想情况下,我想从我的Macbook使用kubectl来轻松地在本地minikube或GCE Kubernetes环境之间切换,并轻松地确定在哪里使用YAML文件。有没有一种简单的方法来切换上下文来做到这一点?
请查看最新的(docker 19.03) docker context命令。
Ajeet Singh Raina)在“Docker 19.03.0预发布版:快速上下文切换,无根Docker, Sysctl对Swarm服务的支持”中阐述了这一点。
A context is essentially the configuration that you use to access a particular cluster.
Say, for example, in my particular case, I have 4 different clusters – mix of Swarm and Kubernetes running locally and remotely.
Assume that I have a default cluster running on my Desktop machine , 2 node Swarm Cluster running on Google Cloud Platform, 5-Node Cluster running on Play with Docker playground and a single-node Kubernetes cluster running on Minikube and that I need to access pretty regularly.
Using docker context CLI I can easily switch from one cluster(which could be my development cluster) to test to production cluster in seconds.
$ sudo docker context --help
Usage: docker context COMMAND
Manage contexts
Commands:
create Create a context
export Export a context to a tar or kubeconfig file
import Import a context from a tar file
inspect Display detailed information on one or more contexts
ls List contexts
rm Remove one or more contexts
update Update a context
use Set the current docker context
Run 'docker context COMMAND --help' for more information on a command.
例如:
[:)Captain'sBay=>sudo docker context ls .
名称描述docker端点kubernetes端点编排器
unix:///var/run/docker. xmlSock https://127.0.0.1:16443(默认)swarm
swarm-context1
请查看最新的(docker 19.03) docker context命令。
Ajeet Singh Raina)在“Docker 19.03.0预发布版:快速上下文切换,无根Docker, Sysctl对Swarm服务的支持”中阐述了这一点。
A context is essentially the configuration that you use to access a particular cluster.
Say, for example, in my particular case, I have 4 different clusters – mix of Swarm and Kubernetes running locally and remotely.
Assume that I have a default cluster running on my Desktop machine , 2 node Swarm Cluster running on Google Cloud Platform, 5-Node Cluster running on Play with Docker playground and a single-node Kubernetes cluster running on Minikube and that I need to access pretty regularly.
Using docker context CLI I can easily switch from one cluster(which could be my development cluster) to test to production cluster in seconds.
$ sudo docker context --help
Usage: docker context COMMAND
Manage contexts
Commands:
create Create a context
export Export a context to a tar or kubeconfig file
import Import a context from a tar file
inspect Display detailed information on one or more contexts
ls List contexts
rm Remove one or more contexts
update Update a context
use Set the current docker context
Run 'docker context COMMAND --help' for more information on a command.
例如:
[:)Captain'sBay=>sudo docker context ls .
名称描述docker端点kubernetes端点编排器
unix:///var/run/docker. xmlSock https://127.0.0.1:16443(默认)swarm
swarm-context1
为不同的环境克隆YAML文件绝对是理想的。你要做的是模板化你的YAML文件——通过提取不同环境的参数。
当然,您可以使用一些模板引擎,分离YAML中的值,并为特定环境生成YAML。但如果你采用掌舵图,这是很容易做到的。要查看一些示例图表,请访问这个Github回购的稳定目录
以Wordpress图表为例,你可以在两个环境中使用两个不同的命令:
戴夫:
头盔安装——name dev-release——set \
wordpressUsername = dev_admin \
wordpressPassword = dev_password \
mariadb。mariadbRootPassword = dev_secretpassword \
稳定/ wordpress
不过,在CLI上传递这些值并不是必须的,可以将这些值存储在一个名为aptly values的文件中。Yml,你可以为不同的环境有不同的文件
在转换为Helm图表标准时,您需要做一些工作,但这些努力是值得的。
是的,我想这就是你要问的问题。要查看当前配置,请使用kubectl配置视图。Kubectl从以下位置加载并合并配置(按顺序)
--kubeconfig=/path/to/.kube/config command line flag
KUBECONFIG=/path/to/.kube/config env variable
$HOME/.kube/config - The DEFAULT
我使用——kubecconfig,因为我经常在多个集群之间切换。它有点麻烦,但它工作得很好。
更多信息请看这些。
https://kubernetes.io/docs/tasks/administer-cluster/share-configuration/和https://kubernetes.io/docs/concepts/cluster-administration/authenticate-across-clusters-kubeconfig/