33
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WindowsでKubernetesを使用可能な環境構築

Last updated at Posted at 2025-12-02

はじめに

普段の業務でKubernetes(k8s)を触る機会はありますが、業務のk8s環境で好き勝手いじるわけにもいきません。
そこで、自宅のWindows環境でk8sを利用できる環境を構築した際の手順を、備忘録として残しておこうと思います。

構築手順

WSL2(Windows Subsystem for Linux 2 )のセットアップ

・windowsの検索バーから「Microsoft Store」を検索し、開く
・「Microsoft Store」内の検索バーで「Ubuntu」と検索し、インストール
  (Ubuntu 24.04 LTSにしています)
image.png
・インストールしたUbuntuを開くと以下の画像のようなウィンドウが開くため、
 そのままEnterキーを押下し、Linux用windowsサブシステムのインストールを実行
image.png
・Linux用windowsサブシステムのインストールが完了したらEnterキーを押下し、PCを再起動
image.png
・Windowsの検索バーで「Windowsの機能の有効化または無効化」を入力し、開く
image.png
・以下の2項目にチェックがついているか確認
(※チェックが無い場合、チェックつけて再起動)

・Linux用Windowsサブシステム
・Virtual Machine Platform

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


Docker DesktopのインストールとWSL2統合の有効化

・以下のサイトからDocker DesktopのインストーラーをWindows上にダウンロードし、
 セットアップを実施 (※完了したら要PC再起動)
https://www.docker.com/products/docker-desktop/
image.png
image.png
・Docker Desktopから設定を開き、
 「Resources」> 「WSL integration」でEnableにチェックマークがついていることを確認
image.png
・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のインストール
コマンド1
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
コマンド2
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
結果1
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
結果2
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 のインストール
コマンド1
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
コマンド2
sudo install minikube-linux-amd64 /usr/local/bin/minikube
結果1
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
結果2
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/

image.png

以上、windows環境でkubernetesを使用可能な環境構築方法でした
kubernetes触って学びたい方の参考になれば幸いです

33
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?