flant/loghouse

Persistent volumes should be initialized

cicdteam opened this issue · 0 comments

Hi!

When hostpath (and probably PVC) used as Storage clickhouse server fail to write anything to /var/lib/clickhouse/ as server process running with user id 105.

Regarding to hostPath documentation:

the files or directories created on the underlying hosts are only writable by root. You either need to run your process as root in a privileged Container or modify the file permissions on the host to be able to write to a hostPath volume

I've solved that by adding additional init container to clickhouse template (first one, before config container):

      initContainers:
      - name: chown
        image: alpine:3.6
        securityContext:
          runAsUser: 0
          fsGroup: 0
        command:
          - '/bin/sh'
          - '-c'
          - chown -R 105:106 /var/lib/clickhouse/
        volumeMounts:
{{- if .Values.storage.hostpath }}
          - name: hostpath
            mountPath: /var/lib/clickhouse/
{{- end }}
{{- if .Values.storage.pvc }}
          - name: {{ .Values.storage.pvc.name }}
            mountPath: /var/lib/clickhouse/
{{- end }}
{{- if .Values.storage.emptyDir }}
          - name: data
            mountPath: /var/lib/clickhouse/
{{- end }}

BTW, emptyDir works well without any modifications as volume created with correct owner when runAsUser used in securityContext.