WSL安装Kubernetes
- 配置文件修改
修改.wslconfig将WSL设置为镜像网络模式1
2
3
4
5
6
7[wsl2]
networkingMode=mirrored
dnsTunneling=true
autoProxy=true
[experimental]
sparseVhd=true
hostAddressLoopback=true/etc/resolv.conf
内不可包含本地nameserver - 安装cri-dockerd, kubeadm, kubelet, kubectl
- 初始化Kubernetes
1
2
3
4
5sudo swapoff -a
sudo systemctl start kubelet
sudo kubeadm init --control-plane-endpoint=main --pod-network-cidr=10.244.0.0/16 --cri-socket=unix:///var/run/cri-dockerd.sock
# 如果出错使用下列命令重置
sudo kubeadm reset --cri-socket=unix:///var/run/cri-dockerd.sock - 安装flannel
1
2
3curl -o kube-flannel.yml https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
# WSL的VXLAN内核功能异常,因此切换其它Backend,需要修改kube-flannel.yml, Backend的type改为UDP, privileged改为true
kubectl apply -f kube-flannel.yml - 安装Dashboard
1
2helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard --set kong.admin.tls.enabled=false #关闭TLS - 移除主节点的
NoSchedule
taint1
kubectl taint nodes xwd node-role.kubernetes.io/control-plane:NoSchedule-
- 创建root用户并绑定最高权限
1
2kubectl create serviceaccount root
kubectl create clusterrolebinding rootBind --clusterrole=cluster-admin --serviceaccount=default:root - 生成root用户登录Dashboard的Token,并开放Dashboard本地访问
1
kubectl create token root && kubectl port-forward -n kubernetes-dashboard svc/kubernetes-dashboard-kong-proxy 8443:443
常用命令
1 |
|