×

As a cluster administrator, you can view a network policy for a namespace.

Viewing network policies

You can list the network policies in your cluster.

Prerequisites
  • You installed the OpenShift CLI (oc).

  • You are logged in to the cluster with a user with cluster-admin privileges.

Procedure
  • To view NetworkPolicy objects defined in your cluster, run the following command:

    $ oc get networkpolicy

Example NetworkPolicy object

The following annotates an example NetworkPolicy object:

kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
  name: allow-27107 (1)
spec:
  podSelector: (2)
    matchLabels:
      app: mongodb
  ingress:
  - from:
    - podSelector: (3)
        matchLabels:
          app: app
    ports: (4)
    - protocol: TCP
      port: 27017
1 The name of the NetworkPolicy object.
2 A selector describing the pods the policy applies to. The policy object can only select pods in the project that the NetworkPolicy object is defined.
3 A selector matching the pods that the policy object allows ingress traffic from. The selector will match pods in any project.
4 A list of one or more destination ports to accept traffic on.