no matches for /, Kind=NetworkPolicy

2/1/2018

I want to set a deny-all-egress policy on a namespace

Here is the yaml file

apiVersion: v1
kind: NetworkPolicy
metadata:
  name: default-deny-egress-namespace
  namespace: myns
spec:
  podSelector:
    matchLabels: {}
  policyTypes:
  - Egress

This gives me the following error

error: unable to recognize "deny-all-egress-namespace.yaml": no matches for /, Kind=NetworkPolicy

I am on version 1.7 of the server

-- user_mda
kubernetes
kubernetes-networkpolicy

1 Answer

2/2/2018

NetworkPolicy is under networking.k8s.io group with v1 version.

Try like this.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-egress-namespace
  namespace: myns
spec:
  podSelector:
    matchLabels: {}
  policyTypes:
  - Egress

Engress introduced in Kubernetes v1.8

And also above NetworkPolicy structure is supported by v1.8+

Check the documentation

-- Mir Shahriar Sabuj
Source: StackOverflow