其他分享
首页 > 其他分享> > k8s存储管理

k8s存储管理

作者:互联网

存储管理 一.nfs搭建 yum install infs-utils -y rpcbind mkdir -p /data/k8s-volume chmod 755 /data/k8s-volume cat >>/etc/exports <<EOF /data/k8s-volume *(rw,no_root_squash,sync) EOF   二.注意需要在客户端安装nfs,才能正常   三.我们需要配置nfs-client的Deployment文件
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:
        - name: nfs-client-provisioner
          image: quay.io/external_storage/nfs-client-provisioner:latest
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: fuseim.pri/ifs
            - name: NFS_SERVER
              value: 10.206.16.4           #nfs server 地址
            - name: NFS_PATH
              value: /data/k8s-volume     #nfs共享目录
      volumes:
        - name: nfs-client-root
          nfs:
            server: 10.206.16.4
            path: /data/k8s-volume
四.创建serviceAccount
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
五.声明storageclass对象
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-nfs-storage
provisioner: fuseim.pri/ifs # or choose another name, must match deployment's env PROVISIONER_NAME'
六.创建对象 kubectl apply -f .   七.pvc申请存储
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: test-claim
  annotations:
    volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"    #storageclass 名称
spec:
  accessModes:              #访问模式
    - ReadWriteMany
  resources:
    requests:
      storage: 1024Mi              #请求
八.查看效果
[root@k8s-master-01 dynamic]# kubectl get pvc|grep test
test-claim   Bound    pvc-d2719003-188b-4d1e-a212-db0b35435630   1Gi        RWX            managed-nfs-storage   14m
[root@k8s-master-01 dynamic]# kubectl get pv|grep test
pvc-d2719003-188b-4d1e-a212-db0b35435630   1Gi        RWX            Delete           Bound    default/test-claim   managed-nfs-storage            12m


标签:存储管理,name,storage,client,nfs,provisioner,k8s
来源: https://blog.51cto.com/luoguoling/2966225