k8s使用nfs-client-provisioner做storageclass

镜像下载与私仓上传

docker pull docker.io/lhcre/nfs-client-provisioner
docker tag docker.io/lhcre/nfs-client-provisioner 172.16.15.250/nfs-client-provisioner
docker push 172.16.15.250/nfs-client-provisioner

权限控制 nfs-rbac.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner-one
  namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-one-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: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-client-provisioner-one
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner-one
    namespace: default
roleRef:
  kind: ClusterRole
  name: nfs-client-provisioner-one-runner
  apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner-one
  # replace with namespace where provisioner is deployed
  namespace: default
rules:
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner-one
  # replace with namespace where provisioner is deployed
  namespace: defaultl
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner-one
    # replace with namespace where provisioner is deployed
    namespace: default
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner-one
  apiGroup: rbac.authorization.k8s.io

nfs-provisioner部署文件 nfs-provisioner.yaml
!!!配置nfs服务器地址和共享的出来的路径

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner-one
  labels:
    app: nfs-client-provisioner-one
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client-provisioner-one
  template:
    metadata:
      labels:
        app: nfs-client-provisioner-one
    spec:
      serviceAccountName: nfs-client-provisioner-one
      containers:
        - name: nfs-client-provisioner-one
          #!!!修改值---镜像
          image: 172.16.15.250/nfs-client-provisioner
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              #!!!修改值---后续创建storageclass时需要用到该参数
              value: nfsone
            - name: NFS_SERVER
              #!!!修改值---nfs服务器地址
              value: 172.16.15.121
            - name: NFS_PATH
              #!!!修改值---nfs共享出来的路径
              value: /data-nfs
      volumes:
        - name: nfs-client-root
          nfs:
            #!!!修改值---nfs服务器地址
            server: 172.16.15.121
            #!!!修改值---nfs共享出来的路径
            path: /data-nfs

部署

kubectl apply -f nfs-provisioner.yaml -n nfs

部署storageclass—nfs-storageclass.yaml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  #创建PVC时会用到的参数
  name: nfs-one
  labels:
    uds.dce.daocloud.io/storage-type: file   #dce平台需要
    uds.dce.daocloud.io/namespaces: '*'    #dce平台需要
  annotations:
   # 设置该storageclass为PVC创建时默认使用的存储机制;如果不设置该参数,PVC想要使用该storageclass时需要指定 storageclassname
    storageclass.kubernetes.io/is-default-class: "true" 
#!!!修改值---匹配deployment中的环境变量'PROVISIONER_NAME'
provisioner: nfsone
parameters:
  archiveOnDelete: "true" # "false" 删除PVC时不会保留数据,"true"将保留PVC数据
reclaimPolicy: Retain

部署
kubectl apply -f nfs-storageclass.yaml -n nfs

pvc使用该storageclass

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: hello-pvc
spec:
  storageClassName: nfs-one
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

5、查看是否绑定

kubectl get pvc 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值