准备
- 至少三台服务器,系统干净防止冲突
- 密码全部相同,方便安装k8s
- 最好是云服务器,方便重装
- 没有特别说明的命令全都在k8s-master
服务器添加ssh访问,能够ssh访问的可以跳过
vi /etc/hosts.allow // 在末尾添加 sshd:ALL
挂载数据盘,已经挂载的可以跳过
fdisk -l
fdisk /dev/vdb
//n->p->1->回车->回车->w
mkfs.ext4 /dev/vdb1
//挂载在 /data目录
mkdir /data
mount /dev/vdb1 /data
df -h
vi /etc/fstab
//打开后,在最后一行加入以下代码;
/dev/vdb1 /data ext4 defaults 0 1
修改主机名
hostnamectl set-hostname k8s-master1
hostnamectl set-hostname k8s-master2
hostnamectl set-hostname k8s-master3
hostnamectl set-hostname k8s-work1
hostnamectl set-hostname k8s-work2
hostnamectl set-hostname k8s-work3
使用sealos部署k8s集群
https://sealyun.com/instructions
# 下载并安装sealos, sealos是个golang的二进制工具,直接下载拷贝到bin目录即可, release页面也可下载
wget -c https://sealyun.oss-cn-beijing.aliyuncs.com/latest/sealos && \
chmod +x sealos && mv sealos /usr/bin
# 下载离线资源包
wget -c https://sealyun.oss-cn-beijing.aliyuncs.com/7b6af025d4884fdd5cd51a674994359c-1.18.0/kube1.18.0.tar.gz
# 安装一个三master的kubernetes集群
sealos init --passwd 123456 \
--master 192.168.0.2 --master 192.168.0.3 --master 192.168.0.4 \
--node 192.168.0.5 \
--pkg-url /root/kube1.18.0.tar.gz \
--version v1.18.0
- 建议使用1.18.6的版本,可以安装kubesphere
- 查看k8s节点情况,全部为ready可以进行下一步
kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master1 Ready master 17h v1.18.6
k8s-master2 Ready master 17h v1.18.6
k8s-master3 Ready master 17h v1.18.6
k8s-work1 Ready <none> 17h v1.18.6
k8s-work2 Ready <none> 17h v1.18.6
k8s-work3 Ready <none> 17h v1.18.6
安装longhorn
yum install -y iscsi-initiator-utils
systemctl enable --now iscsid
kubectl taint nodes --all node-role.kubernetes.io/master-
version=v3.3.1
curl -LO https://repo.huaweicloud.com/helm/${version}/helm-${version}-linux-amd64.tar.gz
tar -zxvf helm-${version}-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm && rm -rf linux-amd64
helm repo add longhorn https://charts.longhorn.io
helm repo update
kubectl create namespace longhorn-system
helm install longhorn \
--namespace longhorn-system \
--set defaultSettings.defaultDataPath="/data/longhorn/" \
--set defaultSettings.defaultReplicaCount=3 \
--set service.ui.type=NodePort \
--set service.ui.nodePort=30890 \
longhorn/longhorn
helm -n longhorn-system ls
kubectl -n longhorn-system get pods
安装kubesphere
https://github.com/kubesphere/ks-installer/releases/download/v3.0.0/kubesphere-installer.yaml
https://github.com/kubesphere/ks-installer/releases/download/v3.0.0/cluster-configuration.yaml
kubectl apply -f kubesphere-installer.yaml
kubectl apply -f cluster-configuration.yaml
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
kubesphere
kubectl get pods -A | grep kubesphere
admin/P@88w0rd
kubectl -n kubesphere-system describe po etcd-65796969c7-bcdzw