svc-external-access.yaml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. {{- if .Values.externalAccess.enabled }}
  2. {{- $fullName := include "kafka.fullname" . }}
  3. {{- $replicaCount := .Values.replicaCount | int }}
  4. {{- $root := . }}
  5. {{- range $i, $e := until $replicaCount }}
  6. {{- $targetPod := printf "%s-%d" (printf "%s" $fullName) $i }}
  7. {{- $_ := set $ "targetPod" $targetPod }}
  8. ---
  9. apiVersion: v1
  10. kind: Service
  11. metadata:
  12. name: {{ template "kafka.fullname" $ }}-{{ $i }}-external
  13. labels: {{- include "common.labels.standard" $ | nindent 4 }}
  14. app.kubernetes.io/component: kafka
  15. pod: {{ $targetPod }}
  16. {{- if $root.Values.commonLabels }}
  17. {{- include "common.tplvalues.render" ( dict "value" $root.Values.commonLabels "context" $ ) | nindent 4 }}
  18. {{- end }}
  19. {{- if or $root.Values.externalAccess.service.annotations $root.Values.commonAnnotations }}
  20. annotations:
  21. {{- if $root.Values.externalAccess.service.annotations }}
  22. {{ include "common.tplvalues.render" ( dict "value" $root.Values.externalAccess.service.annotations "context" $) | nindent 4 }}
  23. {{- end }}
  24. {{- if $root.Values.commonAnnotations }}
  25. {{- include "common.tplvalues.render" ( dict "value" $root.Values.commonAnnotations "context" $ ) | nindent 4 }}
  26. {{- end }}
  27. {{- end }}
  28. spec:
  29. type: {{ $root.Values.externalAccess.service.type }}
  30. {{- if eq $root.Values.externalAccess.service.type "LoadBalancer" }}
  31. {{- if not (empty $root.Values.externalAccess.service.loadBalancerIPs) }}
  32. loadBalancerIP: {{ index $root.Values.externalAccess.service.loadBalancerIPs $i }}
  33. {{- end }}
  34. {{- if $root.Values.externalAccess.service.loadBalancerSourceRanges }}
  35. loadBalancerSourceRanges: {{- toYaml $root.Values.externalAccess.service.loadBalancerSourceRanges | nindent 4 }}
  36. {{- end }}
  37. {{- end }}
  38. ports:
  39. - name: tcp-kafka
  40. port: {{ $root.Values.externalAccess.service.port }}
  41. {{- if not (empty $root.Values.externalAccess.service.nodePorts) }}
  42. nodePort: {{ index $root.Values.externalAccess.service.nodePorts $i }}
  43. {{- else }}
  44. nodePort: null
  45. {{- end }}
  46. targetPort: kafka-external
  47. selector: {{- include "common.labels.matchLabels" $ | nindent 4 }}
  48. app.kubernetes.io/component: kafka
  49. statefulset.kubernetes.io/pod-name: {{ $targetPod }}
  50. ---
  51. {{- end }}
  52. {{- end }}