apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: snowflake
  namespace: juwan
  labels:
    app: snowflake
spec:
  replicas: 3
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      app: snowflake
  template:
    metadata:
      labels:
        app: snowflake
    spec:
      serviceAccountName: find-endpoints
      containers:
        - name: snowflake
#          image: 103.236.53.208:4418/library/snowflake@sha256:1679cf94b69f426eec5d2f960ffb153bb7dbcd3bcaf0286261a43756384a86b3
          image: snowflake:latest
          ports:
            - containerPort: 8080
          readinessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 10
          livenessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 15
            periodSeconds: 20
          resources:
            requests:
              cpu: 500m
              memory: 512Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
          volumeMounts:
            - name: timezone
              mountPath: /etc/localtime
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai

---
apiVersion: v1
kind: Service
metadata:
  name: snowflake-svc
  namespace: juwan
spec:
  ports:
    - port: 8080
      targetPort: 8080
  selector:
    app: snowflake

---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: snowflake-hpa-c
  namespace: juwan
  labels:
    app: snowflake-hpa-c
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: StatefulSet
    name: snowflake
  minReplicas: 3
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 80

---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: snowflake-hpa-m
  namespace: juwan
  labels:
    app: snowflake-hpa-m
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: StatefulSet
    name: snowflake
  minReplicas: 3
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: 80
