This is a cache of https://docs.openshift.com/container-platform/4.3/networking/network_policy/viewing-network-policy.html. It is a snapshot of the page at 2024-09-20T20:23:00.075+0000.
Viewing a network policy - Network policy | Networking | OpenShift Container Platform 4.3
×

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

Viewing NetworkPolicy objects

You can list the NetworkPolicy objects 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: extensions/v1beta1
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.