Docker Desktop を使った Kubernetes へのデプロイ

Docker Desktop には手元のマシン上で動作する Docker CLI 統合環境に加えて、Kubernetes のスタンドアロンサーバーとクライアントが含まれます。

Kubernetes サーバーは Docker インスタンス内にローカルに実行されます。 設定変更することはできず、単一ノードクラスターとして動作します。 Kubernetes サーバーは、ローカルシステム内の Docker コンテナー内部で稼動します。 ローカル環境でのテスト用として利用するものです。

Kubernetes サポートが有効である場合、Kubernetes と Swarm へ同時並行により開発内容をデプロイし、スタンドアロンコンテナーとすることができます。 Kubernetes サーバーの有効、無効は、他の開発内容へは影響しません。

Install and turn on Kubernetes

  1. From the Docker Desktop Dashboard, select the Settings.

  2. Select Kubernetes from the left sidebar.

  3. Next to Enable Kubernetes, select the checkbox.

  4. Select Apply & Restart to save the settings and then select Install to confirm. This instantiates images required to run the Kubernetes server as containers, and installs the /usr/local/bin/kubectl command on your machine.

    重要

    The kubectl binary is not automatically packaged with Docker Desktop for Linux. To install the kubectl command for Linux, see Kubernetes documentation. It should be installed at /usr/local/bin/kubectl.

By default, Kubernetes containers are hidden from commands like docker ps, because managing them manually is not supported. Most users do not need this option. To see these internal containers, select Show system containers (advanced).

When Kubernetes is turned on and running, an additional status bar in the Docker Desktop Dashboard footer and Docker menu displays.

メモ

Docker Desktop does not upgrade your Kubernetes cluster automatically after a new update. To upgrade your Kubernetes cluster to the latest version, select Reset Kubernetes Cluster.

Use the kubectl command

Kubernetes integration provides the Kubernetes CLI command at /usr/local/bin/kubectl on Mac and at C:\Program Files\Docker\Docker\Resources\bin\kubectl.exe on Windows. This location may not be in your shell's PATH variable, so you may need to type the full path of the command or add it to the PATH.

If you have already installed kubectl and it is pointing to some other environment, such as minikube or a GKE cluster, ensure you change the context so that kubectl is pointing to docker-desktop:

$ kubectl config get-contexts
$ kubectl config use-context docker-desktop

情報

Run the kubectl command in a CMD or PowerShell terminal, otherwise kubectl config get-contexts may return an empty result.

If you are using a different terminal and this happens, you can try setting the kubeconfig environment variable to the location of the .kube/config file.

If you installed kubectl using Homebrew, or by some other method, and experience conflicts, remove /usr/local/bin/kubectl.

You can test the command by listing the available nodes:

$ kubectl get nodes

NAME                 STATUS    ROLES            AGE       VERSION
docker-desktop       Ready     control-plane    3h        v1.29.1

For more information about kubectl, see the kubectl documentation.

Turn off and uninstall Kubernetes

To turn off Kubernetes in Docker Desktop:

  1. From the Docker Desktop Dashboard, select the Settings icon.
  2. Select Kubernetes from the left sidebar.
  3. Next to Enable Kubernetes, clear the checkbox
  4. Select Apply & Restart to save the settings.This stops and removes Kubernetes containers, and also removes the /usr/local/bin/kubectl command.