附034.Kubernetes_v1.21.0高可用部署架构二 (10)

本实验采用ingress所暴露的域名:https://web.odocker.com
方式一:token访问
可使用kubectl describe secret -n kubernetes-dashboard ${ADMIN_SECRET} | grep -E '^token' | awk '{print $2}'所获取的token访问。

011

方式二:kubeconfig访问
local-ngkeconk8s-1-21-admin.kubeconfig文件访问。

012

提示:
更多dashboard访问方式及认证可参考附004.Kubernetes Dashboard简介及使用。
dashboard登录整个流程可参考:https://www.cnadn.net/post/2613.html

Longhorn存储部署 Longhorn概述

Longhorn是用于Kubernetes的开源分布式块存储系统。
提示:更多介绍参考:https://github.com/longhorn/longhorn。

基础软件安装 [root@master01 ~]# source environment.sh [root@master01 ~]# for all_ip in ${ALL_IPS[@]} do echo ">>> ${all_ip}" ssh root@${all_ip} "yum -y install iscsi-initiator-utils &" done

提示:所有节点都需要安装。

设置标签 [root@master01 ~]# kubectl label nodes master0{1,2,3} longhorn-ui=enabled

提示:ui图形界面可复用master高可用,因此部署在master节点。

准备磁盘

默认longhorn使用/var/lib/longhorn/作为设备路径,因此建议提前挂载。

[root@master01 ~]# source environment.sh [root@master01 ~]# for node_ip in ${NODE_IPS[@]} do echo ">>> ${node_ip}" ssh root@${node_ip} "mkfs.xfs -f /dev/sdb && mkdir -p /var/lib/longhorn/ && echo '/dev/sdb /var/lib/longhorn xfs defaults 0 0' >> /etc/fstab && mount -a" done 配置Longhorn [root@master01 ~]# mkdir longhorn [root@master01 ~]# cd longhorn/ [root@master01 longhorn]# wget \ https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml [root@master01 longhorn]# vi longhorn.yaml …… --- apiVersion: apps/v1 kind: DaemonSet metadata: labels: app: longhorn-manager name: longhorn-manager …… imagePullPolicy: IfNotPresent …… --- apiVersion: apps/v1 kind: Deployment metadata: labels: app: longhorn-ui name: longhorn-ui …… nodeSelector: longhorn-ui: enabled #追加标签选择 tolerations: - key: node-role.kubernetes.io/master #添加容忍 effect: NoSchedule # imagePullSecrets: # - name: …… --- kind: Service apiVersion: v1 metadata: labels: app: longhorn-ui name: longhorn-frontend namespace: longhorn-system spec: type: NodePort #修改为nodeport selector: app: longhorn-ui ports: - port: 80 targetPort: 8000 nodePort: 30002 --- …… [root@master01 longhorn]# kubectl apply -f longhorn.yaml [root@master01 longhorn]# kubectl -n longhorn-system get pods -o wide

013

提示:若部署异常可删除重建,若出现无法删除namespace,可通过如下操作进行删除:

wget https://github.com/longhorn/longhorn/blob/master/uninstall/uninstall.yaml rm -rf /var/lib/longhorn/ kubectl apple -f uninstall.yaml kubectl delete -f uninstall.yaml 动态sc创建

提示:默认longhorn部署完成已创建一个sc,也可通过如下手动编写yaml创建。

[root@master01 longhorn]# kubectl get sc NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE …… longhorn driver.longhorn.io Delete Immediate true 15m [root@master01 longhorn]# cat <<EOF > longhornsc.yaml kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: longhornsc provisioner: rancher.io/longhorn parameters: numberOfReplicas: "3" staleReplicaTimeout: "30" fromBackup: "" EOF

[root@master01 longhorn]# kubectl apply -f longhornsc.yaml

测试PV及PVC [root@master01 longhorn]# cat <<EOF > longhornpod.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: longhorn-pvc spec: accessModes: - ReadWriteOnce storageClassName: longhorn resources: requests: storage: 500Mi --- apiVersion: v1 kind: Pod metadata: name: longhorn-pod namespace: default spec: containers: - name: volume-test image: nginx:stable-alpine imagePullPolicy: IfNotPresent volumeMounts: - name: volv mountPath: /data ports: - containerPort: 80 volumes: - name: volv persistentVolumeClaim: claimName: longhorn-pvc EOF [root@master01 longhorn]# kubectl apply -f longhornpod.yaml [root@master01 longhorn]# kubectl get pods [root@master01 longhorn]# kubectl get pvc [root@master01 longhorn]# kubectl get pv

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpzfyz.html