最近拿到新的工作机,需要搭一个win10上面的minikube 和docker的开发环境。做个记录。
整体思想是在WSL(Microsoft-Windows-Subsystem-Linux)中使用kubectl 和docker的 Client端,链接使用hyper-v中的minikube cluster和docker 虚拟机。
-
这篇只写WSL和minikube
1.PNG
缺陷
把方案缺陷和注意事项列一下
- 请在powershell里面执行minikube 命令,而不是WSL
- 每当minibkue stop,重新 minibkue start之后。需要根据更新过的"C:\User<user>\.kube\config" 中新的 VM ip地址,更新WSL ,/home/<user>/.kube/config中的IP
- 我遇到minikube stop卡死的问题,只能手动登陆minikube,用docker/tcuser 登录后,shutdown 虚拟机
- 这个方案,似乎网络性能很差
安装需求
- Windows 10 专业版
- 内存16G (8G 也凑合)
- Bios 打开 VT 相关的选项 (为了hyper-v)
安装WSL(Windows Subsystem for Linux)
- 打开用Adminstrator 权限PowerShell
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
-
在Microsoft Store里面搜索 Ubuntu,安装 (本文用的是Ubuntu 18.04)
ubuntu.PNG
打开Hyper-V
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
PS C:\tools\cmder> DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V
Deployment Image Servicing and Management tool
Version: 10.0.16299.15
Image Version: 10.0.16299.611
Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.
PS C:\tools\cmder>
-
如果命令行不好使,也可以用gui
-
搜索,打开Windows Features
hyperv.PNG -
然后重启
创建 virtual switch for minikube
- 搜索,打开 Hyper-V Manager
- 创建Virtual Switch
- 起个名字(minikube-vs)
-
选择external network, 然后绑定一个物理网卡。
vs.PNG
安装 Chocolatey
Chocolatey : The package manager for Windows
-
以Administrator打开powershell
powershell.PNG - 运行下面的命令
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
- 更新Chocolatey
choco upgrade chocolatey
安装Minikube
在powershell里面执行
choco install minikube
运行minikube
minikube start --vm-driver hyperv --hyperv-virtual-switch="minikube-vs"
-
这里时间可能有些长,可以在Hyper-V manager里面看到有虚拟机创建
minikube.PNG
在WSL里面安装kubectl
sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo touch /etc/apt/sources.list.d/kubernetes.list
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl
配置kubectl
- 打开 Ubuntu 18.04(软件)
C盘会mount在/mnt/c - 在home 目录做个link
ln -s /mnt/c/User/<username>/.minikube
- 复制.kube 目录到你的home
cp -r /mnt/c/Users/<username>/.kube .
- 编辑 ~/.kube/config
把所有 C:\Users<username>\.minikube\xxx
certificate-authority: C:\Users\<username>\.minikube\ca.crt
client-certificate: C:\Users\<username>\.minikube\client.crt
client-key: C:\Users\<username>\.minikube\client.key
替换成/home/<username>/.minikube/xxx (这里是个列子,不要删去每行前面的空格)
certificate-authority: /home/<username>/.minikube/ca.crt
client-certificate: /home/<username>/.minikube/client.crt
client-key: /home/<username>/.minikube/client.key
- 试一下,用kubectl链接minikube 的cluster
elluffn@CN-00011373:~$ kubectl get node
NAME STATUS ROLES AGE VERSION
minikube Ready master 21h v1.10.0
kubectl get po --all-namespaces
kube-system etcd-minikube 1/1 Running 0 3m
kube-system kube-addon-manager-minikube 1/1 Running 7 21h
kube-system kube-apiserver-minikube 1/1 Running 0 3m
kube-system kube-controller-manager-minikube 1/1 Running 0 3m
kube-system kube-dns-86f4d74b45-n2f5m 3/3 Running 27 21h
kube-system kube-proxy-99kpm 1/1 Running 0 2m
kube-system kube-scheduler-minikube 1/1 Running 8 21h
kube-system kubernetes-dashboard-5498ccf677-zrffj 1/1 Running 18 21h
kube-system storage-provisioner 1/1 Running 18 21h
kube-system tiller-deploy-df4fdf55d-6c8jb 1/1 Running 7 21h
安装helm
- 在WSL里面执行
$ curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
$ chmod 700 get_helm.sh
$ ./get_helm.sh
- 初始化helm
helm init
Mount 本地目录到Minikube
- 打开powershell
minikube.exe mount .\git\:/media
Mounting .\git\ into /media on the minikube VM
This daemon process needs to stay alive for the mount to still be accessible...
ufs starting
这个进程窗口不能关闭。
- 打开一个新的powershell,进入minikube验证一下
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\tools\cmder> minikube.exe ssh
_ _
_ _ ( ) ( )
___ ___ (_) ___ (_)| |/') _ _ | |_ __
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
$ ls /media/
test demo
$
- 这样就可以将本地目录 mount进入POD,方便开发,调试
后面再补一篇WSL with Docker的文章。
网友评论