svc.yaml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: {{ include "mysql.primary.fullname" . }}
  5. namespace: {{ include "common.names.namespace" . | quote }}
  6. labels: {{- include "common.labels.standard" . | nindent 4 }}
  7. app.kubernetes.io/component: primary
  8. {{- if .Values.commonLabels }}
  9. {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
  10. {{- end }}
  11. annotations:
  12. {{- if .Values.commonAnnotations }}
  13. {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  14. {{- end }}
  15. {{- if .Values.primary.service.annotations }}
  16. {{- include "common.tplvalues.render" ( dict "value" .Values.primary.service.annotations "context" $ ) | nindent 4 }}
  17. {{- end }}
  18. spec:
  19. type: {{ .Values.primary.service.type }}
  20. {{- if and .Values.primary.service.clusterIP (eq .Values.primary.service.type "ClusterIP") }}
  21. clusterIP: {{ .Values.primary.service.clusterIP }}
  22. {{- end }}
  23. {{- if .Values.primary.service.sessionAffinity }}
  24. sessionAffinity: {{ .Values.primary.service.sessionAffinity }}
  25. {{- end }}
  26. {{- if .Values.primary.service.sessionAffinityConfig }}
  27. sessionAffinityConfig: {{- include "common.tplvalues.render" (dict "value" .Values.primary.service.sessionAffinityConfig "context" $) | nindent 4 }}
  28. {{- end }}
  29. {{- if or (eq .Values.primary.service.type "LoadBalancer") (eq .Values.primary.service.type "NodePort") }}
  30. externalTrafficPolicy: {{ .Values.primary.service.externalTrafficPolicy | quote }}
  31. {{- end }}
  32. {{- if and (eq .Values.primary.service.type "LoadBalancer") (not (empty .Values.primary.service.loadBalancerSourceRanges)) }}
  33. loadBalancerSourceRanges: {{ .Values.primary.service.loadBalancerSourceRanges }}
  34. {{- end }}
  35. {{- if and (eq .Values.primary.service.type "LoadBalancer") (not (empty .Values.primary.service.loadBalancerIP)) }}
  36. loadBalancerIP: {{ .Values.primary.service.loadBalancerIP }}
  37. {{- end }}
  38. ports:
  39. - name: mysql
  40. port: {{ .Values.primary.service.ports.mysql }}
  41. protocol: TCP
  42. targetPort: mysql
  43. {{- if (and (or (eq .Values.primary.service.type "NodePort") (eq .Values.primary.service.type "LoadBalancer")) .Values.primary.service.nodePorts.mysql) }}
  44. nodePort: {{ .Values.primary.service.nodePorts.mysql }}
  45. {{- else if eq .Values.primary.service.type "ClusterIP" }}
  46. nodePort: null
  47. {{- end }}
  48. {{- if .Values.primary.service.extraPorts }}
  49. {{- include "common.tplvalues.render" (dict "value" .Values.primary.service.extraPorts "context" $) | nindent 4 }}
  50. {{- end }}
  51. selector: {{ include "common.labels.matchLabels" . | nindent 4 }}
  52. app.kubernetes.io/component: primary