apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-deployment
  namespace: v2
  labels:
    app: api
spec:
  progressDeadlineSeconds: 600
  revisionHistoryLimit: 10
  replicas: 1
  selector:
    matchLabels:
      app: api
  # 更新策略
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - env:
            - name: LIMIT_CPU
              valueFrom:
                resourceFieldRef:
                  divisor: 1m
                  resource: limits.cpu
            - name: LIMIT_MEM
              valueFrom:
                resourceFieldRef:
                  divisor: 1Mi
                  resource: limits.memory
            - name: REQUEST_CPU
              valueFrom:
                resourceFieldRef:
                  divisor: 1m
                  resource: requests.cpu
            - name: REQUEST_MEM
              valueFrom:
                resourceFieldRef:
                  divisor: 1Mi
                  resource: requests.memory
            - name: INTERVAL
              value: '1'
          name: api
          image: myservice:v1.1
          imagePullPolicy: Always
          ports:
            - containerPort: 23341
              name: serial
              protocol: TCP
            - containerPort: 55555
              name: analyze
              protocol: TCP
          # 存活检测
          livenessProbe:
            failureThreshold: 3
            initialDelaySeconds: 15
            periodSeconds: 10
            successThreshold: 1
            tcpSocket:
              port: 23333
            timeoutSeconds: 1
          # 就绪检测
          readinessProbe:
            failureThreshold: 5
            initialDelaySeconds: 1
            periodSeconds: 1
            successThreshold: 1
            tcpSocket:
              port: 23333
            timeoutSeconds: 1
          # 资源限制
          resources:
            requests:
              cpu: 250m
              memory: 512Mi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /var/log/vaptcha/api
              name: volume-emptyDir
            - mountPath: /conf
              name: volume-cm-api
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      serviceAccount: grpclb-sa
      serviceAccountName: grpclb-sa
      terminationGracePeriodSeconds: 30
      volumes:
          - emptyDir: { }
            name: volume-emptyDir
          - configMap:
              defaultMode: 420
              name: api
            name: volume-cm-api
