简体   繁体   English

如何在 Docker 桌面上创建一个新的 Kubernetes 集群?

[英]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:进一步的问题:

  1. If I have multiple clusters, then only one of them (the currently 'set' one) will be running at once with the other's stopped/sleeping?如果我有多个集群,那么只有其中一个(当前“设置”的)将同时运行而另一个停止/休眠?
  2. Clusters are independent from each other, so if i can muck around and play with one cluster, then this should not impact another cluster集群彼此独立,所以如果我可以在一个集群周围玩耍,那么这应该不会影响另一个集群

Make sure that the checkbox is enabled确保复选框已启用

在此处输入图片说明

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.

相关问题 Docker桌面如何新建k8s集群上下文 - Docker desktop how to create new k8s cluster context 如何在没有Kubernetes的情况下使用MQ创建Docker集群 - How to create a docker cluster with MQ without Kubernetes 如何在 Docker 桌面 Kubernetes 集群上找到主 IP? - How do I find the master IP on Docker Desktop Kubernetes Cluster? 在 docker-for-desktop OSX 上删除 kubernetes 集群? - Delete kubernetes cluster on docker-for-desktop OSX? 如何将 Windows docker 容器部署到 docker-for-desktop Kubernetes 集群? 拉取访问被拒绝 - How do I deploy Windows docker containers to docker-for-desktop Kubernetes cluster? pull access denied docker for desktop 如何与Kube.netes交互 - How to interact with Kubernetes on docker for desktop 为 docker 桌面包含的独立 k8s 服务器集群创建新上下文时如何进行身份验证 - How to do authentication when create new context for the cluster of standalone k8s server which docker desktop includes 如何使用 docker 桌面将 kubernetes 集群连接到外部 SQL Server 数据库? - How do I connect a kubernetes cluster to an external SQL Server database using docker desktop? Docker桌面自带的kubernetes小集群如何暴露低号端口 - How to expose low-numbered ports in the kubernetes mini-cluster that comes with Docker Desktop 如何使用 Docker 桌面停止 Docker(和 Kubernetes)? - How to stop Docker (and Kubernetes) using Docker desktop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM