安装k8s-v1.28.0
k8s 从1.24之后移除了dokcer直接支持,安装方式与1.24.0以前有不一样的地方
-
下载安装文件
# 三个主文件
wget qq829.cn/uploads/software/k8s/v1.28.14/kubectl
wget qq829.cn/uploads/software/k8s/v1.28.14/kubelet
wget qq829.cn/uploads/software/k8s/v1.28.14/kubeadm
# docker-compose
wget qq829.cn/uploads/software/k8s/docker-compose
# 两个插件
# https://github.com/Mirantis/cri-dockerd
wget qq829.cn/uploads/software/k8s/v1.28.14/cri-dockerd-0.3.4-3.el7.x86_64.rpm
# https://github.com/kubernetes-sigs/cri-tools
wget qq829.cn/uploads/software/k8s/v1.28.14/crictl-v1.28.0-linux-amd64.tar.gz
# 服务配置文件
wget qq829.cn/uploads/software/k8s/v1.28.14/10-kubeadm.conf
wget qq829.cn/uploads/software/k8s/v1.28.14/kubelet.service
# 网络插件
wget qq829.cn/uploads/software/k8s/v1.28.14/calico.yaml
# 网络插件加速
wget qq829.cn/uploads/software/k8s/v1.28.14/calico-image-vp-whdev.yaml
# nginx-ingress
wget qq829.cn/uploads/software/k8s/v1.28.14/nginx-ingress.yaml
# traefik-ingress
wget qq829.cn/uploads/software/k8s/v1.28.14/traefik-ingress.tar
# nfs-storage
wget qq829.cn/uploads/software/k8s/v1.28.14/nfs-storage.tar
# 安装 socat conntrack 依赖软件
yum install -y socat
yum install -y conntrack
# 复制三个主文件到目录
cp kubectl kubelet kubeadm /usr/local/bin/
# 安装插件
yum install cri-dockerd-0.3.4-3.el7.x86_64.rpm
# 修改cri-docker服务配置
# vi /usr/lib/systemd/system/cri-docker.service
# 修改cri-docker配置文件,在后面增加参数,告诉告诉docker使用 pause镜像与版本
# --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.9
# 开启服务
systemctl enable cri-docker
systemctl restart cri-docker
# 复制crictl到目录
tar -xvzf crictl-v1.28.0-linux-amd64.tar.gz
cp crictl /usr/local/bin
# 修改crictl配置文件(非必须)
# 因为crictl是一个统一的容器管理工具,管理多种容器,不修改如下配置也没事,只是看到一堆错误提示不友好
# vi /etc/crictl.yaml
# runtime-endpoint: unix:///var/run/cri-dockerd.sock
# 或者
echo "runtime-endpoint: unix:///var/run/cri-dockerd.sock" >> /etc/crictl.yaml
# 安装kubelet服务,开启服务自启动
# 需要注意 服务文件里面的执行路径,
cp kubelet.service /usr/lib/systemd/system/kubelet.service
mkdir -p /etc/systemd/system/kubelet.service.d
cp 10-kubeadm.conf /etc/systemd/system/kubelet.service.d
# 安装docker,修改docke运行方式
vi /etc/docker/daemon.json
{
"graph":"/data/docker",
"exec-opts": ["native.cgroupdriver=systemd"]
}
# 设置kubelet 开机启动服务
# 此时会显示一堆错误,这是正常的
systemctl enable kubelet.service
systemctl status kubelet
-
使用keepalived方式高可用(推荐,独立可靠):
docker-keepalived:https://qq829.cn/book/books/k8s/page/docker-keepalived -
使用KUBE-VIP方式高可用(不推荐,简单易用)
kube-vip:https://qq829.cn/book/books/k8s/page/kube-vipk8s
# 部署KUBE-VIP 便于后期扩展,如果不想部署KUBE-VIP,可以直接使用主机名,强烈建议使用kube-api-server作为master主机名
docker run --network host --rm swr.cn-south-1.myhuaweicloud.com/vp-whdev/all-in-devops/kube-vip:v0.6.0 manifest pod --interface=eth0 --vip 192.168.0.200 --controlplane --services --arp --leaderElection | tee /etc/kubernetes/manifests/kube-vip.yaml
-
安装
# 初始化集群
kubeadm init --control-plane-endpoint "kube-api-server:6443" --image-repository registry.aliyuncs.com/google_containers --upload-certs --kubernetes-version v1.28.14 --pod-network-cidr 10.244.0.0/16 --service-cidr=10.96.0.0/12 --cri-socket unix:///var/run/cri-dockerd.sock --v 5
# 如果服务器有多张网卡,kubeadm自动侦测的网卡地址不正确,需要加入参数
--apiserver-advertise-address 192.168.5.10
# 重新打印其他master加入命令
# 需要手工在后面加入 --cri-socket unix:///var/run/cri-dockerd.sock --v 5
echo "$(kubeadm token create --print-join-command) --control-plane --certificate-key $(kubeadm init phase upload-certs --upload-certs | tail -1)"
# 重新打印节点加入命令
# 需要手工在后面加入 --cri-socket unix:///var/run/cri-dockerd.sock --v 5
kubeadm token create --print-join-command
# 重置集群
kubeadm reset --cri-socket unix:///var/run/cri-dockerd.sock
# 安装网络插件
kubectl apply -f calico.yaml
# 修改为ipvs模式
# 40行,mode:"ipvs"
kubectl edit cm -n kube-system kube-proxy
安装ingress-controller
推荐选择nginx-ingress
# 安装nginx-ingress
kubectl apply -f nginx-ingress.yaml
# 安装traefik-ingress
kubeclt apply -f 00-account.yaml -n kube-system \
-f 01-role.yaml -n kube-system \
-f 02-role-binding.yaml -n kube-system \
-f 03-traefik.yaml -n kube-system \
-f 04-traefik-services.yaml -n kube-system \
-f 05-traefik-default-tls.yaml -n kube-system
让pod运行在每一台机器不受污点限制
# 加在与volumes同级
tolerations:
- effect: NoSchedule
operator: Exists
- key: CriticalAddonsOnly
operator: Exists
- effect: NoExecute
operator: Exists