1 这个教程基本上是适应1.13.0左右极其以上版本的
2 默认每个机子上已经搭建好了docker,不做解释,docker搭建比较简单
3 (本教程此步骤非必须)安装过程中一些需要从国外网站下载镜像的可以选择或者先预先下载好,或者采用国内镜像加速都是可以的,也可参考
https://blog.csdn.net/qq735679552/article/details/89186899
4 在所有节点上添加国内镜像仓库,master节点和node节点都要添加
swapoff -a
#临时关闭系统交换分区功能,也可以后边通过参数忽略
cd /etc/apt/sources.list.d/
vim kubernetes.list
#添加仓库地址到kubernetes.list文件中保存此信息:deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
apt-get update
#采用阿里云镜像主要是为了能把kubeadm kubectl kubelet添加进去,以便使用apt-get isntall方式安装
5 开始安装:
master节点
apt-get install kubelet=1.13.5-00 kubectl=1.13.5-00 kubeadm=1.13.5-00
kubeadm init --image-repository=registry.aliyuncs.com/google_containers
出现上面的信息表示安装完成,然后继续master上操作
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
安装验证
记录下其他node节点加入此集群凭证
kubeadm join 192.168.137.123:6443 --token hy7q4g.s5osgznm06p3phkk --discovery-token-ca-cert-hash sha256:9e32757e63916b8bd8af575b2d867722816257d38c4e55bcb248c6281e6f7665
node安装(所有node都一样)
apt-get install kubelet=1.13.5-00 kubectl=1.13.5-00 kubeadm=1.13.5-00
kubeadm join 192.168.137.123:6443 --token hy7q4g.s5osgznm06p3phkk --discovery-token-ca-cert-hash sha256:9e32757e63916b8bd8af575b2d867722816257d38c4e55bcb248c6281e6f7665
看的此信息就标识node节点加入了集群
master上验证
说明此时master已经能感知node节点,自此集群搭建成功
遇到的一些问题记录
问题一:
[kubelet] Downloading configuration for the kubelet from the "kubelet-config-1.13" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Activating the kubelet service
[tlsbootstrap] Waiting for the kubelet to perform the TLS Bootstrap...
[kubelet-check] Initial timeout of 40s passed.
Unfortunately, an error has occurred:
timed out waiting for the condition
This error is likely caused by:
- The kubelet is not running
- The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)
If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
- 'systemctl status kubelet'
- 'journalctl -xeu kubelet'
timed out waiting for the condition
遇到这个问题说明没有正确执行apt-get install步骤,或者通过手动方式打乱正确的执行计划,没有正确启动kubelet所致。
解决方法:
cd /etc/systemd/system/
vim kubelet.service
在kubelet.service文件中添加(作用就是按照这种方式启动kubelet)
[Unit]
Description=Kubelet Server
Documentation=https://kubernetes.io
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --cgroup-driver=cgroupfs --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.1
Restart=on-failure
#ExecStart参数根据自身情况自行更改
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
kubeadm reset
kubeadm join 192.168.137.123:6443 --token hy7q4g.s5osgznm06p3phkk --discovery-token-ca-cert-hash sha256:9e32757e63916b8bd8af575b2d867722816257d38c4e55bcb248c6281e6f7665
基本上就能成功了,也有可能版本错误,可以根据这些思路找原因
问题二:
[ERROR Swap]: running with swap on is not supported. Please disable swap
这情况,swap功能开启,使用 swapoff -a 命令禁用就可
温馨提示:
This error is likely caused by:
- The kubelet is not running
- The kubelet is unhealthy due to a misconfiguration of the node in some way
出现这种错误基本都是kubelet没有正确启动所致,多找下kubelet原因就能解决。