Adding Persistent Storage to Kubernetes for GCP Web UI users.

Jake Cattrall
Jun 8, 2018 · 3 min read

Compared to other solutions Google Cloud Platform relies far too heavily on it’s CLI to perform basic actions on infrastructure. In fact, 90% of the documentation only explains how to perform tasks using the CLI which is confusing when some of the set up may have been done using the nice, comfortable web ui. The potential is great, but their refusal to make life easy for those who just want to get things done with a GUI without learning “yet another” CLI or hitting the terminal at all is pretty short-sighted. For most non-enterprise users, the learning curve is laughable, it really doesn’t have to be.

One of the most basic things a containerised web application may require is persistent storage. It’s a common requirement and not much to ask. The Kubernetes web ui makes it as hard as possible to get started with muddling terminology, docs and missing functionality. So let’s clarify some terminology…

PersistentVolume
It is what it is, a disk that doesn’t go away when pods are destroyed. When you create a new cluster and node pool using the Web UI, 100GB of persistent storage is assigned by default.

PersistentVolumeClaim
(PVC) These are configurations that exist at the cluster level. They are simply a configuration that can be referred to in a workload configuration. Things like the amount of the volume to claim, permissions and namespace can be set. Frustratingly, you can’t add these using the web ui, even though you can manage the existing ones. Management is done through the storage menu found by clicking the menu item in the image above.

Creating a PersistentVolumeClaim

From the Kubernetes Clusters menu, click the “Connect” button next to the cluster you want to add storage to (if you don’t see it, refresh the page). Click “Run in Cloud Shell”. After the shell loads, press the enter key to execute the predefined command. You are now working in the correct cluster.

  • Create a yaml file: touch pstorage.yaml
  • Open the yaml file in an editor: nano pstorage.yaml
  • Paste the following PVC configuration into the editor and change the name, namespace and storage values to your own requirements.
    Note: It’s important that the namespace is the same as the workload.
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: cool-data
namespace: default
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 80Gi
  • Hit ctrl+x to tell the editor you want to leave, it will ask you if you want to save, press y and hit enter.
  • Now create the PVC: kubectl create -f pstorage.yaml
  • Check it out in the Storage menu on the Web UI and make sure the namespace and name are correct.
  • Go to the workload who’s pods you want to have access to this PVC and press the edit button to edit the YAML configuration.

Check out the following configuration…

spec:
template:
spec:
containers:
- env:
volumeMounts:
- mountPath: /var/www/html
name: cool-data
subPath: wp
volumes:
- name: cool-data
persistentVolumeClaim:
claimName: cool-data

Copy the volumeMounts and volumes sections and place them appropriately in your own workload configuration.

  • Set the name to the same as the PVC in previous steps.
  • Set the mountPath to where you want the PVC mounted in the pods filesystem.
  • Set the subPath to a unique subdirectory which will be used on the PVC to prevent conflicts.
  • Press Save
  • If the workload doesn’t reinitialise with fresh pods, go in and delete the pod to force the reinitialisation.

That’s it! Your pods will now have access to the Persistent Storage.

This tutorial is too long, I hope this will all be configurable in the Web UI in the near future.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade