Search code examples
kubernetes.net-corekubernetes-pod

Persist new config files when installing dotnet cor app in kubernetes


I'm new to Kubernetes and I'm struggling with the installation of the app itself as the new config files are not getting persisted, not the deployment of the pods.

The first time I run the app I'm presented with installation panel where I can set basic data such as database server, db name, user/pass and so on. After the installation is completed the application will restart and I lose all the information as one would assume.

So I tried adding /app as mountPath but when I do that I get that dotnet SDK is not installed and pod is never created although I don't think I should be persisting the entire /app folder, so I also tried mountPath /app/App_Data and when I do that pod is started but files are missing in App_Data so installation cannot continue.

Here is the code I'm using. Deploy is done in DigitalOcean.

Here is the yaml I'm using, what I need to do in order to install the app and after restarting the pod getting the application new new config files? Should I create a docker image that already has all needed configuration instead of installing it from the pod directly?

PVC

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-nopcommerce
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: do-block-storage
  resources:
    requests:
      storage: 5Gi

Service

apiVersion: v1
kind: Service
metadata:
  name: nopcommerce
  labels:
    app: nopcommerce
spec:
  ports:
  - name: nopcommerce
    port: 80
  selector:
    app: nopcommerce

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nopcommerce
spec:
  selector:
    matchLabels:
      app: nopcommerce
  replicas: 1
  template:
    metadata:
      labels:
        app: nopcommerce
    spec:
      containers:
      - name: nopcommerce
        image: nopcommerce/nopcommerce:4.2
        ports:
          - containerPort: 80
        volumeMounts:
        - name: nopcommerce
          mountPath: /app
      volumes:
      - name: nopcommerce
        persistentVolumeClaim:
          claimName: pvc-nopcommerce   

Solution

  • From your description, the problem seems to be due mounting volume in place of other files and because of that mount is hiding these files.

    You cannot do anything about it, this is how it works and this is expected bahaviour.

    If you need a directory to be persisted and still have some files in it think about copying these files from other path to this path before starting the application. You can use initContainers or entrypoint script to achieve it.


    Should I create a docker image that already has all needed configuration instead of installing it from the pod directly

    It all depends on specific problem but generally this is a good idea.