kubernetes 基于 StorageClass 的 NFS 动态卷

参考链接:
https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client
https://jicki.me/2017/10/18/nfs-storageclass/
http://dockone.io/article/2598
https://jicki.me/2017/10/18/nfs-storageclass/
http://blog.csdn.net/idea77/article/details/72842723

serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  namespace: fabric8
deployment.yaml
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: nfs-client-provisioner
  namespace: fabric8
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccount: 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: shiwaixiangcun.cn/nfs
            - name: NFS_SERVER
              value: 172.18.xxx.xxx
            - name: NFS_PATH
              value: /localmnt/storage
      volumes:
        - name: nfs-client-root
          nfs:
            server: 172.18.xxx.xxx
            path: /localmnt/storage
clusterrolebinding.yaml
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1alpha1
metadata:
  name: run-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    namespace: fabric8
roleRef:
  kind: ClusterRole
  name: nfs-client-provisioner-runner
  apiGroup: rbac.authorization.k8s.io
clusterrole.yaml
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1alpha1
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"]
storageclass.yaml
apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
  name: standard
provisioner: shiwaixiangcun.cn/nfs # or choose another name, must match deployment's env PROVISIONER_NAME'

至此配置完成。


配置一个pod 来测试一下

test-claim.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: test-claim
  namespace: fabric8
  annotations:
    volume.beta.kubernetes.io/storage-class: "standard"
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Mi
test-pod.yaml
kind: Pod
apiVersion: v1
metadata:
  name: test-pod
  namespace: fabric8
spec:
  containers:
  - name: test-pod
    image: busybox
    command:
      - "/bin/sh"
    args:
      - "-c"
      - "touch /mnt/SUCCESS && exit 0 || exit 1"
    volumeMounts:
      - name: nfs-pvc
        mountPath: "/mnt"
  restartPolicy: "Never"
  volumes:
    - name: nfs-pvc
      persistentVolumeClaim:
        claimName: test-claim

你可能感兴趣的:(kubernetes 基于 StorageClass 的 NFS 动态卷)