<p>I am using clickhouse database and data are stored at <code>/media/user/data/clickhouse</code> and <code>/media/user/data/clickhouse-server</code>. When I run a docker container</p>
<pre><code>$ docker run \
    --name local-clickhouse \
    --ulimit nofile=262144:262144 \
    -u 1000:1000 \
    -p 8123:8123 \
    -p 9000:9000 \
    -p 9009:9009 \
    -v /media/user/data/clickhouse:/var/lib/clickhouse \
    -v /media/user/data/clickhouse-server:/var/log/clickhouse-server \
    -dit clickhouse/clickhouse-server
</code></pre>
<p>I see the data and everything is fine. I am trying to run this in a pod using minikube with following persistent volume configs:</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: host-pv-clickhouse
spec:
  capacity:
    storage: 4000Gi   
  volumeMode: Filesystem
  storageClassName: standard
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /media/user/data/clickhouse
    type: DirectoryOrCreate
</code></pre>
<p>and</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: host-pv-clickhouse-server
spec:
  capacity:
    storage: 4000Gi 
  volumeMode: Filesystem  
  storageClassName: standard
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /media/user/data/clickhouse-server
    type: DirectoryOrCreate
</code></pre>
<p>Additionally, I also have persistent volume claims:</p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: host-pvc-clickhouse-server
spec:
  volumeName: host-pv-clickhouse-server
  storageClassName: standard
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2000Gi
</code></pre>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: host-pvc-clickhouse
spec:
  volumeName: host-pv-clickhouse
  storageClassName: standard
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2000Gi
</code></pre>
<p>and finally service and deployment:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: clickhouse
spec:
  type: NodePort
  ports:
    - protocol: TCP
      name: tcp
      port: 9000
      targetPort: 9000
      nodePort: 30003
    - protocol: TCP
      name: http
      port: 8123
      targetPort: 8123
      nodePort: 30004
    - protocol: TCP
      name: interncomm
      port: 9009
      targetPort: 9009
      nodePort: 30005
  selector:
    app: clickhouse
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: clickhouse
  labels:
    app: clickhouse
spec:
  replicas: 1
  selector:
    matchLabels:
      app: clickhouse
  template:
    metadata:
      labels:
        app: clickhouse
    spec:
      containers:
        - name: clickhouse
          image: clickhouse/clickhouse-server:latest
          ports:
            - containerPort: 8123
              name: http
            - containerPort: 9000
              name: tcp
            - containerPort: 9009
              name: interncomm
          volumeMounts:
            - name: clickhouse-volume
              mountPath: /var/lib/clickhouse
            - name: clickhouse-server-volume
              mountPath: /var/log/clickhouse-server
      volumes:
        - name: clickhouse-volume
          persistentVolumeClaim: 
            claimName: host-pvc-clickhouse
        - name: clickhouse-server-volume
          persistentVolumeClaim: 
            claimName: host-pvc-clickhouse-server
</code></pre>
<p>When I run
<code>kubectl apply -f chdb_node.yaml</code> it works and I can access the database via clickhouse's web gui. However, the data aren't there.</p>
<p>Any suggestions to how to fix this?</p>

MoneyBall
<p>Check first the data at <code>/media/user/data/clickhouse</code> and <code>/media/user/data/clickhouse-server</code> on your host machine indeed contains the expected ClickHouse data.</p>
<p>And remember that, when you use Minikube, it typically runs in a virtual machine (like VirtualBox). It means the <code>hostPath</code> you are providing is referencing the filesystem of the VM, not your actual host.<br />
To use host filesystem in Minikube with <code>hostPath</code>, you should make sure that the directory is properly mounted into the Minikube VM, using <a href="https://minikube.sigs.k8s.io/docs/handbook/mount/" rel="nofollow noreferrer"><code>minikube mount</code></a>.</p>
<pre class="lang-bash prettyprint-override"><code>minikube mount /media/user/data:/media/user/data
</code></pre>
<p>That would mount the <code>/media/user/data</code> directory from your host into the Minikube VM at the same location. After doing this, your <code>hostPath</code> configuration should work as expected.</p>
<p>Warning: Your Docker run command specifies a user and group with UID and GID as <code>1000:1000</code>. Ensure that the files and directories at <code>/media/user/data/clickhouse</code> and <code>/media/user/data/clickhouse-server</code> are owned by this UID and GID. If not, the ClickHouse server might not be able to read them.<br />
In your Kubernetes pod, you did not specify the user or group to run the container. You might want to set the same user as you did with Docker using <a href="https://kubernetes.io/docs/tasks/configure-pod-container/security-context/" rel="nofollow noreferrer">the <code>securityContext</code></a>:</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
    containers:
    - name: clickhouse
        ...
        securityContext:
        runAsUser: 1000
        runAsGroup: 1000
</code></pre>
