Kubernetes loosing data on container restart

Hi there,

I’m facing a non-usual issue with my new InfluxDB 2.0.4 deploy in Kubernetes.
If I perform a scale down to 0 replicas and then a scale up to 1, when I log into InfluxDB it appears the wizard to create the initial settings.

I’ve changed the YAML to have a persistent volume and I can see that the pod is always bound to the same volume.

Also, I’m mounting the disk in /root/.influxdbv2.

It looks like this:

---
apiVersion: v1
kind: Namespace
metadata:
    name: influx
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: influxdb-disk-claim
  namespace: influx
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: default
  resources:
    requests:
     storage: 1Ti
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
    labels:
        app: influxdb
    name: influxdb
    namespace: influx
spec:
    replicas: 1
    selector:
        matchLabels:
            app: influxdb
    serviceName: influxdb
    template:
        metadata:
            labels:
                app: influxdb
        spec:
            volumes:
            - name: data
              persistentVolumeClaim:
                claimName: influxdb-disk-claim
            containers:
              - image: influxdb:2.0.4
                name: influxdb
                ports:
                  - containerPort: 8086
                    name: influxdb
                volumeMounts:
                  - mountPath: /root/.influxdbv2
                    name: data
                env:
                  - name: INFLUXD_STORAGE_CACHE_SNAPSHOT_WRITE_COLD_DURATION
                    value: "5s"
---
apiVersion: v1
kind: Service
metadata:
    name: influxdb
    namespace: influx
spec:
    ports:
      - name: influxdb
        port: 8086
        targetPort: 8086
    selector:
        app: influxdb
    type: LoadBalancer

Can someone explain me what am I missing here?

Thanks

I’ve just found this in the logs:

ts=2021-04-07T13:59:56.196761Z lvl=info msg="Welcome to InfluxDB" log_id=0TN9yG90000 version=2.0.4 commit=4e7a59bb9a build_date=2021-02-08T17:47:02Z
ts=2021-04-07T13:59:56.233619Z lvl=info msg="Resources opened" log_id=0TN9yG90000 service=bolt path=/var/lib/influxdb2/influxd.bolt
ts=2021-04-07T13:59:56.237470Z lvl=info msg="Bringing up metadata migrations" log_id=0TN9yG90000 service=migrations migration_count=14
ts=2021-04-07T13:59:56.681211Z lvl=info msg="Using data dir" log_id=0TN9yG90000 service=storage-engine service=store path=/var/lib/influxdb2/engine/data

Does this means that I should be mounting my disk in /var/lib/influxdb2/engine/data?

I’ve solved this using this:

volumeMounts:
                  - mountPath: /var/lib/influxdb2/engine/data
                    name: data
                env:
                  - name: INFLUXD_BOLT_PATH
                    value: "/var/lib/influxdb2/engine/data/influxd.bolt"

Can you advise if this is a good solution?