apirpc.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package k8s
  2. var apiRpcTmeplate = `apiVersion: apps/v1beta2
  3. kind: Deployment
  4. metadata:
  5. name: {{.name}}
  6. namespace: {{.namespace}}
  7. labels:
  8. app: {{.name}}
  9. spec:
  10. replicas: {{.replicas}}
  11. revisionHistoryLimit: {{.revisionHistoryLimit}}
  12. selector:
  13. matchLabels:
  14. app: {{.name}}
  15. template:
  16. metadata:
  17. labels:
  18. app: {{.name}}
  19. spec:{{if .envIsDev}}
  20. terminationGracePeriodSeconds: 60{{end}}
  21. containers:
  22. - name: {{.name}}
  23. image: registry-vpc.cn-hangzhou.aliyuncs.com/{{.namespace}}/
  24. 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. env:
  41. - name: aliyun_logs_k8slog
  42. value: "stdout"
  43. - name: aliyun_logs_k8slog_tags
  44. value: "stage={{.env}}"
  45. - name: aliyun_logs_k8slog_format
  46. value: "json"
  47. resources:
  48. limits:
  49. cpu: {{.limitCpu}}m
  50. memory: {{.limitMem}}Mi
  51. requests:
  52. cpu: {{.requestCpu}}m
  53. memory: {{.requestMem}}Mi
  54. command:
  55. - ./{{.serviceName}}
  56. - -f
  57. - ./{{.name}}.json
  58. volumeMounts:
  59. - name: timezone
  60. mountPath: /etc/localtime
  61. imagePullSecrets:
  62. - name: {{.namespace}}
  63. volumes:
  64. - name: timezone
  65. hostPath:
  66. path: /usr/share/zoneinfo/Asia/Shanghai
  67. ---
  68. apiVersion: v1
  69. kind: Service
  70. metadata:
  71. name: {{.name}}-svc
  72. namespace: {{.namespace}}
  73. spec:
  74. ports:
  75. - nodePort: 3{{.port}}
  76. port: {{.port}}
  77. protocol: TCP
  78. targetPort: {{.port}}
  79. selector:
  80. app: {{.name}}
  81. sessionAffinity: None
  82. type: NodePort{{if .envIsPreOrPro}}
  83. ---
  84. apiVersion: autoscaling/v2beta1
  85. kind: HorizontalPodAutoscaler
  86. metadata:
  87. name: {{.name}}-hpa-c
  88. namespace: {{.namespace}}
  89. labels:
  90. app: {{.name}}-hpa-c
  91. spec:
  92. scaleTargetRef:
  93. apiVersion: apps/v1beta1
  94. kind: Deployment
  95. name: di-api
  96. minReplicas: {{.minReplicas}}
  97. maxReplicas: {{.maxReplicas}}
  98. metrics:
  99. - type: Resource
  100. resource:
  101. name: cpu
  102. targetAverageUtilization: 80
  103. ---
  104. apiVersion: autoscaling/v2beta1
  105. kind: HorizontalPodAutoscaler
  106. metadata:
  107. name: {{.name}}-hpa-m
  108. namespace: {{.namespace}}
  109. labels:
  110. app: {{.name}}-hpa-m
  111. spec:
  112. scaleTargetRef:
  113. apiVersion: apps/v1beta1
  114. kind: Deployment
  115. name: {{.name}}
  116. minReplicas: {{.minReplicas}}
  117. maxReplicas: {{.maxReplicas}}
  118. metrics:
  119. - type: Resource
  120. resource:
  121. name: memory
  122. targetAverageUtilization: 80{{end}}`