华为云云原生训练营学习(二)在鲲鹏的k8s部署NFS

网友投稿 957 2022-05-28

学习k8s存储架构原理后,对持久化存储和PV/PVC的工作原理有了更深入的了解。部署cephfs条件需要3个以上的node节点和每个节点都必须有3个以上的硬盘才可以。如果部署要另外添加云硬盘,增加学习成本,不划算。之前有部署过glusterfs,但是怕部署glusterfs会跟华为的MRS大数据集群在同时使用时有冲突和抢占资源(特别是存储资源),所以我部署了NFS作为共享存储,避免资源的抢占。

1.1 在mas2安装NFS软件和启动NFS:

yum -y install nfs-utils rpcbind

systemctl start nfs-server rpcbind

systemctl enable nfs-server rpcbind

查看硬盘容量:

df -h

1.2 建立NFS目录

mkdir -p /srv/BigData/k8snfs

cd /srv/BigData/k8snfs

echo wuyicom > index.html

1.3  修改配置

vi /etc/exports

/srv/BigData/k8snfs *(rw,async,no_root_squash)

1.4 重启NFS

systemctl restart nfs-server

exportfs -arv

1.5 客户端测试,所有node节点上要安装nfs客户端

yum -y install nfs-utils rpcbind

systemctl start nfs rpcbind

showmount -e 192.168.0.146

2.手动管理pv和pvc太麻烦了,建议使用StorageClass管理pv和pvc

动态生成pv需要StorageClass和nfs-client-provisioner的共同作用

2.1 创建nfs-client-provisioner

provisione直接使用nfs服务器

查看是否有nfs-client-provisioner镜像

docker search nfs-client-provisioner

docker pull jmgao1983/nfs-client-provisioner

2.2 创建deployment.yaml文件

****

vi deployment.yaml

kind: Deployment

apiVersion: apps/v1

metadata:

name: nfs-client-provisioner

spec:

replicas: 1

selector:

matchLabels:

app: nfs-client-provisioner

strategy:

type: Recreate

template:

metadata:

labels:

app: nfs-client-provisioner

spec:

serviceAccountName: nfs-client-provisioner

containers:

华为云云原生训练营学习(二)在鲲鹏的k8s部署NFS

- name: nfs-client-provisioner

image: jmgao1983/nfs-client-provisioner:latest

volumeMounts:

- name: nfs-client-root

mountPath: /persistentvolumes

env:

- name: PROVISIONER_NAME

value: fuseim.pri/ifs

- name: NFS_SERVER

value: 192.168.0.146

- name: NFS_PATH

value: /srv/BigData/k8snfs

volumes:

- name: nfs-client-root

nfs:

server: 192.168.0.146

path: /srv/BigData/k8snfs

---

apiVersion: v1

kind: ServiceAccount

metadata:

name: nfs-client-provisioner

---

kind: ClusterRole

apiVersion: rbac.authorization.k8s.io/v1

metadata:

name: nfs-client-provisioner-runner

rules:

- apiGroups: [""]

resources: ["persistentvolumes"]

verbs: ["get", "list", "watch", "create", "delete"]

- apiGroups: [""]

resources: ["persistentvolumeclaims"]

verbs: ["get", "list", "watch", "update"]

- apiGroups: ["storage.k8s.io"]

resources: ["storageclasses"]

verbs: ["get", "list", "watch"]

- apiGroups: [""]

resources: ["events"]

verbs: ["list", "watch", "create", "update", "patch"]

- apiGroups: [""]

resources: ["endpoints"]

verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]

---

kind: ClusterRoleBinding

apiVersion: rbac.authorization.k8s.io/v1

metadata:

name: run-nfs-client-provisioner

subjects:

- kind: ServiceAccount

name: nfs-client-provisioner

namespace: default

roleRef:

kind: ClusterRole

name: nfs-client-provisioner-runner

apiGroup: rbac.authorization.k8s.io

*************

kubectl create -f deployment.yaml

查看POD:

kubectl get pod

2.3 创建StorageClass

vi nfsclass.yaml

apiVersion: storage.k8s.io/v1

kind: StorageClass

metadata:

name: course-nfs-storage

provisioner: fuseim.pri/ifs

**************

kubectl create -f nfsclass.yaml

查看storageclass:

kubectl get sc

2.4 在做测试:

vi test2.yaml

apiVersion: apps/v1

kind: StatefulSet

metadata:

name: nfs-web

spec:

serviceName: "nginx"

replicas: 2

selector:

matchLabels:

app: nfs-web

template:

metadata:

labels:

app: nfs-web

spec:

terminationGracePeriodSeconds: 10

containers:

- name: nginx

image: nginx

ports:

- containerPort: 80

name: web

volumeMounts:

- name: www

mountPath: /usr/share/nginx/html

volumeClaimTemplates:

- metadata:

name: www

annotations:

volume.beta.kubernetes.io/storage-class: course-nfs-storage

spec:

accessModes: [ "ReadWriteOnce" ]

resources:

requests:

storage: 1Gi

*********************

kubectl create -f test-pod.yaml

出现下面的问题如图所示:

出现这个问题后后续再解决吧。

云原生 机器学习 鲲鹏

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:数据仓库服务公有云计费介绍
下一篇:Linux 操作系统原理 — 系统启动流程
相关文章