networkpolicy.yaml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. {{- if .Values.networkPolicy.enabled }}
  2. ---
  3. apiVersion: networking.k8s.io/v1
  4. kind: NetworkPolicy
  5. metadata:
  6. name: {{ include "loki.name" . }}-namespace-only
  7. labels:
  8. {{- include "loki.labels" . | nindent 4 }}
  9. spec:
  10. policyTypes:
  11. - Ingress
  12. - Egress
  13. podSelector: {}
  14. egress:
  15. - to:
  16. - podSelector: {}
  17. ingress:
  18. - from:
  19. - podSelector: {}
  20. ---
  21. apiVersion: networking.k8s.io/v1
  22. kind: NetworkPolicy
  23. metadata:
  24. name: {{ include "loki.name" . }}-egress-dns
  25. labels:
  26. {{- include "loki.labels" . | nindent 4 }}
  27. spec:
  28. policyTypes:
  29. - Egress
  30. podSelector:
  31. matchLabels:
  32. {{- include "loki.selectorLabels" . | nindent 6 }}
  33. egress:
  34. - ports:
  35. - port: 53
  36. protocol: UDP
  37. to:
  38. - namespaceSelector: {}
  39. ---
  40. apiVersion: networking.k8s.io/v1
  41. kind: NetworkPolicy
  42. metadata:
  43. name: {{ include "loki.name" . }}-ingress
  44. labels:
  45. {{- include "loki.labels" . | nindent 4 }}
  46. spec:
  47. policyTypes:
  48. - Ingress
  49. podSelector:
  50. matchExpressions:
  51. - key: app.kubernetes.io/component
  52. operator: In
  53. values:
  54. {{- if .Values.gateway.enabled }}
  55. - gateway
  56. {{- else }}
  57. - distributor
  58. - querier
  59. - query-frontend
  60. {{- end }}
  61. matchLabels:
  62. {{- include "loki.selectorLabels" . | nindent 6 }}
  63. ingress:
  64. - ports:
  65. - port: http
  66. protocol: TCP
  67. {{- if .Values.networkPolicy.ingress.namespaceSelector }}
  68. from:
  69. - namespaceSelector:
  70. {{- toYaml .Values.networkPolicy.ingress.namespaceSelector | nindent 12 }}
  71. {{- if .Values.networkPolicy.ingress.podSelector }}
  72. podSelector:
  73. {{- toYaml .Values.networkPolicy.ingress.podSelector | nindent 12 }}
  74. {{- end }}
  75. {{- end }}
  76. ---
  77. apiVersion: networking.k8s.io/v1
  78. kind: NetworkPolicy
  79. metadata:
  80. name: {{ include "loki.name" . }}-ingress-metrics
  81. labels:
  82. {{- include "loki.labels" . | nindent 4 }}
  83. spec:
  84. policyTypes:
  85. - Ingress
  86. podSelector:
  87. matchLabels:
  88. {{- include "loki.selectorLabels" . | nindent 6 }}
  89. ingress:
  90. - ports:
  91. - port: http-metrics
  92. protocol: TCP
  93. {{- if .Values.networkPolicy.metrics.cidrs }}
  94. from:
  95. {{- range $cidr := .Values.networkPolicy.metrics.cidrs }}
  96. - ipBlock:
  97. cidr: {{ $cidr }}
  98. {{- end }}
  99. {{- if .Values.networkPolicy.metrics.namespaceSelector }}
  100. - namespaceSelector:
  101. {{- toYaml .Values.networkPolicy.metrics.namespaceSelector | nindent 12 }}
  102. {{- if .Values.networkPolicy.metrics.podSelector }}
  103. podSelector:
  104. {{- toYaml .Values.networkPolicy.metrics.podSelector | nindent 12 }}
  105. {{- end }}
  106. {{- end }}
  107. {{- end }}
  108. {{- if .Values.ruler.enabled }}
  109. ---
  110. apiVersion: networking.k8s.io/v1
  111. kind: NetworkPolicy
  112. metadata:
  113. name: {{ include "loki.name" . }}-egress-alertmanager
  114. labels:
  115. {{- include "loki.labels" . | nindent 4 }}
  116. spec:
  117. policyTypes:
  118. - Egress
  119. podSelector:
  120. matchLabels:
  121. {{- include "loki.rulerSelectorLabels" . | nindent 6 }}
  122. egress:
  123. - ports:
  124. - port: {{ .Values.networkPolicy.alertmanager.port }}
  125. protocol: TCP
  126. {{- if .Values.networkPolicy.alertmanager.namespaceSelector }}
  127. to:
  128. - namespaceSelector:
  129. {{- toYaml .Values.networkPolicy.alertmanager.namespaceSelector | nindent 12 }}
  130. {{- if .Values.networkPolicy.alertmanager.podSelector }}
  131. podSelector:
  132. {{- toYaml .Values.networkPolicy.alertmanager.podSelector | nindent 12 }}
  133. {{- end }}
  134. {{- end }}
  135. {{- end }}
  136. {{- if .Values.networkPolicy.externalStorage.ports }}
  137. ---
  138. apiVersion: networking.k8s.io/v1
  139. kind: NetworkPolicy
  140. metadata:
  141. name: {{ include "loki.name" . }}-egress-external-storage
  142. labels:
  143. {{- include "loki.labels" . | nindent 4 }}
  144. spec:
  145. policyTypes:
  146. - Egress
  147. podSelector:
  148. matchLabels:
  149. {{- include "loki.selectorLabels" . | nindent 6 }}
  150. egress:
  151. - ports:
  152. {{- range $port := .Values.networkPolicy.externalStorage.ports }}
  153. - port: {{ $port }}
  154. protocol: TCP
  155. {{- end }}
  156. {{- if .Values.networkPolicy.externalStorage.cidrs }}
  157. to:
  158. {{- range $cidr := .Values.networkPolicy.externalStorage.cidrs }}
  159. - ipBlock:
  160. cidr: {{ $cidr }}
  161. {{- end }}
  162. {{- end }}
  163. {{- end }}
  164. {{- end }}
  165. {{- if .Values.networkPolicy.discovery.port }}
  166. ---
  167. apiVersion: networking.k8s.io/v1
  168. kind: NetworkPolicy
  169. metadata:
  170. name: {{ include "loki.name" . }}-egress-discovery
  171. labels:
  172. {{- include "loki.labels" . | nindent 4 }}
  173. spec:
  174. policyTypes:
  175. - Egress
  176. podSelector:
  177. matchLabels:
  178. {{- include "loki.selectorLabels" . | nindent 6 }}
  179. egress:
  180. - ports:
  181. - port: {{ .Values.networkPolicy.discovery.port }}
  182. protocol: TCP
  183. {{- if .Values.networkPolicy.discovery.namespaceSelector }}
  184. to:
  185. - namespaceSelector:
  186. {{- toYaml .Values.networkPolicy.discovery.namespaceSelector | nindent 12 }}
  187. {{- if .Values.networkPolicy.discovery.podSelector }}
  188. podSelector:
  189. {{- toYaml .Values.networkPolicy.discovery.podSelector | nindent 12 }}
  190. {{- end }}
  191. {{- end }}
  192. {{- end }}