Problems with running container on a Kubernetes Persistent Volume

When I use a mount path of /usr/local/bin/ignition/data in my kubernetes deployment yaml, the container won’t start (it works fine in docker-compose on podman & docker). Ignition gateway log reports an error of
init | 2022/05/24 15:00:27 | Creating init.properties file
init | 2022/05/24 15:00:27 | Creating gateway.xml
cp: cannot stat ‘/usr/local/bin/ignition/data/gateway.xml_clean’: No such file or directory

and kubectl get pod shows the container as CrashLoopBackOff

If I change the mount path to /data then the container starts but the volume mounts as /data within the container and not /usr/local/bin/ignition/data so that the data directory is located in temporary storage and is lost on pod restart.
To get around this, I entered into the command line of the container and copied the contents of /usr/local/bin/ignition/data to /data, killed the pod, set my mount path back to /usr/local/bin/ignition/data and restarted the pod. The container started up fine and can now read & write files within the persistent volume
Yaml contents:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: foo-data-pv
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 200Mi
  hostPath:
    path: /data/containerData/foo-data
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-path
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: foo-data-pvc
  namespace: default
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 200Mi
  storageClassName: local-path
  volumeName: foo-data-pv
status:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 200Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ignition-foo-pilot
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ignition-foo-pilot
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: ignition-foo-pilot
    spec:
      containers:
      - env:
        - name: GATEWAY_SYSTEM_NAME
          value: ignition-foo
        - name: GATEWAY_ADMIN_USERNAME
          value: admin
        - name: GATEWAY_ADMIN_PASSWORD
          value: password
        - name: IGNITION_EDITION
          value: standard
        image: inductiveautomation/ignition:8.1.16
        imagePullPolicy: IfNotPresent
        name: ignition-foo
        ports:
        - containerPort: 8088
          protocol: TCP
        - containerPort: 8060
          protocol: TCP
        volumeMounts:
        - mountPath: /usr/local/bin/ignition/data
          name: foo-data
      restartPolicy: Always
      volumes:
      - name: foo-data
        persistentVolumeClaim:
          claimName: foo-data-pvc

Have you looked through this thread?

3 Likes