1. 环境
- windows server2019
- kubernetes 1.18.2
- docker ce 18.09
- 所有的节点的hosts文件添加相应的ip和hosts
可提前下载文件至本地:
1.18.2的文件: - https://dl.k8s.io/v1.18.2/kubernetes-node-windows-amd64.tar.gz
其他版本:https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/
2. 设置flannel(linux节点)
2.1 在linux的控制界面上设置,启用到 iptables 链的桥接 IPv4 流量。
sysctl net.bridge.bridge-nf-call-iptables=1
2.2 配置参数:
kubectl -n kube-system edit cm kube-flannel-cfg
net-conf.json: |
{
"Network": "10.244.0.0/16",
"Backend": {
"Type": "vxlan",
"VNI" : 4096,
"Port": 4789
}
}
重启flannel
kubectl rollout restart ds kube-flannel-ds -n kube-system
3. 安装Windows的flannel和kube-proxy相关daemonset(linux节点)
3.1 安装
curl -L https://github.com/kubernetes-sigs/sig-windows-tools/releases/latest/download/kube-proxy.yml | sed 's/VERSION/v1.18.2/g' | kubectl apply -f -
kubectl apply -f https://github.com/kubernetes-sigs/sig-windows-tools/releases/latest/download/flannel-overlay.yml
3.2 查看
kubectl get all --all-namespaces |grep windows
kube-system daemonset.apps/kube-flannel-ds-windows-amd64 0 0 0 0 0 <none> 130m
kube-system daemonset.apps/kube-proxy-windows 0 0 0 0 0 kubernetes.io/os=windows 2d22h
4. windows节点
4.1 开启Hyper-V
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
4.2 开启RRAS 功能,用于 Pod 跨主机通信
4.3 安装docker
用administrator权限在powershell里运行:
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install-Package -Name docker -ProviderName DockerMsftProvider -Force -RequiredVersion 18.09
Restart-Computer -Force
启动docker
Start-Service docker
查看docker版本
PS C:\Windows\system32> docker --version
Docker version 18.09.13, build e3e8e55
4.4 初始化windows界面
下载运行脚本:
curl.exe -LO https://github.com/kubernetes-sigs/sig-windows-tools/releases/latest/download/PrepareNode.ps1
我提前将文件下载下来放在c:\k目录下了,这里就注释掉了。
运行脚本:
./PrepareNode.ps1 -KubernetesVersion v1.18.2
4.5 windows节点加入集群
建议提前将windows节点需要的镜像下载到windows节点里,避免等待时间过长报错,需要的镜像为:
在linux控制节点上打印加入节点的token:
~ # kubeadm token create --print-join-command
kubeadm join 172.29.9.239:6443 --token iuqm3l.vrmrlqcqtgqbwdtk --discovery-token-ca-cert-hash sha256:02739e517b832cf38109779fd178b35fb71efe6a3b13cfd9c44580c273211fec
在windows节点powershell运行:
PS C:\k>kubeadm join 172.29.9.239:6443 --token iuqm3l.vrmrlqcqtgqbwdtk --discovery-token-ca-cert-hash sha256:02739e517b832cf38109779fd178b35fb71efe6a3b13cfd9c44580c273211fec --v=5
--v=5为查看详细信息
5.查看
5.1 查看node
linux控制界面查看:
~ # kubectl get nodes
NAME STATUS ROLES AGE VERSION
oran-master1 Ready master 2d20h v1.18.2
oran-node1 Ready <none> 160m v1.18.2
5.2 创建deployment
5.3 创建iss应用
kubectl run iis --image=microsoft/iis --overrides='{"spec": { "nodeSelector": { "kubernetes.io/os": "windows" } } }'
5.4 创建iss的service
kubectl expose deploy iis --type=NodePort --port=80 --target-port=80
5.5 查看负载
~ kubectl get pod,deploy,svc | grep iis
pod/iis-776c85bc49-xpxhh 1/1 Running 0 47m
deployment.apps/iis 1/1 1 1 47m
service/iis NodePort 10.111.33.66 <none> 80:30038/TCP 47m
查看页面:ip:port
参考
- https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/adding-windows-nodes/
- https://www.chenshaowen.com/blog/add-windows-node-for-k8s.html#43-%E6%89%BE%E4%B8%8D%E5%88%B0-/run/flannel/subnet.env
遇到的问题
-
The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.
windows节点的hosts里没有localhost的解析
-
Failed to create pod sandbox: rpc error: code = Unknown desc = failed to start sandbox container for pod "kube-flannel-ds-windows-amd64-wmct2": Error response from daemon: network host not found
创建docker网络:docker network create -d nat host