修改 deployment 配置

以 user-admin 的配置文件为例

kind: Deployment
apiVersion: apps/v1
metadata:
  name: user-admin-deploy
  labels:
    app: user-admin
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: >
      {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{"kubesphere.io/alias-name":"用户管理服务","kubesphere.io/description":"用户管理服务"},"labels":{"app":"user-admin"},"name":"user-admin-deploy","namespace":"dw-test"},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"user-admin"}},"template":{"metadata":{"labels":{"app":"user-admin"}},"spec":{"containers":[{"env":[{"name":"SPRING_PROFILES_ACTIVE","value":"test"},{"name":"SPRING_CLOUD_NACOS_SERVER-ADDR","valueFrom":{"configMapKeyRef":{"key":"spring.cloud.nacos.server-addr","name":"nacos-config"}}},{"name":"SPRING_CLOUD_NACOS_CONFIG_NAMESPACE","valueFrom":{"configMapKeyRef":{"key":"spring.cloud.nacos.namespace","name":"nacos-config"}}},{"name":"SPRING_CLOUD_NACOS_DISCOVERY_NAMESPACE","valueFrom":{"configMapKeyRef":{"key":"spring.cloud.nacos.namespace","name":"nacos-config"}}}],"image":"aiban-docker.pkg.coding.net/dongyangxiangmu/dongyang/user-admin:latest","imagePullPolicy":"Always","name":"user-admin","ports":[{"containerPort":8080}]}],"imagePullSecrets":[{"name":"coding-registry-cred"}]}}}}
    kubesphere.io/alias-name: 用户管理服务
    kubesphere.io/description: 用户管理服务
    kubesphere.io/relatedHPA: user-admin-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: user-admin
  template:
    metadata:
      labels:
        app: user-admin
    spec:
      volumes:
        - name: host-time
          hostPath:
            path: /etc/localtime
            type: ''
      containers:
        - name: user-admin
          image: >-
            docker.pkg.coding.net/test/user-admin:test
          ports:
            - name: http-8080
              containerPort: 8080
              protocol: TCP
            # 应用管理端口
            - name: management-port
              containerPort: 50000
              protocol: TCP
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: test
            - name: SPRING_CLOUD_NACOS_SERVER-ADDR
              valueFrom:
                configMapKeyRef:
                  name: nacos-config
                  key: spring.cloud.nacos.server-addr
            - name: SPRING_CLOUD_NACOS_CONFIG_NAMESPACE
              valueFrom:
                configMapKeyRef:
                  name: nacos-config
                  key: spring.cloud.nacos.namespace
            - name: SPRING_CLOUD_NACOS_DISCOVERY_NAMESPACE
              valueFrom:
                configMapKeyRef:
                  name: nacos-config
                  key: spring.cloud.nacos.namespace
            - name: JAVA_TOOL_OPTIONS
              value: >-
                -Xms256M -Xmx512M -XX:+PrintGCDetails -XX:+PrintGCTimeStamps
                -XX:GCLogFileSize=20m -XX:+HeapDumpOnOutOfMemoryError
                -XX:HeapDumpPath=/logs/heaperror.log -Xloggc:/logs/gcerror.log
          resources:
            limits:
              cpu: '2'
              memory: 2Gi
            requests:
              cpu: 100m
              memory: 200Mi
          volumeMounts:
            - name: host-time
              readOnly: true
              mountPath: /etc/localtime
          # 存活探针
          livenessProbe:
            httpGet:
              path: /actuator/health/liveness
              port: 50000
              scheme: HTTP
            initialDelaySeconds: 30
            timeoutSeconds: 1
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 6
          # 就绪探针
          readinessProbe:
            httpGet:
              path: /actuator/health/readiness
              port: 50000
              scheme: HTTP
            initialDelaySeconds: 30
            timeoutSeconds: 1
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 9
          # 启动探针
          startupProbe:
            httpGet:
              path: /actuator/health
              port: 50000
              scheme: HTTP
            initialDelaySeconds: 10
            timeoutSeconds: 1
            periodSeconds: 5
            successThreshold: 1
            failureThreshold: 60
          lifecycle:
            # 结束回调钩子
            preStop:
              exec:
                command:
                  - curl
                  - '-XPOST'
                  - '127.0.0.1:50000/actuator/shutdown'
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: Always
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      imagePullSecrets:
        - name: coding-registry-cred
      affinity:
        # 分散节点部署
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app: user-admin
                topologyKey: kubernetes.io/hostname
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
配置修改汇总
  • 设置调度策略,采取多主机/多可用区部署
  • 设置管理端口,management-port
  • 设置就绪探针 readinessProbe 、 存活探针 livenessProbe、启动探针 startupProbe
  • 停机回调钩子 preStop
调度策略

管理端口

就绪探针

存活探针

设置自动伸缩

作者:Jeebiz  创建时间:2023-02-18 21:48
最后编辑:Jeebiz  更新时间:2024-08-02 14:28