apiVersion: apps/v1
kind: Deployment
metadata:
  #命名规范:应用名称-版本
  name: nodejs-v2
  namespace: default
  labels:
    app: nodejs
spec:
  #保留历史版本数量
  revisionHistoryLimit: 3
  replicas: 1
  selector:
    matchLabels:
      app: nodejs
      version: v2
#  minReadySeconds: 60     #滚动升级时60s后认为该pod就绪
  strategy:
    rollingUpdate:  ##由于replicas为3,则整个升级,pod个数在2-4个之间
      maxSurge: 1      #滚动升级时会先启动1个pod
      maxUnavailable: 1 #滚动升级时允许的最大Unavailable的pod个数
  template:
    metadata:
      labels:
        app: nodejs
        version: v2
      annotations:
        #enable istio sidecar injection
        sidecar.istio.io/inject: "true"
    spec:
      terminationGracePeriodSeconds: 60 ##k8s将会给应用发送SIGTERM信号，可以用来正确、优雅地关闭应用,默认为30秒
      #imagePullSecrets:
      #- name: registrykey-ali-ext
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                    - nodejs
              topologyKey: "kubernetes.io/hostname"
      containers:
      - name: nodejs
        #image: registry.cn-beijing.aliyuncs.com/example/example_web:${BUILD_NUMBER}
        image: slpcat/node-web-app
        imagePullPolicy: Always
        livenessProbe: #kubernetes认为该pod是存活的,不存活则需要重启
          httpGet:
            path: /
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 60 ## equals to the maximum startup time of the application + couple of seconds
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
        readinessProbe: #kubernetes认为该pod是启动成功的
          httpGet:
            path: /
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 30 ## equals to minimum startup time of the application
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
        resources:
          # keep request = limit to keep this container in guaranteed class
          requests:
            cpu: 500m
            memory: 512Mi
          limits:
            cpu: 4
            memory: 8Gi
        env:
          - name: aliyun_logs_catalina
            value: "stdout"
          - name: aliyun_logs_access
            value: "/usr/local/tomcat/logs/localhost_access_log*.txt"
        ports:
          - name: http
            containerPort: 8080
        volumeMounts:
          - name: log
            mountPath: /usr/local/tomcat/logs
           #mountPropagation: HostToContainer
      volumes:
      - name: log
        emptyDir: {}
