如何在 Docker Desktop 上創建新的 Kubernetes 集群? (How to create a new Kubernetes cluster on Docker Desktop?)


問題描述

如何在 Docker Desktop 上創建新的 Kubernetes 集群? (How to create a new Kubernetes cluster on Docker Desktop?)

我似乎無法弄清楚如何在我的計算機上運行 Docker Desktop 的實例上創建一個全新的 Kubernetes 集群。(這應該是 Mac 還是 PC 無關緊要)。

我知道如何設置當前集群上下文,但我只有一個集群,所以我無法設置其他任何東西。

### 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”

更多問題:

  1. 如果我有多個集群,那麼只有其中一個(當前“設置”的一個)將同時運行,而另一個停止/休眠?
  2. 集群之間是相互獨立的,所以如果我可以在一個集群上閒逛,那麼這應該不會影響另一個集群

參考解法

方法 1:

Kubernetes config file describes 3 objects: clusters, users, and contexts.

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. an example context object:

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.

multiple k8s clusters from docker‑desktop

under the hood, when you enable k8s, docker desktop downloads kubernetes components as docker images, and the server listens 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. it doesnt mean the clusters are dead. it wont affect them at all.

方法 2:

Make sure that the checkbox is enabled

enter image description here

方法 3:

Using Docker Desktop you can create multiple clusters using a development tool such as k3d. Disable Kubernetes under Docker Desktop preferences as you won't need it for this. Then install XCode CLT, Homebrew and use Brew to install k3d locally. 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. A more in‑depth tutorial is available for macOS without fee.

(by Pure.KromeEfrat LevitanMazzyvhs)

參考文件

  1. How to create a new Kubernetes cluster on Docker Desktop? (CC BY‑SA 2.5/3.0/4.0)

#docker-desktop #Kubernetes #docker






相關問題

在 Docker 容器中安裝 Windows 服務 (Install Windows service in Docker container)

在不同的用戶下啟動 docker 容器 (Start the docker container under a different user)

如何在 Docker Desktop 上創建新的 Kubernetes 集群? (How to create a new Kubernetes cluster on Docker Desktop?)

連接期間的 Docker for Desktop 錯誤:發布連接嘗試失敗,因為連接方沒有正確 (Docker for Desktop error during connect: Post A connection attempt failed because the connected party did not properly)

Jenkins 昨天安裝成功並在 windows 10 的 docker 桌面上運行,但今天無法在 http://localhost:8080 啟動 jenkins (Jenkins installed successfully and run on docker desktop on windows 10 yesterday , but unable to start jenkins at http://localhost:8080 today)

運行“docker exec”時發布端口 (publish port when running 'docker exec')

無法連接到 docker-desktop kubernetes 中部署的 API?負載均衡器服務不工作 (Unable to connect to the API deployed in docker-desktop kubernetes?. Loadbalancer service not working)

我在哪裡可以看到失敗的 Docker Desktop Windows 安裝的日誌文件? (Where can I see log files for failed Docker Desktop Windows installation?)

如何從 docker-credential-osxkeychain 獲取價值 (How to get value from docker-credential-osxkeychain)

無法訪問 Kubernetes 集群外的 NodePort 服務 (Cannot access NodePort service outside Kubernetes cluster)

如何在 eclipse-che 環境中配置 docker 引擎 (How to configure docker engine inside eclipse-che environment)

如何在 Docker Desktop 中使用參數運行 docker 實例? (How to run a docker instance with params in Docker Desktop?)







留言討論