apiVersion: apps/v1
kind: Deployment
metadata:
  #命名规范:应用名称-版本
  name: example-web-v1
  namespace: default
  labels:
    app: example-web
spec:
  #保留历史版本数量
  revisionHistoryLimit: 3
  replicas: 1
  selector:
    matchLabels:
      #istio标签
      app: example-web
      version: v1
      #监控标签
      k8s-app: example-web
  #minReadySeconds: 60     #滚动升级时60s后认为该pod就绪
  strategy:
    rollingUpdate:  #由于replicas为3,则整个升级,pod个数在2-4个之间
      maxSurge: 1      #滚动升级时会先启动1个pod
      maxUnavailable: 1 #滚动升级时允许的最大Unavailable的pod个数
  template:
    metadata:
      labels:
        app: example-web
        version: v1
      #annotations:
        #disable istio sidecar injection
        #sidecar.istio.io/inject: "false"
        #Filebeat log collector
        #https://www.elastic.co/guide/en/beats/filebeat/master/configuration-autodiscover-hints.html#configuration-autodiscover-hints
        #co.elastic.logs/disable: 'true'
        #co.elastic.logs/module: nginx
        #co.elastic.logs/fileset.stdout: access
        #co.elastic.logs/fileset.stderr: error
        #Metricbeat metric collecor
        #co.elastic.metrics/module: nginx
        #co.elastic.metrics/metricsets: stubstatus
        #co.elastic.metrics/hosts: '${data.host}:80'
        #co.elastic.metrics/period: 10s
    spec:
      #nodeName: k8s.node1 #指定调度节点为k8s.node1
      #nodeName: virtual-kubelet
      #调度特定的节点,用于集群弹性伸缩
      #nodeSelector:
      #  kubernetes.io/role: agent
      #  beta.kubernetes.io/os: linux
      #  type: virtual-kubelet
      #tolerations:
      #- key: virtual-kubelet.io/provider
      #  operator: Exists
      #- key: alibabacloud.com/eci
      #  operator: "Exists"
      #  effect: NoSchedule
      terminationGracePeriodSeconds: 60 #k8s将会给应用发送SIGTERM信号，可以用来正确、优雅地关闭应用,默认为30秒
      #imagePullSecrets:
      #- name: registrykey-ali-ext
      securityContext:
        sysctls:
          #kubernetes >= v1.11 and kernel version >= 4.15 needed
          #- name: kernel.msgmax
          #  value: "65536"
          - name: net.ipv4.tcp_syncookies
            value: "0"
          - name: net.ipv4.ip_local_port_range
            value: "1024 65535"
          - name: net.core.somaxconn
            value: "65535"
          - name: net.ipv4.ip_unprivileged_port_start
            value: "0"
          - name: net.ipv4.tcp_tw_reuse
            value: "2"
          - name: net.ipv4.tcp_fin_timeout
            value: "20"
          - name: net.ipv4.tcp_keepalive_intvl
            value: "10"
          - name: net.ipv4.tcp_keepalive_probes
            value: "2"
          - name: net.ipv4.tcp_keepalive_time
            value: "120"
          - name: net.ipv4.tcp_ecn
            value: "1"
          - name: net.ipv4.tcp_max_syn_backlog
            value: "65536"
          - name: net.ipv4.tcp_rfc1337
            value: "1"
          - name: net.ipv4.tcp_slow_start_after_idle
            value: "0"
          - name: net.ipv4.tcp_fack
            value: "1"
          - name: net.ipv4.tcp_max_tw_buckets
            value: "1048576"
          - name: net.ipv4.tcp_fastopen
            value: "3"
          - name: net.ipv4.icmp_ratelimit
            value: "100"
          - name: net.ipv4.tcp_abort_on_overflow
            value: "1"
          - name: net.ipv4.tcp_adv_win_scale
            value: "2"
          - name: net.ipv4.tcp_retries2
            value: "8"
          - name: net.ipv4.tcp_syn_retries
            value: "3"
          - name: net.ipv4.tcp_synack_retries
            value: "2"
          - name: net.unix.max_dgram_qlen
            value: "512"
          - name: net.ipv4.tcp_fwmark_accept
            value: "1"
          - name: net.ipv4.fwmark_reflect
            value: "1"
      #Kubernetes-managed hosts file: /etc/hosts
      #hostAliases:
      #- ip: "127.0.0.1"
      #  hostnames:
      #  - "foo.local"
      #  - "bar.local"
      #- ip: "10.1.2.3"
      #  hostnames:
      #  - "foo.remote"
      #  - "bar.remote"
      containers:
      - name: example-web
        image: registry.cn-beijing.aliyuncs.com/example/example_web:${BUILD_NUMBER}
        #command:
        #- /cmd
        #- --cpu=100m
        #- --extra-cpu=2m
        #- --memory=150Mi
        #- --extra-memory=30Mi
        #args:
        #- -conf
        #- /etc/app.conf
        imagePullPolicy: Always
        livenessProbe: #kubernetes认为该pod是存活的,不存活则需要重启
          httpGet:
            path: /
            port: 80
            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: 80
            scheme: HTTP
          initialDelaySeconds: 30 ## equals to minimum startup time of the application
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
        resources:
          requests:
            cpu: 50m
            memory: 64Mi
          limits:
            cpu: 500m
            #nvidia.com/gpu: 1
            memory: 512Mi
        securityContext:
          #allowPrivilegeEscalation: false
          capabilities: {}
          privileged: false
          #runAsUser: 1000
          #fsGroup: 1000
        env:
          - name: PROFILE
            value: "test"
          #log collector with aliyun log-pilot
          #- name: aliyun_logs_catalina
          #  value: "stdout"
          #- name: aliyun_logs_access
          #  value: "/usr/local/tomcat/logs/localhost_access_log.*.txt"
        ports:
        #监控端口
        - containerPort: 9180
          name: metrics
          protocol: TCP
        - containerPort: 8080
          name: web
          protocol: TCP
        #log collector with aliyun log-pilot
        volumeMounts:
          - name: log
            mountPath: /usr/local/tomcat/logs
           #mountPropagation: HostToContainer
      volumes:
      - name: log
        emptyDir: {}
