Docker&Kubernetes

Centos7 搭建k8s集群

2020-11-24  本文已影响0人  楚长铭

准备

服务器添加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 
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
上一篇下一篇

猜你喜欢

热点阅读