# 默认的 sata-csi-udisk 是按小时计费的, 我们自定义一个按月计费的
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: sata-csi-udisk-pingcap-community
provisioner: udisk.csi.ucloud.cn #存储供应方，此处不可更改。
parameters:
  type: "sata"   # 存储介质，支持ssd和sata，必填
  fsType: "ext4"    # 文件系统，必填
  udataArkMode: "no"   # 是否开启方舟模式，默认不开启，非必填
  chargeType: "month" # 付费类型，支持dynamic、month、year,不填默认为按小时。
  quantity: "1" # 购买时长，dynamic无需填写，可购买1-9个月，或1-10年
reclaimPolicy: Delete  # PV回收策略，支持Delete和Retain，默认为Delete，非必填
volumeBindingMode: WaitForFirstConsumer   # 强烈建议配置该参数

---

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: community-search-es
  namespace: default
spec:
  selector:
    matchLabels:
      app: community-search-es
  serviceName: "community-search-es"
  replicas: 1
  template:
    metadata:
      labels:
        app: community-search-es
    spec:
      terminationGracePeriodSeconds: 10
      nodeSelector:
        topology.udisk.csi.ucloud.cn/region: cn-bj2
        topology.udisk.csi.ucloud.cn/zone: cn-bj2-02  # udisk zone must be same as node zone
      containers:
      - name: es
        image: registry.cn-hangzhou.aliyuncs.com/pingcap-ee/community-search-es:v2022-04-04
        imagePullPolicy: IfNotPresent
        env:
        - name: discovery.type
          value: single-node
        - name: xpack.security.enabled
          value: "false"
        livenessProbe:
          httpGet:
            path: /
            port: 9200
          periodSeconds: 10
          initialDelaySeconds: 3
          successThreshold: 1
          timeoutSeconds: 4
        ports:
        - containerPort: 9200
          protocol: TCP
        volumeMounts:
        - name: es-storage
          mountPath: /usr/share/elasticsearch/data
        resources:
          limits:
            cpu: "4"
            memory: 4Gi
          requests:
            cpu: "1"
            memory: 512Mi
      initContainers:
        - name: file-permission
          image: busybox:1.28
          command: ['chown', '-R', '1000:1000', '/usr/share/elasticsearch/']
          volumeMounts:
            - name: es-storage
              mountPath: /usr/share/elasticsearch/data
          securityContext:
            privileged: true
            runAsUser: 0
      imagePullSecrets:
      - name: aliyun-hangzhou-registry
  volumeClaimTemplates:
  - metadata:
      name: es-storage
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "sata-csi-udisk-pingcap-community"
      resources:
        requests:
          storage: 20Gi

---

apiVersion: v1
kind: Service
metadata:
  name: community-search-es-inner-ulb
  namespace: default
  labels:
    app: community-search-es
  annotations:
    service.beta.kubernetes.io/ucloud-load-balancer-type: "inner"
    service.beta.kubernetes.io/ucloud-load-balancer-id: "ulb-hd6qpdyzvko"
spec:
  type: LoadBalancer
  externalTrafficPolicy: Local
  ports:
    - protocol: TCP
      port: 9200
      targetPort: 9200
  selector:
    app: community-search-es

---

apiVersion: v1
kind: Service
metadata:
  name: community-search-es
  namespace: default
  labels:
    app: community-search-es
spec:
  ports:
  - port: 9200
    targetPort: 9200
    name: http
  clusterIP: None
  selector:
    app: community-search-es


---

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: community-search-es-v2
  namespace: default
spec:
  selector:
    matchLabels:
      app: community-search-es-v2
  serviceName: "community-search-es-v2"
  replicas: 1
  template:
    metadata:
      labels:
        app: community-search-es-v2
    spec:
      terminationGracePeriodSeconds: 10
      nodeSelector:
        topology.udisk.csi.ucloud.cn/region: cn-bj2
        topology.udisk.csi.ucloud.cn/zone: cn-bj2-02  # udisk zone must be same as node zone
      containers:
      - name: es
        image: registry.cn-hangzhou.aliyuncs.com/pingcap-ee/community-search-es:v8.18.3
        imagePullPolicy: IfNotPresent
        env:
        - name: discovery.type
          value: single-node
        - name: xpack.security.enabled
          value: "false"
        livenessProbe:
          httpGet:
            path: /
            port: 9200
          periodSeconds: 10
          initialDelaySeconds: 3
          successThreshold: 1
          timeoutSeconds: 4
        ports:
        - containerPort: 9200
          protocol: TCP
        volumeMounts:
        - name: es-storage-02
          mountPath: /usr/share/elasticsearch/data
        resources:
          limits:
            cpu: "4"
            memory: 4Gi
          requests:
            cpu: "1"
            memory: 512Mi
      initContainers:
        - name: file-permission
          image: busybox:1.28
          command: ['chown', '-R', '1000:1000', '/usr/share/elasticsearch/']
          volumeMounts:
            - name: es-storage-02
              mountPath: /usr/share/elasticsearch/data
          securityContext:
            privileged: true
            runAsUser: 0
      imagePullSecrets:
      - name: aliyun-hangzhou-registry
  volumeClaimTemplates:
  - metadata:
      name: es-storage-02
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "sata-csi-udisk-pingcap-community"
      resources:
        requests:
          storage: 20Gi

---

apiVersion: v1
kind: Service
metadata:
  name: community-search-es-v2
  namespace: default
  labels:
    app: community-search-es-v2
spec:
  ports:
  - port: 9200
    targetPort: 9200
    name: http
  clusterIP: None
  selector:
    app: community-search-es-v2
