apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: clickhouse-id01
  namespace: default
  labels:
    app: clickhouse-id01
spec:
  selector:
    matchLabels:
      app: clickhouse-id01
  serviceName: clickhouse-id01-server
  replicas: 1
#  minReadySeconds: 60     #滚动升级时60s后认为该pod就绪
  template:
    metadata:
      labels:
        app: clickhouse-id01
      annotations:
        #disable istio sidecar injection
        sidecar.istio.io/inject: "false"
    spec:
      terminationGracePeriodSeconds: 60 ##k8s将会给应用发送SIGTERM信号，可以用来正确、优雅地关闭应用,默认为30秒
      #imagePullSecrets:
      #- name: registrykey-ali-ext
      securityContext:
        #runAsUser: 1000
        #runAsGroup: 3000
        fsGroup: 101
        #fsGroupChangePolicy: "OnRootMismatch"
      containers:
      - name: clickhouse
        image: yandex/clickhouse-server:20.12
        imagePullPolicy: Always
        resources:
          # keep request = limit to keep this container in guaranteed class
          requests:
            cpu: 500m
            memory: 2Gi
          limits:
            cpu: 4000m
            memory: 8Gi
        env:
        - name: TZ
          value: Asia/Shanghai
        ports:
        - containerPort: 8123
          name: clickhouse-http
        - containerPort: 9000
          name: clickhouse-tcp
        - containerPort: 9004
          name: mysql-tcp
        #- containerPort: 9009
        #  name: clickhouse-replica
        - containerPort: 9363
          name: metrics
        volumeMounts:
        - name: clickhouse-config
          mountPath: /etc/clickhouse-server/config.xml
          subPath: config.xml
        - name: clickhouse-users
          mountPath: /etc/clickhouse-server/users.xml
          subPath: users.xml
        - name: clickhouse-data
          mountPath: /var/lib/clickhouse
      volumes:
      - name: clickhouse-config
        configMap:
          name: clickhouse-id01-etc-configmap
          #Add ConfigMap data to a specific path in the Volume
          items:
          - key: config.xml
            path: config.xml
      - name: clickhouse-users
        configMap:
          name: clickhouse-id01-etc-configmap
          #Add ConfigMap data to a specific path in the Volume
          items:
          - key: users.xml
            path: users.xml
  volumeClaimTemplates:
  - metadata:
      name: clickhouse-data
    spec:
      accessModes:
        - "ReadWriteOnce"
      #storageClassName: openebs-standard
      resources:
        requests:
          storage: "80Gi"
