準(zhǔn)備
- 至少三臺(tái)服務(wù)器,系統(tǒng)干凈防止沖突
- 密碼全部相同寄狼,方便安裝k8s
- 最好是云服務(wù)器枫振,方便重裝
- 沒(méi)有特別說(shuō)明的命令全都在k8s-master
服務(wù)器添加ssh訪問(wèn),能夠ssh訪問(wèn)的可以跳過(guò)
vi /etc/hosts.allow // 在末尾添加 sshd:ALL
掛載數(shù)據(jù)盤(pán)蒋纬,已經(jīng)掛載的可以跳過(guò)
- 查看掛載猎荠,數(shù)據(jù)盤(pán)一般是/dev/vdb
fdisk -l
fdisk /dev/vdb
//n->p->1->回車(chē)->回車(chē)->w
mkfs.ext4 /dev/vdb1
//掛載在 /data目錄
mkdir /data
mount /dev/vdb1 /data
df -h
vi /etc/fstab
//打開(kāi)后,在最后一行加入以下代碼蜀备;
/dev/vdb1 /data ext4 defaults 0 1
修改主機(jī)名
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集群
- 文檔地址,以下關(guān)于sealos說(shuō)明來(lái)自該文檔中
https://sealyun.com/instructions
# 下載并安裝sealos, sealos是個(gè)golang的二進(jìn)制工具关摇,直接下載拷貝到bin目錄即可, release頁(yè)面也可下載
wget -c https://sealyun.oss-cn-beijing.aliyuncs.com/latest/sealos && \
chmod +x sealos && mv sealos /usr/bin
# 下載離線(xiàn)資源包
wget -c https://sealyun.oss-cn-beijing.aliyuncs.com/7b6af025d4884fdd5cd51a674994359c-1.18.0/kube1.18.0.tar.gz
# 安裝一個(gè)三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節(jié)點(diǎn)情況,全部為ready可以進(jìn)行下一步
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
- 去除master節(jié)點(diǎn)的污點(diǎn)碾阁,讓其能夠調(diào)度pod
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