apiVersion: apps/v1
kind: Deployment
metadata:
  #命名规范:应用名称-版本
  name: tomcat8-v2
  namespace: default
  labels:
    app: tomcat8
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tomcat8
      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: tomcat8
        version: v2
      annotations:
        #enable istio sidecar injection
        sidecar.istio.io/inject: "true"
    spec:
      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"
      containers:
      - name: tomcat8
        #image: registry.cn-beijing.aliyuncs.com/example/example_web:${BUILD_NUMBER}
        image: slpcat/tomcat8:alpine-8.5
        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: JAVA_OPTS
            value: "-server -Djava.awt.headless=true -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.EPollSelectorProvider -Dorg.apache.tomcat.sendfile.support=true -Xverify:none -XX:MetaspaceSize=128m -XX:+UseNUMA -XX:+UseNUMAInterleaving -XX:NUMAInterleaveGranularity=65536 -XX:+UseLargePages -XX:+UseCompressedOops -XX:MaxMetaspaceSize=512m -XX:ReservedCodeCacheSize=240M -XX:MaxRAMFraction=2 -XshowSettings:vm -XX:+AggressiveOpts -Djute.maxbuffer=41943040 -XX:-UseBiasedLocking -XX:+UseFastAccessorMethods -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:+UseCompressedOops -XX:+CMSClassUnloadingEnabled  -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrent -XX:SoftRefLRUPolicyMSPerMB=0 -XX:G1ReservePercent=25 -XX:G1NewSizePercent=10 -XX:G1MaxNewSizePercent=25 -XX:MaxGCPauseMillis=20 -XX:-OmitStackTraceInFastThrow -XX:+ParallelRefProcEnabled -XX:ParallelGCThreads=8 -XX:MaxTenuringThreshold=1 -XX:G1HeapWastePercent=10 -XX:SurvivorRatio=8 -XX:G1MixedGCCountTarget=16 -XX:G1MixedGCLiveThresholdPercent=90 -XX:InitiatingHeapOccupancyPercent=35 -XX:G1HeapRegionSize=32m -XX:+PerfDisableSharedMem -XX:-ResizePLAB"
          - 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: {}
