一、准备三台虚拟机
1 master最低2核
2 设置hostname
hostnamectl set-hostname master
hostnamectl set-hostname node1
hostnamectl set-hostname node2
3 关闭一些服务
关闭防火墙: systemctl disable firewalld
关闭selinux: sed -i 's/enforcing/disabled/' /etc/selinux/config (临时关闭 setenforce 0)
关闭swap: sed -ri 's/.*swap.*/#&/' /etc/fstab (临时关闭swapoff -a)
4 将桥接的IPv4流量传递到iptables的链
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
5 时间同步
yum install ntpdate -y
ntpdate time.windows.com
6 sysctl --system
7 安装docker
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce-18.06.1.ce-3.el7
systemctl enable docker && systemctl start docker
如果安装docker失败,建议更换源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
8 安装依赖
yum install -y socat conntrack ebtables ipset
二、安装
1、下载KubeKey
wget https://github.com/kubesphere/kubekey/releases/download/v1.2.0-alpha.2/kubekey-v1.2.0-alpha.2-linux-amd64.tar.gz
tar -zxvf kubekey-v1.2.0-alpha.2-linux-amd64.tar.gz
mv kk /usr/local/bin/
查看支持的版本:kk version --show-supported-k8s
2、创建集群配置yaml文件
./kk create config --with-kubernetes v1.20.4 --with-kubesphere v3.1.1
3、修改yaml
四、创建集群
kk create cluster -f config-sample.yaml
访问日志打印的地址,输入用户名密码
安装完成,最好设置开机启动 systemctl enable kubelet
五 kubekey集群维护
1、添加节点
kk add nodes -f config-sample.yaml
2、 删除节点
kk delete node
3、删除集群
kk delete cluster
kk delete cluster [-f config-sample.yaml]
4、集群升级
kk upgrade [--with-kubernetes version] [--with-kubesphere version]
kk upgrade [--with-kubernetes version] [--with-kubesphere version] [(-f | --file) path]