K8S-1.23.17+Ceph+KubeSphere 一主二从部署攻略

K8S部署攻略

 

此教程以一主二从为例,需要三台服务器。

主机最低需求: 4 核 CPU,4 GB 内存,硬盘:20 GBx2 (需保留一个未分区的磁盘)

从机最低需求: 4 核 CPU,8 GB 内存,硬盘:20 GBx2 (需保留一个未分区的磁盘)

 

软件版本:

Ubuntu22.04

Kubesphere:3.4.1

Docker20.10.24

K8s1.23.17

Rook:1.13.6

 

1. 配置Cgroup驱动

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "registry-mirrors": [
    "https://hub-mirror.c.163.com/",
    "https://dockerproxy.com/"
  ]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

 

2. 配置docker存储库,安装docker-ce

sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get -y update
sudo apt-get -y install docker-ce=5:20.10.24~3-0~ubuntu-jammy
sudo systemctl enable docker && sudo systemctl start docker

 

3. 关闭交换分区

sudo swapoff -a
sudo vi /etc/fstab

注释掉swap行并保存

 

4. 允许 iptables 检查桥接流量

sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system

 

5. 安装 kubeadm、kubelet 和 kubectl

sudo apt-get update && sudo apt-get install -y apt-transport-https
sudo curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add - 
sudo tee /etc/apt/sources.list.d/kubernetes.list <<-'EOF'
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet=1.23.17-00 kubeadm=1.23.17-00 kubectl=1.23.17-00
sudo systemctl enable kubelet && sudo systemctl start kubelet

 

6. 初始化控制平面节点(仅主节点执行)

sudo kubeadm init \
 --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers \
 --kubernetes-version v1.23.17 \
 --pod-network-cidr=10.244.0.0/16

出现如下信息表示初始化成功,将token(图中最后两行)复制保存,后面会用到,token有效期为24小时

执行命令:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

 

7. 安装 Pod 网络附加组件(仅主节点执行,方式二选一)

方式一:

下载文件:https://files.cnblogs.com/files/blogs/785788/kube-flannel.zip?t=1710498095&download=true

解压上传kube-flannel.yml文件至主节点用户根目录下,执行:

sudo kubectl apply -f kube-flannel.yml

方式二:

sudo kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

执行命令查看安装是否完成

watch kubectl get pod -n kube-system -o wide

输出中检查 CoreDNS Pod 的STATUS直到变成 Running 表示完成(需要几分钟)

 

8. 配置hosts

sudo vi /etc/hosts

配置示例:

192.168.1.100 k8s1
192.168.1.101 k8s2
192.168.1.102 k8s3

 

9. 从节点加入主节点

在从节点执行步骤六保存的token,注意非root用户前面加上sudo

sudo kubeadm join 192.168.1.100:6443 --token **** \
--discovery-token-ca-cert-hash sha256:****

成功输出:

失败可以关闭防火墙后重试:

sudo systemctl stop firewalld
sudo systemctl disable firewalld

完毕后,执行kubectl get nodes查看,等待所有节点状态变成Ready(需要几分钟)

 

10. 删除污点(仅主节点执行)

kubectl taint nodes <主节点名,比如k8s1> node-role.kubernetes.io/master:NoSchedule

 

11. 安装Rook-CephFS(仅主节点执行,方式二选一)

方式一:

下载文件:https://files.cnblogs.com/files/blogs/785788/rook-1.13.6.zip?t=1710498602&download=true

解压后把rook整个文件夹,上传到主节点用户根目录。

方式二:

git clone --single-branch --branch v1.13.7 https://github.com/rook/rook.git


执行命令:

cd /rook/deploy/examples
kubectl create -f crds.yaml -f common.yaml -f operator.yaml
kubectl create -f cluster.yaml

待安装完成(需要十分钟左右),使用 kubectl get pods -n rook-ceph 来确认安装进度,除 rook-ceph-osd-prepare-*** 以外,其他都要为Runing

 

12. 创建默认StorageClass,恢复污点(仅主节点执行)

cd /rook/deploy/examples
kubectl create -f filesystem.yaml
kubectl create -f csi/cephfs/storageclass.yaml
Kubectl patch storageclass rook-cephfs -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
kubectl taint nodes <主节点名,比如k8s1> node-role.kubernetes.io=master:NoSchedule

使用:kubectl get sc确认是否成功。

 

13. 安装KubeSphere(仅主节点执行)

kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/kubesphere-installer.yaml
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/cluster-configuration.yaml

查看安装进度:

kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f

成功输出:

完结撒花!

附件:k8s部署攻略.doc

热门相关:陷阱   史泰龙的传奇   冷血动物   她热辣的秘密   美漫大幻想