apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: sonarr-network
  namespace: media
spec:
  podSelector:
    matchLabels:
      app.kubernetes.io/instance: sonarr
      app.kubernetes.io/name: sonarr
  policyTypes:
    - Ingress
    - Egress
  ingress:
    - from:
        - namespaceSelector:
            matchLabels:
              name: networking
          podSelector:
            matchLabels:
              app.kubernetes.io/instance: traefik
              app.kubernetes.io/name: traefik
      ports:
        - port: 8989
          protocol: TCP
    - from:
        - podSelector: {}
    - from:
        - namespaceSelector:
            matchLabels:
              name: monitoring
          podSelector:
            matchLabels:
              app.kubernetes.io/instance: prometheus-prometheus
              app.kubernetes.io/name: prometheus
      ports:
        - port: 9793
          protocol: TCP
  egress:
    - to:
        - podSelector:
            matchLabels:
              app.kubernetes.io/instance: prowlarr
              app.kubernetes.io/name: prowlarr
      ports:
        - port: 9696
          protocol: TCP
    - to:
        - podSelector:
            matchLabels:
              app.kubernetes.io/instance: qbittorrent
              app.kubernetes.io/name: qbittorrent
      ports:
        - port: 8080
          protocol: TCP
    - to:
        - podSelector:
            matchLabels:
              app.kubernetes.io/instance: jellyfin
              app.kubernetes.io/name: jellyfin
      ports:
        - port: 8096
    - to:
        - ipBlock:
            cidr: 0.0.0.0/0
      ports:
        - port: 443
          protocol: TCP
    - to:
        - namespaceSelector: {}
          podSelector:
            matchLabels:
              k8s-app: kube-dns
      ports:
        - port: 53
          protocol: UDP
