deployment.go 2.4 KB

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