apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: aprs-allow-egress
  namespace: aprs
spec:
  podSelector:
    matchLabels:
      app: aprs
  policyTypes:
    - Egress
  egress:
    # DNS resolution
    - to:
        - namespaceSelector: {}
          podSelector:
            matchLabels:
              k8s-app: kube-dns
      ports:
        - port: 53
          protocol: UDP
        - port: 53
          protocol: TCP
    # APRS-IS upstream servers (TCP 10152 to any IP)
    - to:
        - ipBlock:
            cidr: 0.0.0.0/0
            except:
              - 10.0.0.0/8
              - 172.16.0.0/12
              - 192.168.0.0/16
      ports:
        - port: 10152
          protocol: TCP
    # HTTPS outbound (external APIs, package fetches)
    - to:
        - ipBlock:
            cidr: 0.0.0.0/0
            except:
              - 10.0.0.0/8
              - 172.16.0.0/12
              - 192.168.0.0/16
      ports:
        - port: 443
          protocol: TCP
    # Database egress (PostgreSQL — if in-cluster, restrict to DB pod)
    # Update the podSelector if your PostgreSQL runs in-cluster with a specific label.
    # If your DB is external, this is covered by the 0.0.0.0/0 catch-all above on port 5432.
    - to:
        - ipBlock:
            cidr: 0.0.0.0/0
            except:
              - 10.0.0.0/8
              - 172.16.0.0/12
              - 192.168.0.0/16
      ports:
        - port: 5432
          protocol: TCP
