apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: $JAVA_MODEL
  name: $JAVA_MODEL
  namespace: $DOCKERHUB_NAMESPACE   #一定要写名称空间 由jenkinsfile通过sed命令替换
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      app: $JAVA_MODEL
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: $JAVA_MODEL
    spec:
      imagePullSecrets:
        - name: $DOCKER_CREDENTIAL_ID  #提前在k8s的DevOps项目下配置访问镜像服务的账号密码
      containers:
        - image: $REGISTRY/$DOCKERHUB_NAMESPACE/$DOCKERHUB_NAMESPACE:$JAVA_MODEL-$SNAPSHOT-v$BUILD_NUMBER #$开头的都将在cicd中通过sed指令替换
          readinessProbe:
            httpGet:
              path: /actuator/health
              port: $SERVER_PORT
            timeoutSeconds: 30
            failureThreshold: 30
            periodSeconds: 20
          imagePullPolicy: Always
          name: app
          ports:
            - containerPort: $SERVER_PORT
              protocol: TCP
          resources:
            requests: #资源请求的设置
              memory: 1024Mi     #内存清楚，容器启动的初始可用数量
            limits:
              memory: 1024Mi
          volumeMounts:
            - mountPath: /home/heyu/logs
              name: api-logs
            - name: host-time
              readOnly: true
              mountPath: /etc/localtime
          terminationMessagePath: /nfs/data/heyu/api/logs
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      volumes:
        - name: api-logs
          hostPath:
            path: /nfs/data/heyu/api/logs
        - name: host-time
          hostPath:
            path: /etc/localtime
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: $JAVA_MODEL
  name: $JAVA_MODEL
  namespace: $DOCKERHUB_NAMESPACE
spec:
  ports:
    - name: http
      port: $SERVER_PORT
      protocol: TCP
      targetPort: $SERVER_PORT
  selector:
    app: $JAVA_MODEL
  sessionAffinity: None
  type: ClusterIP
