deployment.tpl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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}}ports:
  25. - containerPort: {{.Port}}
  26. readinessProbe:
  27. tcpSocket:
  28. port: {{.Port}}
  29. initialDelaySeconds: 5
  30. periodSeconds: 10
  31. livenessProbe:
  32. tcpSocket:
  33. port: {{.Port}}
  34. initialDelaySeconds: 15
  35. periodSeconds: 20
  36. resources:
  37. requests:
  38. cpu: {{.RequestCpu}}m
  39. memory: {{.RequestMem}}Mi
  40. limits:
  41. cpu: {{.LimitCpu}}m
  42. memory: {{.LimitMem}}Mi
  43. volumeMounts:
  44. - name: timezone
  45. mountPath: /etc/localtime
  46. {{if .Secret}}imagePullSecrets:
  47. - name: {{.Secret}}
  48. {{end}}volumes:
  49. - name: timezone
  50. hostPath:
  51. path: /usr/share/zoneinfo/Asia/Shanghai
  52. ---
  53. apiVersion: v1
  54. kind: Service
  55. metadata:
  56. name: {{.Name}}-svc
  57. namespace: {{.Namespace}}
  58. spec:
  59. ports:
  60. {{if .UseNodePort}}- nodePort: {{.NodePort}}
  61. port: {{.Port}}
  62. protocol: TCP
  63. targetPort: {{.Port}}
  64. type: NodePort{{else}}- port: {{.Port}}{{end}}
  65. selector:
  66. app: {{.Name}}
  67. ---
  68. apiVersion: autoscaling/v2beta1
  69. kind: HorizontalPodAutoscaler
  70. metadata:
  71. name: {{.Name}}-hpa-c
  72. namespace: {{.Namespace}}
  73. labels:
  74. app: {{.Name}}-hpa-c
  75. spec:
  76. scaleTargetRef:
  77. apiVersion: apps/v1
  78. kind: Deployment
  79. name: {{.Name}}
  80. minReplicas: {{.MinReplicas}}
  81. maxReplicas: {{.MaxReplicas}}
  82. metrics:
  83. - type: Resource
  84. resource:
  85. name: cpu
  86. targetAverageUtilization: 80
  87. ---
  88. apiVersion: autoscaling/v2beta1
  89. kind: HorizontalPodAutoscaler
  90. metadata:
  91. name: {{.Name}}-hpa-m
  92. namespace: {{.Namespace}}
  93. labels:
  94. app: {{.Name}}-hpa-m
  95. spec:
  96. scaleTargetRef:
  97. apiVersion: apps/v1
  98. kind: Deployment
  99. name: {{.Name}}
  100. minReplicas: {{.MinReplicas}}
  101. maxReplicas: {{.MaxReplicas}}
  102. metrics:
  103. - type: Resource
  104. resource:
  105. name: memory
  106. targetAverageUtilization: 80