gateway-deployment.yaml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: shop-recycle-gateway
  5. namespace: default
  6. labels:
  7. app: shop-recycle-gateway
  8. service: gateway
  9. version: "1.0.0"
  10. spec:
  11. replicas: 2 # 根据环境调整:dev=1, staging=2, prod=3
  12. strategy:
  13. type: RollingUpdate
  14. rollingUpdate:
  15. maxSurge: 1
  16. maxUnavailable: 0
  17. selector:
  18. matchLabels:
  19. app: shop-recycle-gateway
  20. template:
  21. metadata:
  22. labels:
  23. app: shop-recycle-gateway
  24. service: gateway
  25. version: "1.0.0"
  26. annotations:
  27. prometheus.io/scrape: "true"
  28. prometheus.io/port: "1211"
  29. prometheus.io/path: "/actuator/prometheus"
  30. spec:
  31. containers:
  32. - name: shop-recycle-gateway
  33. image: shop-recycle-gateway:1.0.0 # 使用本地镜像或修改为完整镜像路径
  34. imagePullPolicy: IfNotPresent
  35. # 端口配置
  36. ports:
  37. - name: http
  38. containerPort: 1211
  39. protocol: TCP
  40. - name: sentinel
  41. containerPort: 8005
  42. protocol: TCP
  43. # 环境变量
  44. env:
  45. - name: JAVA_OPTS
  46. value: "-Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Xss256k -XX:+DisableExplicitGC"
  47. - name: TZ
  48. value: "Asia/Shanghai"
  49. # Redis 凭证(从 common-redis-credentials Secret)
  50. - name: REDIS_PASSWORD
  51. valueFrom:
  52. secretKeyRef:
  53. name: common-redis-credentials
  54. key: redis-password
  55. - name: REDIS_DATABASE
  56. valueFrom:
  57. secretKeyRef:
  58. name: common-redis-credentials
  59. key: redis-database
  60. # 挂载配置文件
  61. volumeMounts:
  62. - name: config-volume
  63. mountPath: /app/conf
  64. readOnly: true
  65. # 资源限制
  66. resources:
  67. requests:
  68. cpu: 250m
  69. memory: 512Mi
  70. limits:
  71. cpu: 1000m
  72. memory: 1024Mi
  73. # 健康检查 - 就绪检查
  74. readinessProbe:
  75. httpGet:
  76. path: /actuator/health/readiness
  77. port: http
  78. scheme: HTTP
  79. initialDelaySeconds: 30
  80. periodSeconds: 10
  81. timeoutSeconds: 5
  82. successThreshold: 1
  83. failureThreshold: 3
  84. # 健康检查 - 存活检查
  85. livenessProbe:
  86. httpGet:
  87. path: /actuator/health/liveness
  88. port: http
  89. scheme: HTTP
  90. initialDelaySeconds: 60
  91. periodSeconds: 15
  92. timeoutSeconds: 5
  93. successThreshold: 1
  94. failureThreshold: 3
  95. # 启动检查(K8S 1.16+)
  96. startupProbe:
  97. httpGet:
  98. path: /actuator/health
  99. port: http
  100. scheme: HTTP
  101. initialDelaySeconds: 0
  102. periodSeconds: 5
  103. timeoutSeconds: 3
  104. successThreshold: 1
  105. failureThreshold: 30 # 最多等待 30*5=150 秒启动
  106. # 生命周期钩子
  107. lifecycle:
  108. preStop:
  109. exec:
  110. command: ["/bin/sh", "-c", "sleep 15"] # 优雅关闭延迟
  111. # 配置卷
  112. volumes:
  113. - name: config-volume
  114. configMap:
  115. name: shop-recycle-gateway-config
  116. items:
  117. - key: application.yml
  118. path: application.yml
  119. - key: application.properties
  120. path: application.properties
  121. # Pod 调度策略
  122. affinity:
  123. podAntiAffinity:
  124. preferredDuringSchedulingIgnoredDuringExecution:
  125. - weight: 100
  126. podAffinityTerm:
  127. labelSelector:
  128. matchExpressions:
  129. - key: app
  130. operator: In
  131. values:
  132. - shop-recycle-gateway
  133. topologyKey: kubernetes.io/hostname
  134. # 容忍污点
  135. tolerations:
  136. - key: "apps"
  137. operator: "Equal"
  138. value: "true"
  139. effect: "NoSchedule"
  140. # 安全上下文
  141. securityContext:
  142. runAsNonRoot: false
  143. runAsUser: 0
  144. # 终止宽限期(等待优雅关闭的时间)
  145. terminationGracePeriodSeconds: 30