rancher / local-path-provisioner

Dynamically provisioning persistent local storage with Kubernetes
Apache License 2.0
2.08k stars 440 forks source link

ZFS example #162

Open killfill opened 3 years ago

killfill commented 3 years ago

Hi all :wave:

Just adding a tip in here, in case it saves a couple of minutes for people wanted to use ZFS with this local-path-provisioner. At least it will for me, when i forget it :grimacing:

kind: ConfigMap
apiVersion: v1
metadata:
  name: local-path-config
  namespace: local-path-storage
data:
  config.json: |-
        {
                "nodePathMap":[
                {
                        "node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
                        "paths":["/tank/"]
                }
                ]
        }
  setup: |-
        #!/bin/sh
        while getopts "m:s:p:" opt
        do
            case $opt in
                p)
                absolutePath=$OPTARG
                ;;
                s)
                sizeInBytes=$OPTARG
                ;;
                m)
                volMode=$OPTARG
                ;;
            esac
        done
        #volMode=Filesystem
        zfs create -o quota=${sizeInBytes} ${absolutePath:1}
  teardown: |-
        #!/bin/sh
        while getopts "m:s:p:" opt
        do
            case $opt in
                p)
                absolutePath=$OPTARG
                ;;
                s)
                sizeInBytes=$OPTARG
                ;;
                m)
                volMode=$OPTARG
                ;;
            esac
        done
        zfs destroy ${absolutePath:1}
  helperPod.yaml: |-
        apiVersion: v1
        kind: Pod
        metadata:
          name: helper-pod
        spec:
          containers:
          - name: helper-pod
            image: srueg/zfs-utils
            securityContext:
              privileged: true
killfill commented 3 years ago

Hm.. ok im sorry. That actually did not work.

When creating or destroying ZFS datasets from a container like the podHelper's one, we need to mount the directory as 'Bidirectional', so the changes can propagate to the Host.

This is maybe related to https://github.com/rancher/local-path-provisioner/issues/165

killfill commented 3 years ago

I guess this can be done enabling the mountPropagation=Bidirectional directly, near here, but that would require the pod helper to run privileged, thus probably would need to be enabled via a flag.

Anyway, another aproach could be something like this?

In case anyone cares, just uploaded a docker image with that change.

With the followin config, ZFS does actually work now =)

kind: ConfigMap
apiVersion: v1
metadata:
  name: local-path-config
  namespace: local-path-storage
data:
  config.json: |-
        {
                "nodePathMap":[
                {
                        "node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
                        "paths":["/tank/"]
                }
                ]
        }
  setup: |-
        #!/bin/sh
        while getopts "m:s:p:" opt
        do
            case $opt in
                p)
                absolutePath=$OPTARG
                ;;
                s)
                sizeInBytes=$OPTARG
                ;;
                m)
                volMode=$OPTARG
                ;;
            esac
        done
        #volMode=Filesystem
        zfs create -o quota=${sizeInBytes} ${absolutePath:1}
        chmod g+w ${absolutePath}
  teardown: |-
        #!/bin/sh
        while getopts "m:s:p:" opt
        do
            case $opt in
                p)
                absolutePath=$OPTARG
                ;;
                s)
                sizeInBytes=$OPTARG
                ;;
                m)
                volMode=$OPTARG
                ;;
            esac
        done
        zfs destroy ${absolutePath:1}
  helperPod.yaml: |-
        apiVersion: v1
        kind: Pod
        metadata:
          name: helper-pod
        spec:
          containers:
          - name: helper-pod
            image: srueg/zfs-utils
            securityContext:
              privileged: true
            volumeMounts:
            - mountPath: /tank
              name: data
              mountPropagation: Bidirectional
markusressel commented 3 years ago

Thx for the effort, looking forward to trying this out in the coming days :nerd_face:

mgoltzsche commented 3 years ago

PR #166 allows to specify the mountPropagation within the helper Pod template.

haslersn commented 3 years ago

What needs to be done in order to integrate this with the volume snapshot API?

innobead commented 3 years ago

I guess this can be done enabling the mountPropagation=Bidirectional directly, near here, but that would require the pod helper to run privileged, thus probably would need to be enabled via a flag.

Anyway, another aproach could be something like this?

In case anyone cares, just uploaded a docker image with that change.

With the followin config, ZFS does actually work now =)

kind: ConfigMap
apiVersion: v1
metadata:
  name: local-path-config
  namespace: local-path-storage
data:
  config.json: |-
        {
                "nodePathMap":[
                {
                        "node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
                        "paths":["/tank/"]
                }
                ]
        }
  setup: |-
        #!/bin/sh
        while getopts "m:s:p:" opt
        do
            case $opt in
                p)
                absolutePath=$OPTARG
                ;;
                s)
                sizeInBytes=$OPTARG
                ;;
                m)
                volMode=$OPTARG
                ;;
            esac
        done
        #volMode=Filesystem
        zfs create -o quota=${sizeInBytes} ${absolutePath:1}
        chmod g+w ${absolutePath}
  teardown: |-
        #!/bin/sh
        while getopts "m:s:p:" opt
        do
            case $opt in
                p)
                absolutePath=$OPTARG
                ;;
                s)
                sizeInBytes=$OPTARG
                ;;
                m)
                volMode=$OPTARG
                ;;
            esac
        done
        zfs destroy ${absolutePath:1}
  helperPod.yaml: |-
        apiVersion: v1
        kind: Pod
        metadata:
          name: helper-pod
        spec:
          containers:
          - name: helper-pod
            image: srueg/zfs-utils
            securityContext:
              privileged: true
            volumeMounts:
            - mountPath: /tank
              name: data
              mountPropagation: Bidirectional

@killfill I would suggest you can contribute back to the examples that will be great. Thanks.

killfill commented 3 years ago

Hi @innobead,

Thanks for your comment, but i think for this to work it needs the bidirectional mounting thing enabled. May be a good idea to wait for that first. What do you think?

innobead commented 3 years ago

Hi @innobead,

Thanks for your comment, but i think for this to work it needs the bidirectional mounting thing enabled. May be a good idea to wait for that first. What do you think?

Sounds good to me, let's wait for #165 to resolve first.

derekbit commented 2 years ago

@killfill Looks good. Are you ready for submitting a PR for ZFS example?

killfill commented 2 years ago

Hey @derekbit , well I would love to.

But I think some changes needs to be done previously. Im actually using these changes for my little setup, which works, but im not sure its going into the right direction.

killfill commented 2 years ago

All right, adding the example file as a PR. It actually needs the head-master tag, (and probably the next release v0.0.22).

Hope it helps.

derekbit commented 2 years ago

@killfill Sorry for the late reply. The PR Looks good. I will test it before merging it. Thank you!