################ Network policies ################ As Catalyst Cloud uses `Calico CNI`_ for the default network driver it is possible to define network policies to control what and how resources are accessed within the cluster. In the following example we look at adding a default policy that denies all access to the cluster network and then look at how to add an exception to this. You can read more about `Network Policies`_ in the official `Kubernetes documentation`_. .. _`Calico CNI`: https://docs.tigera.io/calico/latest/about/ .. _`Network Policies`: https://kubernetes.io/docs/concepts/services-networking/network-policies/ .. _`Kubernetes documentation`: https://kubernetes.io/docs/home/ ************************** Create a simple deployment ************************** First create a simple deployment with 2 replicas. .. Note:: We will be using the ``default`` namespace. This could be done in any `namespace`_ however, by first creating a new namespace and then using the ``-n `` parameter for the kubectl commands. .. _`namespace`: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ The image ``gcr.io/google-samples/hello-app:1.0`` provides a simple web app, listening on port 8080, that returns the app version, hostname and a 'Hello world' message. .. code-block:: bash $ kubectl create -f - < 53s If we describe the policy we can confirm that no ingress or egress traffic is allowed and that this will apply to all pods. .. code-block:: bash $ kubectl describe networkpolicies netpol-default-deny Name: netpol-default-deny Namespace: default Created on: 2018-11-07 16:36:00 +1300 NZDT Labels: Annotations: Spec: PodSelector: (Allowing the specific traffic to all pods in this namespace) Allowing ingress traffic: (Selected pods are isolated for ingress connectivity) Allowing egress traffic: (Selected pods are isolated for egress connectivity) Policy Types: Ingress Let's connect to the busybox pod again and try to access the app-pod service. This time we will add a timeout to our wget command as it will not succeed. .. code-block:: text $ kubectl run --generator=run-pod/v1 -it --rm busybox --image=busybox -- sh If you don't see a command prompt, try pressing enter. / # wget -q --timeout=10 app-service -O - wget: download timed out / # ************************** Create the policy override ************************** Now let's add a new policy that allows ingress to the deployment. We will match the pods to allow access to using the labels ``app: test-app`` and we will limit this access to only pods with the label ``run: busybox``. .. code-block:: bash kubectl create -f - <