How to create a helm chart where one template relies on another

6/5/2019

I'm trying to create a kubernetes chart which creates an nfs based on the example given here:

https://medium.com/platformer-blog/nfs-persistent-volumes-with-kubernetes-a-case-study-ce1ed6e2c266

The problem with this is that it requires that we create a service, and then we create a persistent volume which references the cluster ip of the service (which I won't know until the service has been deployed.

I was initially thinking that I could use a template in someway to call kubectl to query for the cluster ip, but as far as I can tell, you can't run a CLI from within helm templates?

If this is the case, I'm really struggling to see the usefulness of helm, as lots of setups would require creating one resource, and then referencing a dynamic property of that from a different resource? I know I could solve this by splitting the chart in two, but my understanding of helm is that a chart should contain everything required to deploy a functional part of your app?

Here is the relevant snippet from my template:

apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.prefix }}-{{ .Values.appName }}-nfs
spec:
  ports:
    - name: nfs
      port: 2049
    - name: mountd
      port: 20048
    - name: rpcbind
      port: 111
  selector:
    role: {{ .Values.prefix }}-{{ .Values.appName }}-nfs

---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: {{ .Values.prefix }}-{{ .Values.appName }}-nfs
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: << nfs.clusterip >>
    path: "/"

NOTE: the << nfs.clusterip >> field at the end of the persistent volume.

-- Andy
kubernetes-helm

0 Answers