准备服务器

3台Linux主机,2核4G,50G硬盘

内网IP(可互相ssh)hostname
10.206.0.17master
10.206.0.12node1
10.206.0.16node2

初始化安装环境

systemctl stop firewalld
systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config 
sed -ri 's/.*swap.*/#&/' /etc/fstab
cat > /etc/sysctl.d/k8s.conf << EOF 
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1 
EOF
sysctl --system
yum install ntpdate -y
ntpdate time.windows.com

安装依赖

更新yum源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
yum update -y

#查看当前yum源
yum repolist

安装依赖

yum install -y socat
yum install -y conntrack

配置阿里镜像加速

设置仓库地址:https://help.aliyun.com/docum...

cat > /etc/docker/daemon.json << EOF
{ 
  "registry-mirrors": ["https://xxx.mirror.aliyuncs.com"] 
}
EOF

添加阿里源

cat > /etc/yum.repos.d/kubernetes.repo << EOF 
[kubernetes] 
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 
enabled=1 
gpgcheck=0 
epo_gpgcheck=0 
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg 
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg 
EOF

多节点安装

拉取KubeKey

export KKZONE=cn

curl -sfL https://get-kk.kubesphere.io | VERSION=v1.1.1 sh -

chmod +x kk

创建配置文件

./kk create config --with-kubernetes v1.20.4 --with-kubesphere v3.1.1

编辑配置文件

apiVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: master, address: 10.206.0.17, internalAddress: 10.206.0.17, user: root, password: 123456}
  - {name: node1, address: 10.206.0.12, internalAddress: 10.206.0.12, user: root, password: 123456}
  - {name: node2, address: 10.206.0.16, internalAddress: 10.206.0.16, user: root, password: 123456}
  roleGroups:
    etcd:
    - master
    master:
    - master
    worker:
    - node1
    - node2

开始安装

./kk create cluster -f config-sample.yaml

安装完成
image.png

常见问题

1.服务器重启后kubelet无法启动

kubectl get nodes

The connection to the server lb.kubesphere.local:6443 was refused - did you specify the right host or port?

查看日志

journalctl  -xefu kubelet

#异常信息
Aug 28 14:36:33 VM-0-17-centos kubelet[9055]: F0828 14:36:33.316089    9055 server.go:265] failed to run Kubelet: misconfiguration: kubelet cgroup driver: "systemd" is different from docker cgroup driver: "cgroupfs"

解决方法:

vim /var/lib/kubelet/config.yaml

#修改配置
cgroupDriver: cgroupfs

2.服务器重启后节点异常

原因:hostname失效
解决:

hostnamectl set-hostname master
hostnamectl set-hostname node1
hostnamectl set-hostname node2

参考文档

  1. 多节点安装KubeSphere
  2. CentOS7 yum源修改为阿里,配置阿里epel源

IT小马
1.2k 声望166 粉丝

Php - Go - Vue - 云原生


引用和评论

0 条评论