暂无描述

backend-network-policy.yaml 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. {{- if .Values.backend.networkPolicy.enabled }}
  2. kind: NetworkPolicy
  3. apiVersion: {{ include "common.capabilities.networkPolicy.apiVersion" . }}
  4. metadata:
  5. name: {{ template "shuffle.backend.name" . }}
  6. namespace: {{ include "common.names.namespace" . | quote }}
  7. labels: {{- include "shuffle.backend.labels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  8. {{- if .Values.commonAnnotations }}
  9. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  10. {{- end }}
  11. spec:
  12. {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.backend.podLabels .Values.commonLabels ) "context" . ) }}
  13. podSelector:
  14. matchLabels: {{- include "shuffle.backend.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }}
  15. policyTypes:
  16. - Ingress
  17. - Egress
  18. egress:
  19. {{- if .Values.backend.networkPolicy.allowExternalEgress }}
  20. - {}
  21. {{- else }}
  22. # Allow DNS resolution with an in-cluster DNS server
  23. - ports:
  24. - port: 53
  25. protocol: UDP
  26. - port: 53
  27. protocol: TCP
  28. to:
  29. - namespaceSelector:
  30. matchLabels:
  31. kubernetes.io/metadata.name: kube-system
  32. {{- if .Values.backend.networkPolicy.extraEgress }}
  33. {{- include "common.tplvalues.render" ( dict "value" .Values.backend.networkPolicy.extraEgress "context" $ ) | nindent 4 }}
  34. {{- end }}
  35. {{- end }}
  36. ingress:
  37. - ports:
  38. - port: {{ .Values.backend.containerPorts.http }}
  39. protocol: TCP
  40. {{- if not .Values.backend.networkPolicy.allowExternal }}
  41. from:
  42. # Allow traffic from orborus
  43. - namespaceSelector:
  44. matchLabels:
  45. kubernetes.io/metadata.name: {{ .Release.Namespace }}
  46. podSelector:
  47. matchLabels: {{ include "shuffle.orborus.matchLabels" . | nindent 14 }}
  48. # Allow traffic from workers
  49. - namespaceSelector:
  50. matchLabels:
  51. kubernetes.io/metadata.name: {{ .Release.Namespace }}
  52. podSelector:
  53. matchLabels: {{ include "shuffle.worker.matchLabels" . | nindent 14 }}
  54. # Allow traffic from apps
  55. - namespaceSelector:
  56. matchLabels:
  57. kubernetes.io/metadata.name: {{ .Release.Namespace }}
  58. podSelector:
  59. matchLabels: {{ include "shuffle.app.matchLabels" . | nindent 14 }}
  60. {{- end }}
  61. {{- if .Values.backend.networkPolicy.extraIngress }}
  62. {{- include "common.tplvalues.render" ( dict "value" .Values.backend.networkPolicy.extraIngress "context" $ ) | nindent 4 }}
  63. {{- end }}
  64. {{- end }}