k8s deployment通用模板

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {APP_NAME}-deployment
  labels:
    app: {APP_NAME}
    #version: v{IMAGE_TAG}
  namespace: depoly
spec:
  replicas: 1
  minReadySeconds: 30
  strategy:
    rollingUpdate:
      maxSurge: 3
      maxUnavailable: 0
  selector:
    matchLabels:
      app: {APP_NAME}
     # version: v{IMAGE_TAG}
  template:
    metadata:
      labels:
        app: {APP_NAME}
       # version: v{IMAGE_TAG}
      annotations:
        k8s.aliyun.com/eci-use-specs : {ECI_SPECS}   #指定ECI实例的vCPU和内存
        proxy.istio.io/config: '{ "terminationDrainDuration": 60s }'

#istio 提供了 terminationDrainDuration 这个连接优雅终止时长的自定义配置,表示 sleep 多长时间之后才强制杀死 envoy,默认是 5s,结合下面的terminationGracePeriodSeconds使用
    spec:
      terminationGracePeriodSeconds: 70 

#调整优雅终止时间,terminationGracePeriodSeconds 默认是30s。自己视情况而定(terminationGracePeriodSeconds 一定大于sleep的时间)


      containers:
      - name: {APP_NAME}
        image: registry.aliyuncs.com/{APP_NAME}:{IMAGE_TAG}
        lifecycle:
#          postStart:
#            exec: 
#              command:  ["/bin/sh", "-c", "echo nacos-update.sh > /usr/local/depoly/start.sh"]
          preStop:
            exec:
#              command:  ["/bin/sh", "-c", "/bin/sh /usr/local/depoly/offline.sh ; sleep 30; kill -15 1"]
              command:  ["/bin/sh", "-c", "/bin/sh /usr/local/depoly/offline.sh ; sleep 60 ; kill -15 1; while [ ! -f 'kill.conf' ]; do sleep 10 && echo 1 >>1.txt; done"]
        readinessProbe:
          timeoutSeconds: 5 
          failureThreshold: 5
          initialDelaySeconds: 50   #延迟检测时间
          periodSeconds: 10 
          exec:
            command:  ["/bin/sh", "-c", "/bin/sh /usr/local/depoly/nacos-update.sh "]
      
        ports:
        - containerPort: {APP_PORT}
        env:
          - name: SPRING_PROFILES_ACTIVE
            value: {SPRING_PROFILE}
          - name: TZ
            value: "Asia/Shanghai"
          - name: POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
     #   volumeMounts:
     #     - name: tz
     #       mountPath: /etc/localtime
     #       subPath: Shanghai
        resources:
          limits:
            cpu: {LIMITS_CPU}
            memory: {LIMITS_MEM}
          requests:
            cpu: {REQ_CPU}
            memory: {REQ_MEM}
        volumeMounts:
          - mountPath: /home/jvm
            name: pvc-jvm
      volumes:
        - name: tz
          configMap:
            name: tz
        - name: pvc-jvm
          persistentVolumeClaim:
            claimName: pvc-jvm
      imagePullSecrets:
      - name: registry-pull-secret

你可能感兴趣的:(kubernetes,kubernetes)