This project solves the PersistentVolume provisioning in OpenShift. It is mainly a packaged and polished version of the Kubernetes Incubator's Hostpath Provisioner (https://github.com/kubernetes-incubator/external-storage/tree/master/docs/demo/hostpath-provisioner).
The original license is Apache 2.0. This project remains under the same license.
Main differences from the original project :
- OpenShift Template that works Out-of-the-Box
- Naming convention (namespace/pvc-name instead of GUID)
- Configurable root directory (HOSTPATH_TO_USE parameter)
- Docker Image available on DockerHub (https://hub.docker.com/r/nmasse/openshift-hostpath-provisioner/)
Current limitations :
- DO NOT USE IT IN PRODUCTION
- Only works on OpenShift clusters that have a single node
If you just want to use this project, without having to compile or debug, here is the way to go.
First, you will have to create a directory that will hold all PersistentVolumes :
mkdir /var/openshift
chmod 777 /var/openshift
chcon -Rt svirt_sandbox_file_t /var/openshift
If you chose a different path, mind that you will have to pass the HOSTPATH_TO_USE parameter to the OpenShift template (-p HOSTPATH_TO_USE=/path/to/other/directory).
In order to setup the hostpath provisioner, you have to be cluster admin on your OpenShift instance. There are multiple ways to login with cluster admin rights, one way is to use your kube.config file on the master :
oc login -u system:admin --config ~/.kube/config
Then, you will have to process the template and create the generated objects :
oc process -f setup/hostpath-provisioner-template.yaml > objects.json
oc create -f objects.json
If you chose a different path, just pass the HOSTPATH_TO_USE parameter to the "oc process" command :
oc process -f setup/hostpath-provisioner-template.yaml -p HOSTPATH_TO_USE=/path/to/other/directory > objects.json
oc create -f objects.json
The template by default creates objects in the "default" namespace, no matter the "-n" option you used or the "oc project" command you issued before. This is in fact a limitation (see openshift/origin#8971).
But, if you want to generate objects in another namespace (project), just pass the TARGET_NAMESPACE parameter to the "oc process" command :
oc process -f setup/hostpath-provisioner-template.yaml -p TARGET_NAMESPACE=my-project > objects.json
oc create -f objects.json
By default, the template uses the "nmasse/openshift-hostpath-provisioner:latest" image on DockerHub (see https://hub.docker.com/r/nmasse/openshift-hostpath-provisioner/). You can change this behavior by passing the HOSTPATH_PROVISIONER_IMAGE to "oc process" command :
oc process -f setup/hostpath-provisioner-template.yaml -p HOSTPATH_PROVISIONER_IMAGE=john/openshift-hostpath-provisioner:latest > objects.json
oc create -f objects.json
If you need to pass multiple parameters, use multiple "-p" options :
oc process -f setup/hostpath-provisioner-template.yaml -p TARGET_NAMESPACE=my-project -p HOSTPATH_TO_USE=/path/to/other/directory > objects.json
oc create -f objects.json
Note about the file 'objects.json' :
It's a good idea to keep that file safe since it will be use to clean up your OpenShift instance in case you change your mind. See the cleanup section below.
A sample PersistentVolumeClaim object is provided to test the provisioner :
oc project my-project
oc create -f setup/sample-claim.yaml
find /var/openshift/
You can cleanup your OpenShift instance by running the "oc delete" command :
oc delete -f objects.json
export GOPATH="$PWD"
cd src
glide install -v
CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o ../hostpath-provisioner hostpath-provisioner/hostpath-provisioner.go
docker build -t openshift-hostpath-provisioner:latest .
oc project default
oc delete all -l template=hostpath-provisioner-template
oc delete sa hostpath-provisioner
oc delete clusterrolebinding hostpath-provisioner
oc delete clusterrole hostpath-provisioner
oc delete scc hostpath-provisioner
oc delete storageclass hostpath-provisioner
docker login https://index.docker.io/v1/
docker images openshift-hostpath-provisioner:latest --format '{{ .ID }}'
docker tag $(docker images openshift-hostpath-provisioner:latest --format '{{ .ID }}') index.docker.io/<your-username>/openshift-hostpath-provisioner
docker push index.docker.io/<your-username>/openshift-hostpath-provisioner