附031.Kubernetes_v1.20.4高可用部署架构二 (8)

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

Longhorn存储部署 Longhorn概述

Longhorn是用于Kubernetes的开源分布式块存储系统。
提示:更多介绍参考:https://github.com/longhorn/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 ~]# 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 #…… --- 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 --- …… kind: DaemonSet …… imagePullPolicy: IfNotPresent …… #…… [root@master01 longhorn]# kubectl apply -f longhorn.yaml [root@master01 longhorn]# kubectl -n longhorn-system get pods -o wide

010

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

wget https://github.com/longhorn/longhorn/blob/master/uninstall/uninstall.yaml rm -rf /var/lib/longhorn/ kubectl delete -f uninstall.yaml kubectl delete -f longhorn.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]# vi longhornsc.yaml kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: longhornsc provisioner: rancher.io/longhorn parameters: numberOfReplicas: "3" staleReplicaTimeout: "30" fromBackup: ""

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

测试PV及PVC [root@master01 longhorn]# vi longhornpod.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: longhorn-pvc spec: accessModes: - ReadWriteOnce storageClassName: longhorn resources: requests: storage: 2Gi --- 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 [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

014

Ingress暴露Longhorn [root@master01 longhorn]# yum -y install httpd-tools [root@master01 longhorn]# htpasswd -c auth xhy #创建用户名和密码

提示:也可通过如下命令创建:

USER=xhy; PASSWORD=x120952576; echo "${USER}:$(openssl passwd -stdin -apr1 <<< ${PASSWORD})" >> auth [root@master01 longhorn]# kubectl -n longhorn-system create secret generic longhorn-basic-auth --from-file=auth [root@master01 longhorn]# vi longhorn-ingress.yaml #创建ingress规则 apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: longhorn-ingress namespace: longhorn-system annotations: nginx.ingress.kubernetes.io/auth-type: basic nginx.ingress.kubernetes.io/auth-secret: longhorn-basic-auth nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required ' spec: rules: - host: longhorn.odocker.com http: paths: - path: / pathType: Prefix backend: service: name: longhorn-frontend port: number: 80 [root@master01 longhorn]# kubectl apply -f longhorn-ingress.yaml [root@master01 longhorn]# kubectl -n longhorn-system get ingress NAME CLASS HOSTS ADDRESS PORTS AGE longhorn-ingress <none> longhorn.odocker.com 172.16.10.21,172.16.10.22,172.16.10.23 80 45s 确认验证

浏览器访问:longhorn.odocker.com,并输入账号和密码。

011

登录查看。

012

Helm部署

参考053.集群管理-Helm工具

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

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