kubectl plugin for rendering details of Network Policies
Listing all Network Policies in a Namespace provides little information about the Pods they apply to and the rules they specify. The following command list all Network Policies describes as examples in the Kubernetes documentation.
$ kubectl get networkpolicy
NAME POD-SELECTOR AGE
allow-all-egress <none> 17h
allow-all-ingress <none> 17h
deny-all-egress <none> 17h
deny-all-ingress <none> 17h
deny-all-ingress-egress <none> 17h
test-network-policy role=db 17h
As you can see, it’s extremely hard to grasp the effect of the Network Policies. You’d usually have to have a look at the details of each Network Policy to understand their inner workings. This is where this plugin comes in.
Run the command swiftnp
with the subcommand list
to render detailed information about Network Policies.
You can render Network Policies in other Namespaces by providing the --namespace
option.
$ kubectl swiftnp list
NAME SELECTED-PODS INGRESS-POLICY EGRESS-POLICY INGRESS-RULE EGRESS-RULE FROM-COUNT TO-COUNT
allow-all-egress frontend, mypod ✖ ✔ ✖ ✔ 0 0
allow-all-ingress frontend, mypod ✔ ✖ ✔ ✖ 0 0
deny-all-egress frontend, mypod ✖ ✔ ✖ ✖ 0 0
deny-all-ingress frontend, mypod ✔ ✖ ✖ ✖ 0 0
deny-all-ingress-egress frontend, mypod ✔ ✔ ✖ ✖ 0 0
test-network-policy mypod ✔ ✔ ✔ ✔ 3 1
The subcommand version
renders the version of the released binary.
$ kubectl swiftnp version
kubectl swiftnp v0.2.0
The project requires Go 1.11 or higher as dependencies are defined with the help of Go Modules.
First, activate Go Modules by setting the relevant environment variable.
Next, create the platform-specific binary with the build
command.
$ export GO111MODULES=on
$ go build -o kubectl-swiftnp
Binaries for a wide range of other platforms can be created with the help of GoReleaser.
$ goreleaser release --skip-validate --snapshot --rm-dist
To release a new version of the binaries to GitHub Releases, create a Git tag and remove the relevant flags in the command above.
The binary must be placed on the $PATH
named kubectl-swiftnp
. Ensure that the binary has execution permissions.
For more information, see the official documentation on kubectl plugins.