rimusz / hostpath-provisioner Goto Github PK
View Code? Open in Web Editor NEWDynamic Provisioning of Kubernetes HostPath Volumes
License: Apache License 2.0
Dynamic Provisioning of Kubernetes HostPath Volumes
License: Apache License 2.0
When using subPath option of volumeMounts, the pvc-... directory and subpath is not created.
System:
Thank you
Both the tl;dr
and the installation instructions are not valid for V3, which requires a name
parameter.
Suggestion for tl;dr
:
# generates the release name
helm install -g rimusz/nfs-client-provisioner --set nfs.server="1.2.3.4"
Suggestion for Installing
:
helm install nfs rimusz/nfs-client-provisioner--set nfs.server="1.2.3.4"
Depending on the type of pod you start the PVs are created with different owners/permissions.
In the pod we do see now permission errors
cp: cannot create directory '/var/solr/data/ezplatform': Permission denied
The reason for that is that the folder is owned by root with 755 permissions and the user solr can`t create folders.
A fix could be to create that folders with 777 permissions somehow.
[root@openshift data]# ls -lisa hostpath-provisioner/
total 16
2147488241 4 drwxrwxrwx. 9 root root 4096 Aug 14 16:47 .
64 0 drwxrwxrwx. 5 root root 101 Aug 14 15:48 ..
2147491394 4 drwxr-xr-x. 7 polkitd root 4096 Aug 14 16:48 pvc-0d44ea3c-de3d-11ea-a18f-00259056a256
4299069738 0 drwxr-xr-x. 2 root root 6 Aug 14 16:47 pvc-0d4e1822-de3d-11ea-a18f-00259056a256
Currently, the directory name is generated as random UUID. Could you add an option to use the PVC name as directory name for generated PVs?
The absolute ideal soultion would be to have a template with placeholders (e.g. UUID, namespace, pvcname). This would allow more customized settings (e.g. use $namespace/$pvcname as directory name)
Currently, the type of the created hostpath volume is empty, so k8s waits until someone creates the directory. Would you add an option to specify the type (so that it can be set to "DirectoryOrCreate")?
Best regards,
Michael.
when I use NODE_HOST_PATH to set a custom directory as my hostpath mount point,such as /data. If i create pvc and pod by the yaml file below.The pvc directory is created normal in /data.but when I delete the pod and pvc, The pvc directory is still exists.
[root@easyk8s1 ~]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
hostpath hostpath Delete Immediate false 15m
managed-nfs-storage (default) fuseim.pri/ifs Delete Immediate false 11d
[root@easyk8s1 ~]# cat /root/hostpath-pvc.yaml
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-hostpath-pvc
spec:
storageClassName: "hostpath"
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: test-deployment
labels:
app: test-deployment
spec:
replicas: 1
selector:
matchLabels:
app: test-deployment
template:
metadata:
labels:
app: test-deployment
spec:
containers:
- name: test-deployment
image: nginx
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
protocol: TCP
volumeMounts:
- name: hostpath-pvc
mountPath: "/usr/share/nginx/html"
volumes:
- name: hostpath-pvc
persistentVolumeClaim:
claimName: test-hostpath-pvc
[root@easyk8s1 ~]# kubectl get deployment -n hostpath-provisioner my-hostpath-provisioner -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: "2021-08-26T12:49:01Z"
generation: 1
labels:
app.kubernetes.io/instance: my-hostpath-provisioner
app.kubernetes.io/managed-by: Tiller
app.kubernetes.io/name: hostpath-provisioner
helm.sh/chart: hostpath-provisioner-0.2.11
managedFields:
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:labels:
.: {}
f:app.kubernetes.io/instance: {}
f:app.kubernetes.io/managed-by: {}
f:app.kubernetes.io/name: {}
f:helm.sh/chart: {}
f:spec:
f:progressDeadlineSeconds: {}
f:replicas: {}
f:revisionHistoryLimit: {}
f:selector: {}
f:strategy:
f:type: {}
f:template:
f:metadata:
f:labels:
.: {}
f:app.kubernetes.io/instance: {}
f:app.kubernetes.io/name: {}
f:spec:
f:containers:
k:{"name":"hostpath-provisioner"}:
.: {}
f:env:
.: {}
k:{"name":"HOSTPATH_PROVISIONER_NAME"}:
.: {}
f:name: {}
f:value: {}
k:{"name":"NODE_HOST_PATH"}:
.: {}
f:name: {}
f:value: {}
k:{"name":"NODE_NAME"}:
.: {}
f:name: {}
f:valueFrom:
.: {}
f:fieldRef:
.: {}
f:apiVersion: {}
f:fieldPath: {}
f:image: {}
f:imagePullPolicy: {}
f:name: {}
f:resources:
.: {}
f:limits:
.: {}
f:cpu: {}
f:memory: {}
f:requests:
.: {}
f:cpu: {}
f:memory: {}
f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
f:volumeMounts:
.: {}
k:{"mountPath":"/mnt/hostpath"}:
.: {}
f:mountPath: {}
f:name: {}
f:dnsPolicy: {}
f:restartPolicy: {}
f:schedulerName: {}
f:securityContext: {}
f:serviceAccount: {}
f:serviceAccountName: {}
f:terminationGracePeriodSeconds: {}
f:volumes:
.: {}
k:{"name":"pv-volume"}:
.: {}
f:hostPath:
.: {}
f:path: {}
f:type: {}
f:name: {}
manager: Go-http-client
operation: Update
time: "2021-08-26T12:49:01Z"
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:deployment.kubernetes.io/revision: {}
f:status:
f:availableReplicas: {}
f:conditions:
.: {}
k:{"type":"Available"}:
.: {}
f:lastTransitionTime: {}
f:lastUpdateTime: {}
f:message: {}
f:reason: {}
f:status: {}
f:type: {}
k:{"type":"Progressing"}:
.: {}
f:lastTransitionTime: {}
f:lastUpdateTime: {}
f:message: {}
f:reason: {}
f:status: {}
f:type: {}
f:observedGeneration: {}
f:readyReplicas: {}
f:replicas: {}
f:updatedReplicas: {}
manager: kube-controller-manager
operation: Update
time: "2021-08-26T12:49:02Z"
name: my-hostpath-provisioner
namespace: hostpath-provisioner
resourceVersion: "143592"
selfLink: /apis/apps/v1/namespaces/hostpath-provisioner/deployments/my-hostpath-provisioner
uid: 8b07a84e-ceb3-48ca-8148-43e9077b1911
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app.kubernetes.io/instance: my-hostpath-provisioner
app.kubernetes.io/name: hostpath-provisioner
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/instance: my-hostpath-provisioner
app.kubernetes.io/name: hostpath-provisioner
spec:
containers:
- env:
- name: NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: NODE_HOST_PATH
value: /data
- name: HOSTPATH_PROVISIONER_NAME
value: hostpath
image: quay.io/rimusz/hostpath-provisioner:v0.2.3
imagePullPolicy: IfNotPresent
name: hostpath-provisioner
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /mnt/hostpath
name: pv-volume
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: my-hostpath-provisioner
serviceAccountName: my-hostpath-provisioner
terminationGracePeriodSeconds: 30
volumes:
- hostPath:
path: /data
type: ""
name: pv-volume
status:
availableReplicas: 1
conditions:
- lastTransitionTime: "2021-08-26T12:49:02Z"
lastUpdateTime: "2021-08-26T12:49:02Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2021-08-26T12:49:01Z"
lastUpdateTime: "2021-08-26T12:49:02Z"
message: ReplicaSet "my-hostpath-provisioner-75d6bb5868" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 1
readyReplicas: 1
replicas: 1
updatedReplicas: 1
[root@easyk8s1 ~]# kubectl apply -f /root/hostpath-pvc.yaml
persistentvolumeclaim/test-hostpath-pvc created
deployment.apps/test-deployment created
[root@easyk8s1 ~]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
test-hostpath-pvc Bound pvc-51b85064-d158-44cc-a0d5-10f7ad286407 100Mi RWO hostpath 14s
[root@easyk8s1 ~]# ls /data/
pvc-51b85064-d158-44cc-a0d5-10f7ad286407
[root@easyk8s1 ~]# kubectl delete -f /root/hostpath-pvc.yaml
persistentvolumeclaim "test-hostpath-pvc" deleted
deployment.apps "test-deployment" deleted
[root@easyk8s1 ~]# ls /data/
pvc-51b85064-d158-44cc-a0d5-10f7ad286407
[root@easyk8s1 ~]# kubectl logs -n hostpath-provisioner my-hostpath-provisioner-75d6bb5868-rgqpl
I0826 13:08:36.341866 1 controller.go:926] provision "default/test-hostpath-pvc" class "hostpath": started
I0826 13:08:36.357548 1 controller.go:1026] provision "default/test-hostpath-pvc" class "hostpath": volume "pvc-51b85064-d158-44cc-a0d5-10f7ad286407" provisioned
I0826 13:08:36.357653 1 controller.go:1040] provision "default/test-hostpath-pvc" class "hostpath": trying to save persistentvolume "pvc-51b85064-d158-44cc-a0d5-10f7ad286407"
I0826 13:08:36.358289 1 event.go:221] Event(v1.ObjectReference{Kind:"PersistentVolumeClaim", Namespace:"default", Name:"test-hostpath-pvc", UID:"51b85064-d158-44cc-a0d5-10f7ad286407", APIVersion:"v1", ResourceVersion:"146892", FieldPath:""}): type: 'Normal' reason: 'Provisioning' External provisioner is provisioning volume for claim "default/test-hostpath-pvc"
I0826 13:08:36.374979 1 controller.go:1047] provision "default/test-hostpath-pvc" class "hostpath": persistentvolume "pvc-51b85064-d158-44cc-a0d5-10f7ad286407" saved
I0826 13:08:36.375018 1 controller.go:1088] provision "default/test-hostpath-pvc" class "hostpath": succeeded
I0826 13:08:36.375078 1 event.go:221] Event(v1.ObjectReference{Kind:"PersistentVolumeClaim", Namespace:"default", Name:"test-hostpath-pvc", UID:"51b85064-d158-44cc-a0d5-10f7ad286407", APIVersion:"v1", ResourceVersion:"146892", FieldPath:""}): type: 'Normal' reason: 'ProvisioningSucceeded' Successfully provisioned volume pvc-51b85064-d158-44cc-a0d5-10f7ad286407
I0826 13:09:22.030954 1 controller.go:1097] delete "pvc-51b85064-d158-44cc-a0d5-10f7ad286407": started
I0826 13:09:22.035694 1 controller.go:1125] delete "pvc-51b85064-d158-44cc-a0d5-10f7ad286407": volume deleted
I0826 13:09:22.041431 1 controller.go:1135] delete "pvc-51b85064-d158-44cc-a0d5-10f7ad286407": persistentvolume deleted
I0826 13:09:22.041447 1 controller.go:1137] delete "pvc-51b85064-d158-44cc-a0d5-10f7ad286407": succeeded
Problem
Provisioner fails to provision for PVC on k8s 1.20.0, probably due to using deprecated API
I1222 08:35:34.516087 1 leaderelection.go:187] attempting to acquire leader lease kube-system/hostpath...
E1222 08:35:34.527970 1 event.go:259] Could not construct reference to: '&v1.Endpoints{TypeMeta:v1.TypeMeta{Kind:"", APIVersion:""}, ObjectMeta:v1.ObjectMeta{Name:"hostpath", GenerateName:"", Namespace:"kube-system", SelfLink:"", UID:"c60ee6c6-8865-4b6b-96a3-fcccfadadc4f", ResourceVersion:"507", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:63744222934, loc:(*time.Location)(0x1d6f9e0)}}, DeletionTimestamp:(*v1.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string{"control-plane.alpha.kubernetes.io/leader":"{\"holderIdentity\":\"hostpath-provisioner-fb7b56c97-xnn84_a8bf3c14-4430-11eb-905e-f69a64d714c5\",\"leaseDurationSeconds\":15,\"acquireTime\":\"2020-12-22T08:35:34Z\",\"renewTime\":\"2020-12-22T08:35:34Z\",\"leaderTransitions\":0}"}, OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Subsets:[]v1.EndpointSubset(nil)}' due to: 'selfLink was empty, can't make reference'. Will not report event: 'Normal' 'LeaderElection' 'hostpath-provisioner-fb7b56c97-xnn84_a8bf3c14-4430-11eb-905e-f69a64d714c5 became leader'
I1222 08:35:34.528054 1 leaderelection.go:196] successfully acquired lease kube-system/hostpath
I1222 08:35:34.602606 1 controller.go:571] Starting provisioner controller hostpath_hostpath-provisioner-fb7b56c97-xnn84_a8bf3c14-4430-11eb-905e-f69a64d714c5!
I1222 08:35:34.702851 1 controller.go:620] Started provisioner controller hostpath_hostpath-provisioner-fb7b56c97-xnn84_a8bf3c14-4430-11eb-905e-f69a64d714c5!
Related issue
kubernetes-sigs/nfs-subdir-external-provisioner#25
Workaround
Disable deprecation of feature in kube-apiserver-arg
- --feature-gates=RemoveSelfLink=false
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.