Search code examples
nginxkuberneteskubectl

How to delete networkpolicies using kubectl?


I've followed a Kubernetes tutorial similar to: https://kubernetes.io/docs/tasks/administer-cluster/declare-network-policy/ which created some basic networkpolicies as follows:

root@server:~# kubectl get netpol -n policy-demo
NAME           POD-SELECTOR   AGE
access-nginx   run=nginx      49m
default-deny   <none>         50m

I saw that I can delete the entire namespace (pods included) using a command like "kubectl delete ns policy-demo", but I can't see what command I need to use if I just want to delete a single policy (or edit it even).

How would I use kubectl to delete just the "access-nginx" policy above?


Solution

  • This should work. A similar command works at my end.

    kubectl -n policy-demo delete networkpolicy access-nginx