Kubernetes的不同版本,需要安装什么版本的docker,可以通过github上K8s源码,找到CHANGCH.中,找到所需的不同的docker版本
所有节点都需要安装
【基本组件】
安装docker
python
# 安装docker
yum install docker-ce -y
#如果提示containerd(管理系统容器生命周期)自动安装失败,需要手动安装后,再执行docker命令:
wget https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6--3.3.el7.x86_64.rpm
yum -y install containerd.io-1.2.6--3.3.el7.x86_64.rpm
安装kubeadm
python
# 查看版本相应版本信息
yum list kubeadm.x86_64 --showduplicates | sort -r
# 安装kubeadm
yum install kubeadm -y
python
# 设置开机启动docker
systemctl enable --now docker
# 执行该命令,需要没有警报,有的话,必须提前解决掉
docker info
安装kubelet
python
#更改为国内镜像源
cat >/etc/sysconfig/kubelet<<EOF
KUBELET_EXTRA_ARGS="--cgroup-driver=$DOCKER_CGROPS --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.1"
EOF
# 设置开机自启动
systemctl daemon -reload
systemctl enable --now kubelet
【高可用组件】
1、需要在3台Moster节点安装。
安装KeepAlived 和HAProxy
python
# 直接安装命令,完成后,下面导入配置文件
yum install keepalived haproxy -y
# 所有Master节点配置HAProxy。
mkdir /etc/haproxy
vim /etc/haproxy/haproxy.cfg
python
globale
maxeenn 2000
ulimit-n l6384
log 127.0.0.1 local0 err
stats timeout 30s
defaults
log globale
mode http
optian httplog
timeout connect 5000
timeout client 50000
timeout server 50000
timeout http-reguest 15s
timeout http-keep-alive 15s
frontend monitor-in
bind *:33305
mode http
option httplog
monitor-uri monitor
listen stats
bind *:8006
mode http
stats enable
stats hide-version
stats uri /stats
stats refresh 30s
stats realm Haproxy\ Statistics
stats auth admin:admin
frontend k8s-master
bind 0.0.0.0:16443
bind 127.0.0.1:16443
mode tcp
option tcplog
tcp-request inspect-delay 5s
default_backend k8s-master
backend k8s-master
mode tcp
option tcplog
option tcp-check
balance roundrobin
default-server inter 10s downinter 5s rise 2 fall slowstart 60s maxconn 250 maxqueue 256 weight 100
server k8s-master01 192.18.0.100:6443 check
server k8s-master02 192.18.0.106:6443 check
server k8s-master03 192.18.0.107:6443 check
2、Master01/Master02/Master03节点配置keepalived (注意仅仅节点ip和网卡不同,其他均一致)
python
mkdir /etc/keepalived
vim /etc/keepalived/keepalived.conf
python
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_script chk_apiserver{
script "/etc/keepalived/check_apiserver.sh"
interval 2
weight -5
fall 3
rise 2
}
vrrp_instance VI_1 {
state MASTER
interrface ens33 # 此处各个master放自己的网卡
mcast_stc_ip 192.168.0.100 # 此处各个master放自己的ip
virtual_router_id 51
priority 100
advert_int 2
authentication {
auth_type PASS
auth_pass K8SHA_KA_AUTH
}
virtual_ipaddress {
192.168.0.200
}
# 健康检测在集群部署后,再开启
# track_script {
# chk_apiserver
# }
}
配置KeepAlived健康检测文件:'cat /etc/keepalived/check_apiserver.sh' 。检测apiserver接口是否存活
python
#!/bin/bash
err=0
for k in $(seq 1 5)
do
check_code=$(pqrep kube-apiserver)
if [[ $check_code == " " ]]; then
err=$(expr $err + 1)
sleep 5
continue
else
err=0
break
fi
done
if [[ $err != "0" ]]; then
echo "systemctl stop keepalived"
/usr/bin/systemctl stop keepalived
exit 1
else
exit 0
fi
启动 KeepAlived 和HAProxy
python
systemctl enable --now haproxy
systemctl enable --now keepalived