service.yaml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. {{- if or .Release.IsUpgrade (ne .Values.sentinel.service.type "NodePort") .Values.sentinel.service.nodePorts.redis -}}
  2. {{- if and (eq .Values.architecture "replication") .Values.sentinel.enabled }}
  3. {{ $portsmap := (lookup "v1" "ConfigMap" $.Release.Namespace (printf "%s-%s" ( include "common.names.fullname" . ) "ports-configmap")).data }}
  4. {{ $sentinelport := 0}}
  5. {{ $redisport := 0}}
  6. {{- if $portsmap }}
  7. {{ $sentinelport = index $portsmap (printf "%s-%s" (include "common.names.fullname" $) "sentinel") }}
  8. {{ $redisport = index $portsmap (printf "%s-%s" (include "common.names.fullname" $) "redis") }}
  9. {{- else }}
  10. {{- end }}
  11. apiVersion: v1
  12. kind: Service
  13. metadata:
  14. name: {{ template "common.names.fullname" . }}
  15. namespace: {{ .Release.Namespace | quote }}
  16. labels: {{- include "common.labels.standard" . | nindent 4 }}
  17. app.kubernetes.io/component: node
  18. {{- if .Values.commonLabels }}
  19. {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
  20. {{- end }}
  21. {{- if or .Values.sentinel.service.annotations .Values.commonAnnotations }}
  22. annotations:
  23. {{- if .Values.sentinel.service.annotations }}
  24. {{- include "common.tplvalues.render" ( dict "value" .Values.sentinel.service.annotations "context" $ ) | nindent 4 }}
  25. {{- end }}
  26. {{- if .Values.commonAnnotations }}
  27. {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  28. {{- end }}
  29. {{- end }}
  30. spec:
  31. type: {{ .Values.sentinel.service.type }}
  32. {{- if or (eq .Values.sentinel.service.type "LoadBalancer") (eq .Values.sentinel.service.type "NodePort") }}
  33. externalTrafficPolicy: {{ .Values.sentinel.service.externalTrafficPolicy | quote }}
  34. {{- end }}
  35. {{- if and (eq .Values.sentinel.service.type "LoadBalancer") (not (empty .Values.sentinel.service.loadBalancerIP)) }}
  36. loadBalancerIP: {{ .Values.sentinel.service.loadBalancerIP }}
  37. {{- end }}
  38. {{- if and (eq .Values.sentinel.service.type "LoadBalancer") (not (empty .Values.sentinel.service.loadBalancerSourceRanges)) }}
  39. loadBalancerSourceRanges: {{ toYaml .Values.sentinel.service.loadBalancerSourceRanges | nindent 4 }}
  40. {{- end }}
  41. {{- if and .Values.sentinel.service.clusterIP (eq .Values.sentinel.service.type "ClusterIP") }}
  42. clusterIP: {{ .Values.sentinel.service.clusterIP }}
  43. {{- end }}
  44. {{- if .Values.sentinel.service.sessionAffinity }}
  45. sessionAffinity: {{ .Values.sentinel.service.sessionAffinity }}
  46. {{- end }}
  47. {{- if .Values.sentinel.service.sessionAffinityConfig }}
  48. sessionAffinityConfig: {{- include "common.tplvalues.render" (dict "value" .Values.sentinel.service.sessionAffinityConfig "context" $) | nindent 4 }}
  49. {{- end }}
  50. ports:
  51. - name: tcp-redis
  52. {{- if and (or (eq .Values.sentinel.service.type "NodePort") (eq .Values.sentinel.service.type "LoadBalancer")) .Values.sentinel.service.nodePorts.redis }}
  53. port: {{ .Values.sentinel.service.nodePorts.redis }}
  54. {{- else if eq .Values.sentinel.service.type "NodePort" }}
  55. port: {{ $redisport }}
  56. {{- else}}
  57. port: {{ .Values.sentinel.service.ports.redis }}
  58. {{- end }}
  59. targetPort: {{ .Values.replica.containerPorts.redis }}
  60. {{- if and (or (eq .Values.sentinel.service.type "NodePort") (eq .Values.sentinel.service.type "LoadBalancer")) .Values.sentinel.service.nodePorts.redis }}
  61. nodePort: {{ .Values.sentinel.service.nodePorts.redis }}
  62. {{- else if eq .Values.sentinel.service.type "ClusterIP" }}
  63. nodePort: null
  64. {{- else if eq .Values.sentinel.service.type "NodePort" }}
  65. nodePort: {{ $redisport }}
  66. {{- end }}
  67. - name: tcp-sentinel
  68. {{- if and (or (eq .Values.sentinel.service.type "NodePort") (eq .Values.sentinel.service.type "LoadBalancer")) .Values.sentinel.service.nodePorts.sentinel }}
  69. port: {{ .Values.sentinel.service.nodePorts.sentinel }}
  70. {{- else if eq .Values.sentinel.service.type "NodePort" }}
  71. port: {{ $sentinelport }}
  72. {{- else }}
  73. port: {{ .Values.sentinel.service.ports.sentinel }}
  74. {{- end }}
  75. targetPort: {{ .Values.sentinel.containerPorts.sentinel }}
  76. {{- if and (or (eq .Values.sentinel.service.type "NodePort") (eq .Values.sentinel.service.type "LoadBalancer")) .Values.sentinel.service.nodePorts.sentinel }}
  77. nodePort: {{ .Values.sentinel.service.nodePorts.sentinel }}
  78. {{- else if eq .Values.sentinel.service.type "ClusterIP" }}
  79. nodePort: null
  80. {{- else if eq .Values.sentinel.service.type "NodePort" }}
  81. nodePort: {{ $sentinelport }}
  82. {{- end }}
  83. {{- if eq .Values.sentinel.service.type "NodePort" }}
  84. - name: sentinel-internal
  85. nodePort: null
  86. port: {{ .Values.sentinel.containerPorts.sentinel }}
  87. protocol: TCP
  88. targetPort: {{ .Values.sentinel.containerPorts.sentinel }}
  89. - name: redis-internal
  90. nodePort: null
  91. port: {{ .Values.replica.containerPorts.redis }}
  92. protocol: TCP
  93. targetPort: {{ .Values.replica.containerPorts.redis }}
  94. {{- end }}
  95. {{- if .Values.sentinel.service.extraPorts }}
  96. {{- include "common.tplvalues.render" (dict "value" .Values.sentinel.service.extraPorts "context" $) | nindent 4 }}
  97. {{- end }}
  98. selector: {{- include "common.labels.matchLabels" . | nindent 4 }}
  99. app.kubernetes.io/component: node
  100. {{- end }}
  101. {{- end }}