【Kubernetes】安装集群用到的组件

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
相关推荐
_秋牧1 分钟前
Docker 镜像导出和导入
运维·docker·容器
Xiao2000010121 分钟前
一文讲解Docker入门到精通
运维·docker·容器
软泡芙44 分钟前
【Docker】可视化平台Portainer
运维·docker·容器
月清晖1 小时前
使用docker搭建squid和ss5
运维·docker·容器
dami_king1 小时前
新手怎么使用GitLab?
运维·git·svn·云原生·gitlab·github
阿维同学1 小时前
今天不看明天付费------中国AGI(人工智能)的发展趋势
汇编·人工智能·ai·云原生·开源·agi
Studying_swz2 小时前
利用Frp实现内网穿透(docker实现)
运维·docker·容器
Freecode#2 小时前
🚀 Karpor - 让 AI 全面赋能 Kubernetes!
kubernetes·go·opensource·cloudnative
咖猫3 小时前
配置下载 docker镜像 playedu开源 最佳实践部署
运维·docker·容器
江湖有缘4 小时前
云原生之使用Docker部署RabbitMQ消息中间件
docker·云原生·rabbitmq