_helpers.tpl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. {{/*
  2. Base service template
  3. */}}
  4. {{- define "base.service" -}}
  5. apiVersion: v1
  6. kind: Service
  7. metadata:
  8. name: {{ .Values.app.name }}
  9. labels:
  10. app: {{ .Values.app.name }}
  11. spec:
  12. type: {{ .Values.service.type }}
  13. ports:
  14. - port: {{ .Values.service.port }}
  15. targetPort: http
  16. protocol: TCP
  17. name: http
  18. selector:
  19. app: {{ .Values.app.name }}
  20. {{- if .Values.service.dubbo_port }}
  21. ---
  22. # Headless Service for Dubbo RPC
  23. apiVersion: v1
  24. kind: Service
  25. metadata:
  26. name: {{ .Values.app.name }}-dubbo
  27. labels:
  28. app: {{ .Values.app.name }}
  29. spec:
  30. type: ClusterIP
  31. clusterIP: None # Headless Service
  32. ports:
  33. - port: {{ .Values.service.dubbo_port }}
  34. targetPort: dubbo
  35. protocol: TCP
  36. name: dubbo
  37. selector:
  38. app: {{ .Values.app.name }}
  39. {{- end }}
  40. {{- end }}
  41. {{/*
  42. Base deployment template
  43. */}}
  44. {{- define "base.deployment" -}}
  45. apiVersion: apps/v1
  46. kind: Deployment
  47. metadata:
  48. name: {{ .Values.app.name }}
  49. labels:
  50. app: {{ .Values.app.name }}
  51. spec:
  52. revisionHistoryLimit: {{ .Values.revisionHistoryLimit | default 3 }}
  53. replicas: {{ .Values.replicaCount | default 1 }}
  54. selector:
  55. matchLabels:
  56. app: {{ .Values.app.name }}
  57. template:
  58. metadata:
  59. labels:
  60. app: {{ .Values.app.name }}
  61. spec:
  62. containers:
  63. - name: {{ .Values.app.name }}
  64. image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
  65. imagePullPolicy: {{ .Values.image.pullPolicy | default "IfNotPresent" }}
  66. ports:
  67. - containerPort: {{ .Values.service.targetPort | default 8080 }}
  68. name: http
  69. protocol: TCP
  70. {{- if .Values.service.dubbo_port }}
  71. - containerPort: {{ .Values.service.dubbo_port }}
  72. name: dubbo
  73. protocol: TCP
  74. {{- end }}
  75. {{- if .Values.livenessProbe }}
  76. livenessProbe:
  77. httpGet:
  78. path: {{ .Values.livenessProbe.path | default "/actuator/health" }}
  79. port: {{ .Values.service.targetPort | default 8080 }}
  80. initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds | default 30 }}
  81. periodSeconds: {{ .Values.livenessProbe.periodSeconds | default 10 }}
  82. {{- end }}
  83. {{- if .Values.readinessProbe }}
  84. readinessProbe:
  85. httpGet:
  86. path: {{ .Values.readinessProbe.path | default "/actuator/health" }}
  87. port: {{ .Values.service.targetPort | default 8080 }}
  88. initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds | default 10 }}
  89. periodSeconds: {{ .Values.readinessProbe.periodSeconds | default 5 }}
  90. {{- end }}
  91. resources:
  92. limits:
  93. cpu: {{ .Values.resources.limits.cpu | default "500m" }}
  94. memory: {{ .Values.resources.limits.memory | default "512Mi" }}
  95. requests:
  96. cpu: {{ .Values.resources.requests.cpu | default "250m" }}
  97. memory: {{ .Values.resources.requests.memory | default "256Mi" }}
  98. volumeMounts:
  99. - name: config-volume
  100. mountPath: /etc/config
  101. env:
  102. - name: SPRING_CLOUD_NACOS_DISCOVERY_SERVER_ADDR
  103. value: "nacos.bak.com:8848"
  104. - name: SPRING_CLOUD_NACOS_CONFIG_SERVER_ADDR
  105. value: "nacos.bak.com:8848"
  106. {{- if .Values.service.dubbo_port }}
  107. - name: DUBBO_PROTOCOL_PORT
  108. value: "{{ .Values.service.dubbo_port }}"
  109. - name: DUBBO_REGISTRY_ADDRESS
  110. value: "nacos://nacos.bak.com:8848?namespace=public"
  111. {{- end }}
  112. volumes:
  113. - name: config-volume
  114. configMap:
  115. name: {{ .Values.app.name }}-config
  116. {{- end }}
  117. {{/*
  118. Base ConfigMap template
  119. */}}
  120. {{- define "base.configmap" -}}
  121. apiVersion: v1
  122. kind: ConfigMap
  123. metadata:
  124. name: {{ .Values.app.name }}-config
  125. labels:
  126. app: {{ .Values.app.name }}
  127. data:
  128. application.yml: |
  129. {{ .Values.config.yml | toYaml | indent 4 }}
  130. {{- end }}