kubeadm安装k8s
- 系统要求
- Master:2core、2GB内存和20GB SSD
- Node:4core、4GB内存和20GB SSD
- 关闭swap
echo "vm.swappiness = 0">> /etc/sysctl.conf
swapoff -a
- 安装客户端版本 k8s version
apt-get remove -y kubelet kubeadm kubectl --allow-change-held-packages
# 阿里云镜像
apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
# chuan
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt install kubeadm=1.23.4-00 kubectl=1.23.4-00 kubelet=1.23.4-00
- 修改主机名
hostname master
hostname node
ubuntu docker repo
kubeadm init --kubernetes-version=v1.23.1 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=100.64.15.213\
--ignore-preflight-errors=swap --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers
健康检查-失败解决方案
# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://v13n36u1.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
网络插件安装
https://projectcalico.docs.tigera.io/getting-started/kubernetes/flannel/flannel
# 注意点就是 --pod-network-cidr=10.244.0.0/16 网络的使用要一致
cd ~ && mkdir flannel && cd flannel
curl -O https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f ~/flannel/kube-flannel.yml
# 另一个插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml
# 国内网络不能下载
docker pull quay.io/coreos/flannel:v0.12.0-amd64
doc
ker tag quay.io/coreos/flannel:v0.12.0-amd64 kube-flannel-ds-amd64-l7x64:latest
清除kubernetes莫名故障
kubeadm reset
systemctl stop docker.socket
systemctl stop kubelet
rm -rf /var/lib/kubelet
rm -rf /var/lib/dockershim
rm -rf /var/run/kubernetes
rm -rf /var/lib/cni
ifconfig cni0 down
ifconfig cni0 flannel.1 down
ip link delete cni0
ip link delete flannel.1
systemctl start docker.socket
systemctl start kubelet
自动化补充 需要在内网下载的进行替换方案
apt-get install -y bash-completion
locate bash_completion /usr/share/bash-completion/bash_completion
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
join node and delete node
- show node list
kubectl get node
- 查看pod分布
kubectl get pods -o wide -name kube-system
- 标记污点node
kubectl drain node_name --delete-local-data --force --ignore-daemonsets
- 清除标记
kubectl uncordon node_name
- 查看当前的标记信息
kubectl get nodes -A
- 删除node
kubectl delete node as09-14-wpr
添加新的node到集群中
- 查看当前系统的node信息
kubectl get node -A
- 生成token信息,生成完整的信息
kubeadm token create --print-join-command
- 在准备好的node执行
kubeadm join 1.1.1.1:6443 --token xiaepe.89kztn0v76yiq9vn --discovery-token-ca-cert-hash sha256:cf87746641508bfebcc670b52439af0d5e6d846f332614fb184a2d3629544f71
kubernetes kubeadm upgrade version of k8s
! 版本升级可以平滑升级但是在降级的时候就不怎么平滑,需要重启机器。
- 查看升级版本
apt-cache policy kubeadm
- 升级kubeadm
apt-mark unhold kubeadm && apt-get update && apt-get install -y kubeadm=1.20.0-00 && apt-mark hold kubeadm
apt-get install -y kubelet=1.19.6-00 kubeadm=1.19.6-00 kubectl=1.19.6-00
apt-get remove -y kubelet=1.20.0-00 kubeadm=1.20.0-00 kubectl=1.20.0-00
apt-get install -y kubelet=1.20.0-00 kubeadm=1.20.0-00 kubectl=1.20.0-00
apt-get install -y kubelet=1.20.1-00 kubeadm=1.20.1-00 kubectl=1.20.1-00
apt-get remove -y kubelet=1.20.1-00 kubeadm kubectl
apt-get install -y kubelet=1.8.6-00 kubeadm=1.8.6-00 kubectl=1.8.6-00
- 查看版本
kubeadm version
- 腾空控制平面节点
kubectl drain node1 --ignore-daemonsets
- 执行升级计划
sudo kubeadm upgrade plan
- 升级依赖组件
# 使用以上提示命令完成升级
Referencedockers
清除master节点的污点
kubectl taint nodes --all node-role.kubernetes.io/master-