How to create a new Kubernetes cluster on Docker Desktop? How to create a new Kubernetes cluster on Docker Desktop? kubernetes kubernetes

How to create a new Kubernetes cluster on Docker Desktop?


Make sure that the checkbox is enabled

enter image description here


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: v1current-context: ""kind: Configpreferences: {}clusters:- cluster:    certificate-authority: xxxxxxxxx    server: xxxxxxxxx  name: gke_dev-yufuyjfvk_us-central1-a_standard-cluster-1users:- name: efrat-dev  user:    client-certificate: xxxxxxxxx    client-key: xxxxxxxxxcontexts:- 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.


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.