kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
  name: ingress-allow-prometheus-to-access-mongodb-monitoring
  namespace: production
spec:
  podSelector:
    matchLabels:
      app.kubernetes.io/name: mongodb
  ingress:
  - ports:
      # Refer to the ports.containerPort.name field in mongo pod
      - port: metrics
    from:
      - namespaceSelector:
          matchLabels:
            namespace: monitoring
        podSelector:
          matchLabels:
              app: prometheus
              component: server