apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: clickhouse
  namespace: clickhouse
spec:
  selector:
    matchLabels:
      app: clickhouse
  serviceName: clickhouse
  template:
    metadata:
      labels:
        app: clickhouse
    spec:
      volumes:
        - name: init
          configMap:
            name: init
        - name: config
          configMap:
            name: config
        - name: users
          secret:
            secretName: users
      containers:
        - name: clickhouse
          image: clickhouse/clickhouse-server:21.12-alpine
          ports:
            - containerPort: 8123
            - containerPort: 9000
          volumeMounts:
            - name: init
              mountPath: /docker-entrypoint-initdb.d
            - name: config
              mountPath: /etc/clickhouse-server/users.xml
              subPath: users.xml
            - name: users
              mountPath: /etc/clickhouse-server/users.d
            - name: data
              mountPath: /var/lib/clickhouse
            - name: logs
              mountPath: /var/log/clickhouse-server
  volumeClaimTemplates:
    - metadata:
        name: data
        namespace: clickhouse
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 10Gi
    - metadata:
        name: logs
        namespace: clickhouse
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 2Gi