How to enable Network Policies in Docker for Mac with Kubernetes

1/13/2019

Is there an easy way to enable Network Policies in single-node k8s cluster managed by Docker Desktop for Mac?

-- Erkan Erol
docker-desktop
docker-for-mac
kubernetes
kubernetes-networkpolicy

1 Answer

3/28/2020

A single-node k8s cluster managed by Docker Desktop for Mac is imply a VM provisioned by the Docker for Mac Daemon that is then bootstrapped with a Kubernetes cluster. Docker has extended this solution in some ways to make it easier for developers to use but it is effectively similar to using Minikube.

A NetworkPolicy is a Kubernetes resource and as you have discovered, it is not enabled in your environment by default. This is because the NetworkPolicy resource requires a controller to be installed to enabled the enforcement of NetworkPolicy rules after they have been declared. Many applications can be installed to provide this functionality. The most common way is by installing a CNI like Calico.

After you do this, Calico will be able to enforce your NetworkPolicy rules that you have defined. They will automatically move from the Pending to Ready state in the cluster.

-- TJ Zimmerman
Source: StackOverflow