Skip to content

Instantly share code, notes, and snippets.

@aemneina
Created December 9, 2018 09:36
Show Gist options
  • Save aemneina/7e0d3c5f2e08cad0ad58248e9f4b3b2f to your computer and use it in GitHub Desktop.
Save aemneina/7e0d3c5f2e08cad0ad58248e9f4b3b2f to your computer and use it in GitHub Desktop.
Nuke NetworkPolicy
#documented steps, in the rancher docs, to identify/clean up network policies from rancher/k8s. if your k8s cluster started with an early version of rancher, chances are you have network policies defined. This could prevent traffic routing from the ingress controller to rancher.
#check if cluster has a network policy enabled
kubectl get cluster -o=custom-columns=ID:.metadata.name,NAME:.spec.displayName,NETWORKPOLICY:.spec.enableNetworkPolicy
#disable the network policy at the cluster level
kubectl get cluster -o jsonpath='{range .items[*]}{@.metadata.name}{"\n"}{end}' | xargs -I {} kubectl patch cluster {} --type merge -p '{"spec": {"enableNetworkPolicy": false}}'
#delete network policies for each of the following namespaces
for namespace in kube-system kube-public cattle-system cattle-alerting cattle-logging cattle-pipeline ingress-nginx; do
kubectl -n $namespace delete networkpolicy --all;
done
#smaller delete hammer
for namespace in kube-system kube-public cattle-system ingress-nginx; do
echo "$namespace";
kubectl -n $namespace delete networkpolicy --all;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment