[英]How to create a new Kubernetes cluster on Docker Desktop?
I can't seem to figure out how to create a totally new Kubernetes cluster on a Docker Desktop running instance on my computer.我似乎无法弄清楚如何在我的计算机上运行实例的 Docker 桌面上创建一个全新的 Kubernetes 集群。 (It shouldn't matter if this was a Mac or PC).
(这是 Mac 还是 PC 应该无关紧要)。
I know how to -set- the current cluster context, but I only have one cluster so I can't set anything else.我知道如何设置当前集群上下文,但我只有一个集群,因此无法设置其他任何内容。
### What's my current context pointing to?
$ kubectl config current-context
docker-for-desktop
### Set the context to be "docker-for-desktop" cluster
$ kubectl config use-context docker-for-desktop
Switched to context “docker-for-desktop”
Further questions:进一步的问题:
Kubernetes config file describes 3 objects: clusters , users , and contexts . Kubernetes 配置文件描述了 3 个对象:集群、用户和上下文。
cluster - cluster name + details - the host and the certificates.集群- 集群名称 + 详细信息 - 主机和证书。
user - user name and credentials, to authorise you against any cluster host.用户- 用户名和凭据,授权您使用任何集群主机。
the context role is to make the connection between a user and a cluster , so when you use that context, kubectl
will authorise you against the cluster specified in the context object, using the credentials of the user specified in the context object.上下文角色是在用户和集群之间建立连接,因此当您使用该上下文时,
kubectl
将使用上下文对象中指定的用户凭据授权您针对上下文对象中指定的集群。 an example context
object:一个示例
context
对象:
apiVersion: v1
current-context: ""
kind: Config
preferences: {}
clusters:
- cluster:
certificate-authority: xxxxxxxxx
server: xxxxxxxxx
name: gke_dev-yufuyjfvk_us-central1-a_standard-cluster-1
users:
- name: efrat-dev
user:
client-certificate: xxxxxxxxx
client-key: xxxxxxxxx
contexts:
- context:
cluster: gke_dev-yufuyjfvk_us-central1-a_standard-cluster-1
user: efrat-dev
name: gke-dev
the kubectl config
subcommand has a set of commands to generate cluster, user & context entries in the config file. kubectl config
子命令有一组命令来在配置文件中生成集群、用户和上下文条目。
multiple k8s clusters from docker-desktop来自 docker-desktop 的多个 k8s 集群
under the hood, when you enable k8s, docker desktop downloads kubernetes components as docker images, and the server listens https://localhost:6443
.在幕后,当您启用 k8s 时,docker desktop 会将 kubernetes 组件下载为 docker 镜像,并且服务器会侦听
https://localhost:6443
。 it is all done automatically so unless you have any intention to run the entire structure by yourself i dont suppose you can configure it to run multiple clusters.这一切都是自动完成的,因此除非您打算自己运行整个结构,否则我不认为您可以将其配置为运行多个集群。
about your further questions:关于您的进一步问题:
when you set a context, kubectl
will set current-context
to that one, and every kubectl
you run will go to the context's cluster, using the context's user credentials.当您设置上下文时,
kubectl
会将current-context
设置kubectl
current-context
,并且您运行的每个kubectl
都将使用上下文的用户凭据转到上下文的集群。 it doesnt mean the clusters are dead.这并不意味着集群已经死了。 it wont affect them at all.
它根本不会影响他们。
Using Docker Desktop you can create multiple clusters using a development tool such as k3d .使用 Docker Desktop,您可以使用诸如k3d 之类的开发工具创建多个集群。 Disable Kubernetes under Docker Desktop preferences as you won't need it for this.
在 Docker 桌面首选项下禁用 Kubernetes,因为您不需要它。 Then install XCode CLT, Homebrew and use Brew to install k3d locally.
然后安装 XCode CLT、Homebrew 并使用 Brew 在本地安装 k3d。 Next issue the commands:
接下来发出命令:
k3d cluster create one && \
k3d cluster create two
This will create two clusters, automatically switching contexts.这将创建两个集群,自动切换上下文。 Run
k3d cluster list
to list available clusters and use k3d --help
for online help.运行
k3d cluster list
列出可用的集群并使用k3d --help
获取在线帮助。 A more in-depth tutorial is available for macOS without fee.免费提供适用于 macOS 的更深入的教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.