question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

We should set the PVC's volumeName, i think

See original GitHub issue

@hans-permana found the z2jh setting singleuser.storage.dynamic.volumeNameTemplate. We both thought that this could influence the naming of the dynamically created PersistantVolume objects. Our investigation led us to conclude that this is only the spawned pods volume reference under the pods spec.volumes that is named in this manner, while the actual PersistantVolume k8s object, which is to be provisioned by the cloud provider looking at the PVC object in turn created by KubeSpawner, is not getting a similar name. This is because the PVC kubespawner creates does not set the spec.volumeName field (see reference documentation).

I think we should allow optionally setting the volumeName field of the PVC’s spec through the make_pvc function in kubespawner. The Z2JH project can then later decide to utilize this option or not.

Suggested action - Add config of volumeName here

https://github.com/jupyterhub/kubespawner/blob/481ec0926960927300c7355c48bd03230ee857f0/kubespawner/objects.py#L393-L433

Reference only, related code

Z2JH configuration (inspect in the source code):

singleuser:
  storage:
    dynamic:
      storageClass:
      pvcNameTemplate: claim-{username}{servername}
      volumeNameTemplate: volume-{username}{servername}
      storageAccessModes: [ReadWriteOnce]

Z2JH config of kubespawner based on Z2JH config:

if storage_type == 'dynamic':
    pvc_name_template = get_config('singleuser.storage.dynamic.pvcNameTemplate')
    c.KubeSpawner.pvc_name_template = pvc_name_template
    volume_name_template = get_config('singleuser.storage.dynamic.volumeNameTemplate')
    c.KubeSpawner.storage_pvc_ensure = True
    set_config_if_not_none(c.KubeSpawner, 'storage_class', 'singleuser.storage.dynamic.storageClass')
    set_config_if_not_none(c.KubeSpawner, 'storage_access_modes', 'singleuser.storage.dynamic.storageAccessModes')
    set_config_if_not_none(c.KubeSpawner, 'storage_capacity', 'singleuser.storage.capacity')

    # Add volumes to singleuser pods
    c.KubeSpawner.volumes = [
        {
            'name': volume_name_template,
            'persistentVolumeClaim': {
                'claimName': pvc_name_template
            }
        }
    ]
    c.KubeSpawner.volume_mounts = [
        {
            'mountPath': get_config('singleuser.storage.homeMountPath'),
            'name': volume_name_template
        }
    ]

A spawned user pods specs

spec:
  # ...
  volumes:
  - name: volume-erik-2esundell
    persistentVolumeClaim:
      claimName: claim-erik-2esundell

Docs about the volumes configurable on kubespawner

https://github.com/jupyterhub/kubespawner/blob/481ec0926960927300c7355c48bd03230ee857f0/kubespawner/spawner.py#L586-L611

Kubespawners actual usage of the volumes

https://github.com/jupyterhub/kubespawner/blob/481ec0926960927300c7355c48bd03230ee857f0/kubespawner/objects.py#L311-L312

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bitnikcommented, Oct 24, 2018

I just tried to create a PVC with volumeName set:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: claim-test-volume-name
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  volumeName: volume-test-name

But the creation of PVC not completed because I think it searches for a PV with this name and it doesn’t exist. I commented the line with volumeName and this time PVC is created with PV with a random name. I am not completely sure but if volumeName config is set, in the code we first should create a PV with claimRef to the PVC and when PVC is created, it will be bound it.

0reactions
consideRatiocommented, Oct 24, 2018

Hmmm, I’m not confident about what happens if you create the full cluster itself, but if you delete the namespace and the helm release etc, then I know the PVs created by the PVCs can be undeleted and things will can be fine. For that, see:

  1. https://github.com/jupyterhub/zero-to-jupyterhub-k8s/blob/master/CHANGELOG.md#1-optional-ensure-the-hubs-and-users-data-isnt-lost
  2. https://github.com/jupyterhub/zero-to-jupyterhub-k8s/blob/master/CHANGELOG.md#troubleshooting---make-released-pvs-available-for-reuse

I’m curious to learn more about how a PV is coupled to a cluster, and if you could transfer it to another cluster, etc. I’ve only been using GKE, and never done such thing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do I need a PersistentVolume, if I have a ... - Stack Overflow
So, one can create a PVC with volumeName: my-volume , and have it bounded to an existing PV. Or create the PV later,...
Read more >
1369977 – PVC fails to bind - Red Hat Bugzilla
How can a PVC be bound to a PV (i.e. > pvc.Spec.VolumeName is set) and still have pvc.Status.Phase = Pending in the >...
Read more >
Reclaiming Persistent Volumes in Kubernetes - Medium
Create new PVC manifests. Before we can delete the old PVCs, we will export their manifests and modify them to match the naming...
Read more >
Premature ventricular contractions (PVCs) - Mayo Clinic
Premature ventricular contractions (PVCs) are extra heartbeats that begin in one of the heart's two lower pumping chambers (ventricles).
Read more >
Kubernetes Persistent Volumes | Tutorial and Examples
In this article, you will learn about Kubernetes persistent volumes, including some ... You configure your application pod to use the PVC as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found