node-services.yaml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. {{- if and (eq .Values.architecture "replication") .Values.sentinel.enabled (eq .Values.sentinel.service.type "NodePort") (or .Release.IsUpgrade .Values.sentinel.service.nodePorts.redis ) }}
  2. {{- range $i := until (int .Values.replica.replicaCount) }}
  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-node-%s-%s" (include "common.names.fullname" $) (toString $i) "sentinel") }}
  8. {{ $redisport = index $portsmap (printf "%s-node-%s-%s" (include "common.names.fullname" $) (toString $i) "redis") }}
  9. {{- else }}
  10. {{- end }}
  11. apiVersion: v1
  12. kind: Service
  13. metadata:
  14. name: {{ template "common.names.fullname" $ }}-node-{{ $i }}
  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: NodePort
  32. ports:
  33. - name: sentinel
  34. {{- if $.Values.sentinel.service.nodePorts.sentinel }}
  35. nodePort: {{ (add $.Values.sentinel.service.nodePorts.sentinel $i 1) }}
  36. port: {{ (add $.Values.sentinel.service.nodePorts.sentinel $i 1) }}
  37. {{- else }}
  38. nodePort: {{ $sentinelport }}
  39. port: {{ $sentinelport }}
  40. {{- end }}
  41. protocol: TCP
  42. targetPort: {{ $.Values.sentinel.containerPorts.sentinel }}
  43. - name: redis
  44. {{- if $.Values.sentinel.service.nodePorts.redis }}
  45. nodePort: {{ (add $.Values.sentinel.service.nodePorts.redis $i 1) }}
  46. port: {{ (add $.Values.sentinel.service.nodePorts.redis $i 1) }}
  47. {{- else }}
  48. nodePort: {{ $redisport }}
  49. port: {{ $redisport }}
  50. {{- end }}
  51. protocol: TCP
  52. targetPort: {{ $.Values.replica.containerPorts.redis }}
  53. - name: sentinel-internal
  54. nodePort: null
  55. port: {{ $.Values.sentinel.containerPorts.sentinel }}
  56. protocol: TCP
  57. targetPort: {{ $.Values.sentinel.containerPorts.sentinel }}
  58. - name: redis-internal
  59. nodePort: null
  60. port: {{ $.Values.replica.containerPorts.redis }}
  61. protocol: TCP
  62. targetPort: {{ $.Values.replica.containerPorts.redis }}
  63. selector:
  64. statefulset.kubernetes.io/pod-name: {{ template "common.names.fullname" $ }}-node-{{ $i }}
  65. ---
  66. {{- end }}
  67. {{- end }}