I have a Kubernetes POD running and I have attached a PVC to it. The PVC volume is /opt/stackstorm.
By default, there are certain files inside the /opt/stackstorm which comes as part of the docker official image. These files are visible when there is no PVC attached to the POD.
But when a PVC is attached, the files are replace and a lost&found directory is created.
How we can retain the directory even after attaching the PVC ?
I have changed directories for the PVC. When I change the directory from opt/stackstorm to /opt/stack then /opt/stackstorm has all the details but /opt/stack becomes empty.
So the PVC when attached to a POD is creating issue.
pvc.yaml:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: stacke
annotations:
volume.beta.kubernetes.io/storage-class: "ebs"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
deployment.yaml:
volumeMounts:
- name: stacke
mountPath: /opt/stackstorm
volumes:
- name: stacke
persistentVolumeClaim:
claimName: stacke
imagePullSecrets:
- name: regcred
expected results is that /opt/stackstorm should have all the files as part of the image.
Your data deleted from pod because your PVC path is not pointing to particular dir.
in this case if you want to save files which are default coming with docker image you can use init container which will copy data or change the permission so files will not be deleted.
initContainers:
- name: init-sysctl
image: busybox
imagePullPolicy: IfNotPresent
command: ["sysctl", "-w", "Command"]
securityContext:
privileged: true
volume:
mount path : /
you can copy the the content of /opt/stackstorm to a new directory in dockerfile and build a new image . After that you can copy the content of the new directory back to /opt/stackstorm in run time. All of this issue occurred because this directory get initialized in build time . For copying in run time you can use postStart in container lifecycle in kubernetes . for example : spec: containers: - name: .... image: .... lifecycle: postStart: exec: command: ["cp" , "-r" , "/test/" ,"/opt/stackstorm"]
this command run after the container start . but this approach copy every time the pod start , if you want to avoid this you can delete the content of the /opt/stackstorm in dockerfile in build time and then in postStart command write the script to check if this dir is empty do copying . And you can have /opt/stackstorm as mountPath and attach a pvc to it just like you have done.