Có 2 cách sử dụng docker và k8s bên trong WSL 2:
- Docker Desktop WSL 2 integration
- Docker CE inside the WSL 2 distro (systemd trên WSL 2)
Trong bài viết này, minhfsex hướng dẫn các bạn cài đặt Minikube trong WSL 2 (sử dụng Ubuntu)
Cài đặt
Cài đặt Ubuntu
Mở Terminal trên Windows, cài đặt WSL2
wsl --install
Restart Window
Liệt kê các bản Linux distribution mà Microsoft hỗ trợ:
PS >wsl -l --online
The following is a list of valid distributions that can be installed.
Install using 'wsl.exe --install <Distro>'.
NAME FRIENDLY NAME
Ubuntu Ubuntu
Debian Debian GNU/Linux
kali-linux Kali Linux Rolling
Ubuntu-18.04 Ubuntu 18.04 LTS
Ubuntu-20.04 Ubuntu 20.04 LTS
Ubuntu-22.04 Ubuntu 22.04 LTS
OracleLinux_7_9 Oracle Linux 7.9
OracleLinux_8_7 Oracle Linux 8.7
OracleLinux_9_1 Oracle Linux 9.1
openSUSE-Leap-15.5 openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4 SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5 SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed openSUSE Tumbleweed
Bạn gõ lệnh
wsl --install -d ubuntu
Cài đặt Docker
Remove the already docker containers
---------------------------------------------------------------
sudo apt-get remove docker docker-engine docker.io containerd runc
Update the repository
----------------------------------
sudo apt-get update
Install the prerequisite softwares
-----------------------------------------------------
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
Add the pgp key to repos
----------------------------------------
curl -fsSL https://download.docker.com/linux/ubu... | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
Update the repository
------------------------------------
sudo apt-get update
Upgrade the wsl
---------------------------
sudo apt-get upgrade -y
Install the docker container engine
--------------------------------------------------------
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
sudo groupadd docker
sudo usermod -aG docker $USER && newgrp docker
Tham khảo thêm: Docker: Cài đặt Docker Engine trên WSL 2 - Part 1.2
Cài đặt Minikube
Binary download
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
Debian package
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb
Start cluster
minikube start
Dừng cluster nhưng không ảnh hưởng tới quá trình deploy
minikue pause
minikube stop
minikube delete --all
Ngoài docker ra, Minikube còn hỗ trợ các driver khác
- kvm2
- podman
- qemu2
- virtualbox
▪ docker: Not healthy: "docker version --format {{.Server.Os}}-{{.Server.Version}}:{{.Server.Platform.Name}}" exit status 1: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version": dial unix /var/run/docker.sock: connect: permission denied
▪ docker: Suggestion: Add your user to the 'docker' group: 'sudo usermod -aG docker $USER && newgrp docker'
💡 Alternatively you could install one of these drivers:
▪ kvm2: Not installed: exec: "virsh": executable file not found in $PATH
▪ podman: Not installed: exec: "podman": executable file not found in $PATH
▪ qemu2: Not installed: exec: "qemu-system-x86_64": executable file not found in $PATH
▪ virtualbox: Not installed: unable to find VBoxManage in $PATH
Cài đặt Kubectl
$ sudo snap install kubectl --classic
kubectl 1.28.3 from Canonical✓ installed
$ kubectl version --client
Client Version: v1.28.3
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Nhận xét
Đăng nhận xét