svc-external.yaml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. {{- if .Values.broker.external.enabled }}
  2. {{- $externalValues := .Values.broker.external }}
  3. {{- $svclValues := .Values.broker.external.service }}
  4. {{- $componet := include "kafka.broker.componet" . }}
  5. {{- $fullNodePorts := list }}
  6. {{- range include "kafka.fullNodePorts" . | split "," }}
  7. {{- $fullNodePorts = printf "%s" . | append $fullNodePorts }}
  8. {{- end }}
  9. {{- $replicaCount := .Values.broker.replicaCount | int }}
  10. {{- range $i := until $replicaCount }}
  11. {{- $nodePort := (index $fullNodePorts $i) }}
  12. {{- $targetPod := printf "%s-%d" (include "kafka.broker.fullname" $) $i }}
  13. apiVersion: v1
  14. kind: Service
  15. metadata:
  16. name: {{ printf "%s-%d-external" (include "kafka.broker.fullname" $) $i | trunc 63 | trimSuffix "-" }}
  17. labels:
  18. {{- include "kafka.labels" $ | nindent 4 }}
  19. component: {{ $componet | quote }}
  20. pod: {{ $targetPod }}
  21. {{- with $svclValues.annotations }}
  22. annotations:
  23. {{- toYaml . | nindent 4 }}
  24. {{- end }}
  25. spec:
  26. type: {{ $svclValues.type | default "NodePort" }}
  27. {{- if eq $svclValues.type "LoadBalancer" }}
  28. {{- if $svclValues.loadBalancerSourceRanges }}
  29. loadBalancerSourceRanges:
  30. {{- toYaml $svclValues.loadBalancerSourceRanges | nindent 4 }}
  31. {{- end }}
  32. {{- if $svclValues.allocateLoadBalancerNodePorts }}
  33. allocateLoadBalancerNodePorts: true
  34. {{- end }}
  35. {{- end }}
  36. ports:
  37. - name: external
  38. port: {{ $svclValues.port }}
  39. targetPort: external
  40. protocol: TCP
  41. {{- if eq $svclValues.type "NodePort" }}
  42. nodePort: {{ $nodePort }}
  43. {{- end }}
  44. selector:
  45. {{- include "kafka.selectorLabels" $ | nindent 4 }}
  46. component: {{ $componet | quote }}
  47. statefulset.kubernetes.io/pod-name: {{ $targetPod }}
  48. ---
  49. {{- end }}
  50. {{- end }}