はじめに
普段の業務でKubernetes(k8s)を触る機会はありますが、業務のk8s環境で好き勝手いじるわけにもいきません。
そこで、自宅のWindows環境でk8sを利用できる環境を構築した際の手順を、備忘録として残しておこうと思います。
構築手順
WSL2(Windows Subsystem for Linux 2 )のセットアップ
・windowsの検索バーから「Microsoft Store」を検索し、開く
・「Microsoft Store」内の検索バーで「Ubuntu」と検索し、インストール
(Ubuntu 24.04 LTSにしています)

・インストールしたUbuntuを開くと以下の画像のようなウィンドウが開くため、
そのままEnterキーを押下し、Linux用windowsサブシステムのインストールを実行

・Linux用windowsサブシステムのインストールが完了したらEnterキーを押下し、PCを再起動

・Windowsの検索バーで「Windowsの機能の有効化または無効化」を入力し、開く

・以下の2項目にチェックがついているか確認
(※チェックが無い場合、チェックつけて再起動)
・Linux用Windowsサブシステム
・Virtual Machine Platform

・再度インストールしたUbuntuを開くと、初期設定(ユーザ名/パスワード)を聞かれるので、
それぞれ設定すればUbuntuのセットアップは完了
※画像はtest-user1で設定した例です

Docker DesktopのインストールとWSL2統合の有効化
・以下のサイトからDocker DesktopのインストーラーをWindows上にダウンロードし、
セットアップを実施 (※完了したら要PC再起動)
https://www.docker.com/products/docker-desktop/


・Docker Desktopから設定を開き、
「Resources」> 「WSL integration」でEnableにチェックマークがついていることを確認

・Ubuntuのターミナルで以下のコマンドを実行し、Dockerグループにユーザ追加
sudo usermod -aG docker $USER
test-user1:~$ sudo usermod -aG docker $USER
[sudo] password for test-user1:
test-user1:~$ cat /etc/group | grep docker
docker:x:1001:test-user1
・試しにメッセージを表示するイメージでコンテナ起動ができるか確認
※下記に記載の結果のような内容が返ってくればOK
docker run hello-world
test-user1:~$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
- 停止しているコンテナ表示
docker ps -a
test-user1:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a5cc07f73650 hello-world "/hello" 3 minutes ago Exited (0) 3 minutes ago naughty_babbage
- 停止しているテスト用コンテナ削除
docker rm <CONTAINER_ID_OR_NAME>
test-user1:~$ docker rm naughty_babbage
naughty_babbage
kubernetes(Minikube)のセットアップ
- kubectlのインストール
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
test-user1:~$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 138 100 138 0 0 675 0 --:--:-- --:--:-- --:--:-- 673
100 57.7M 100 57.7M 0 0 10.5M 0 0:00:05 0:00:05 --:--:-- 11.1M
test-user1:~$ sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
[sudo] password for test-user1:
- kubectlがインストールできたか確認(kubectl バージョン確認)
kubectl version
test-user1:~$ kubectl version
Client Version: v1.34.1
Kustomize Version: v5.7.1
The connection to the server localhost:8080 was refused - did you specify the right host or port?
- Minikube のインストール
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
test-user1:~$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 133M 100 133M 0 0 9385k 0 0:00:14 0:00:14 --:--:-- 10.5M
test-user1:~$ sudo install minikube-linux-amd64 /usr/local/bin/minikube
- Minikube がインストールできたか確認(minikubeバージョン確認)
minikube version
test-user1:~$ minikube version
minikube version: v1.37.0
commit: 65318f4cfff9c12cc87ec9eb8f4cdd57b25047f3
- minikubeクラスターの起動
※Docker DesktopがWindows上で起動していることを確認し、
以下のコマンドでminikubeクラスタを起動
minikube start --driver=docker
test-user1:~$ minikube start --driver=docker
😄 minikube v1.37.0 on Ubuntu 24.04 (kvm/amd64)
✨ Using the docker driver based on user configuration
📌 Using Docker driver with root privileges
❗ For an improved experience it's recommended to use Docker Engine instead of Docker Desktop.
Docker Engine installation instructions: https://docs.docker.com/engine/install/#server
👍 Starting "minikube" primary control-plane node in "minikube" cluster
🚜 Pulling base image v0.0.48 ...
💾 Downloading Kubernetes v1.34.0 preload ...
> preloaded-images-k8s-v18-v1...: 337.07 MiB / 337.07 MiB 100.00% 7.24 Mi
> gcr.io/k8s-minikube/kicbase...: 488.51 MiB / 488.52 MiB 100.00% 5.57 Mi
🔥 Creating docker container (CPUs=2, Memory=3072MB) ...
🐳 Preparing Kubernetes v1.34.0 on Docker 28.4.0 ...
🔗 Configuring bridge CNI (Container Networking Interface) ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
- minikubeクラスター状態確認(STATUSがReadyになっていればOK)
kubectl get node
test-user1:~$ kubectl get node
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 67s v1.34.0
これでwindows環境でk8sが使えるようになりました!
おまけ
①minikubeクラスターの停止方法
minikube stop
test-user1:~$ minikube stop
✋ Stopping node "minikube" ...
🛑 Powering off "minikube" via SSH ...
🛑 1 node stopped.
②クラスタの削除方法
minikube delete
test-user1:~$ minikube delete
🔥 Deleting "minikube" in docker ...
🔥 Deleting container "minikube" ...
🔥 Removing /home/test-user1/.minikube/machines/minikube ...
💀 Removed all traces of the "minikube" cluster.
③minikubeのウェブUIでクラスターの状態確認
minikube dashboard
test-user1:~$ minikube dashboard
🔌 Enabling dashboard ...
▪ Using image docker.io/kubernetesui/dashboard:v2.7.0
▪ Using image docker.io/kubernetesui/metrics-scraper:v1.0.8
💡 Some dashboard features require the metrics-server addon. To enable all features please run:
minikube addons enable metrics-server
🤔 Verifying dashboard health ...
🚀 Launching proxy ...
🤔 Verifying proxy health ...
🎉 Opening http://127.0.0.1:43343/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
👉 http://127.0.0.1:43343/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
以上、windows環境でkubernetesを使用可能な環境構築方法でした
kubernetes触って学びたい方の参考になれば幸いです
