apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: beacon-chain
  namespace: ethereum-2
  labels:
    app.kubernetes.io/name: beacon-chain
spec:
  podSelector:
    matchLabels:
      app.kubernetes.io/name: beacon-chain
  policyTypes:
  - Ingress
  ingress:
  # allow the world to connect to beacon chain's p2p endpoints
  - from:
    - ipBlock:
        cidr: 0.0.0.0/0
    ports:
    - protocol: TCP
      port: 31300
    - protocol: UDP
      port: 31200
  # allow eth2stats to connect to rpc and metrics endpoints
  - from:
    - podSelector:
        matchLabels:
          app.kubernetes.io/name: eth2stats
    ports:
    - protocol: TCP
      port: 4000
    - protocol: TCP
      port: 8080
  # allow the slasher to connect to the rpc endpoint
  - from:
    - podSelector:
        matchLabels:
          app.kubernetes.io/name: slasher
    ports:
    - protocol: TCP
      port: 4000
  # allow the validator to connect to the rpc endpoint
  - from:
    - podSelector:
        matchLabels:
          app.kubernetes.io/name: validator
    ports:
    - protocol: TCP
      port: 4000
  # allow prometheus to scrape the metrics endpoint
  - from:
    - podSelector:
        matchLabels:
          app.kubernetes.io/name: prometheus
    ports:
    - protocol: TCP
      port: 8080
  # allow prometheus-to-sd to scrape the metrics endpoint
  - from:
    - podSelector:
        matchLabels:
          app.kubernetes.io/name: prometheus-to-sd
    ports:
    - protocol: TCP
      port: 8080
