deployment.tpl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: {{.Name}}
  5. namespace: {{.Namespace}}
  6. labels:
  7. app: {{.Name}}
  8. spec:
  9. replicas: {{.Replicas}}
  10. revisionHistoryLimit: {{.Revisions}}
  11. selector:
  12. matchLabels:
  13. app: {{.Name}}
  14. template:
  15. metadata:
  16. labels:
  17. app: {{.Name}}
  18. spec:{{if .ServiceAccount}}
  19. serviceAccountName: {{.ServiceAccount}}{{end}}
  20. containers:
  21. - name: {{.Name}}
  22. image: {{.Image}}
  23. {{if .ImagePullPolicy}}imagePullPolicy: {{.ImagePullPolicy}}
  24. {{end}}lifecycle:
  25. preStop:
  26. exec:
  27. command: ["sh","-c","sleep 5"]
  28. ports:
  29. - containerPort: {{.Port}}
  30. readinessProbe:
  31. tcpSocket:
  32. port: {{.Port}}
  33. initialDelaySeconds: 5
  34. periodSeconds: 10
  35. livenessProbe:
  36. tcpSocket:
  37. port: {{.Port}}
  38. initialDelaySeconds: 15
  39. periodSeconds: 20
  40. resources:
  41. requests:
  42. cpu: {{.RequestCpu}}m
  43. memory: {{.RequestMem}}Mi
  44. limits:
  45. cpu: {{.LimitCpu}}m
  46. memory: {{.LimitMem}}Mi
  47. volumeMounts:
  48. - name: timezone
  49. mountPath: /etc/localtime
  50. {{if .Secret}}imagePullSecrets:
  51. - name: {{.Secret}}
  52. {{end}}volumes:
  53. - name: timezone
  54. hostPath:
  55. path: /usr/share/zoneinfo/Asia/Shanghai
  56. ---
  57. apiVersion: v1
  58. kind: Service
  59. metadata:
  60. name: {{.Name}}-svc
  61. namespace: {{.Namespace}}
  62. spec:
  63. ports:
  64. {{if .UseNodePort}}- nodePort: {{.NodePort}}
  65. port: {{.Port}}
  66. protocol: TCP
  67. targetPort: {{.Port}}
  68. type: NodePort{{else}}- port: {{.Port}}{{end}}
  69. selector:
  70. app: {{.Name}}
  71. ---
  72. apiVersion: autoscaling/v2beta1
  73. kind: HorizontalPodAutoscaler
  74. metadata:
  75. name: {{.Name}}-hpa-c
  76. namespace: {{.Namespace}}
  77. labels:
  78. app: {{.Name}}-hpa-c
  79. spec:
  80. scaleTargetRef:
  81. apiVersion: apps/v1
  82. kind: Deployment
  83. name: {{.Name}}
  84. minReplicas: {{.MinReplicas}}
  85. maxReplicas: {{.MaxReplicas}}
  86. metrics:
  87. - type: Resource
  88. resource:
  89. name: cpu
  90. targetAverageUtilization: 80
  91. ---
  92. apiVersion: autoscaling/v2beta1
  93. kind: HorizontalPodAutoscaler
  94. metadata:
  95. name: {{.Name}}-hpa-m
  96. namespace: {{.Namespace}}
  97. labels:
  98. app: {{.Name}}-hpa-m
  99. spec:
  100. scaleTargetRef:
  101. apiVersion: apps/v1
  102. kind: Deployment
  103. name: {{.Name}}
  104. minReplicas: {{.MinReplicas}}
  105. maxReplicas: {{.MaxReplicas}}
  106. metrics:
  107. - type: Resource
  108. resource:
  109. name: memory
  110. targetAverageUtilization: 80