deploying calico on kubernetes

26
Anirban Sen Chowdhary

Upload: anirban-sen-chowdhary

Post on 21-Jan-2018

209 views

Category:

Technology


7 download

TRANSCRIPT

Page 1: Deploying calico on kubernetes

Anirban Sen Chowdhary

Page 2: Deploying calico on kubernetes

Calico which is a open source project is a new approach to enables networking and network policy in Kubernetes clusters across the cloud. Calico works on all major public cloud providers and private cloud as well. Calico uses a pure IP networking fabric that provide high performance networking, and its battle-tested policy engine enforces high-level, intent-focused network policy.

Page 3: Deploying calico on kubernetes

This slides will guide you to configure a Kubernetes cluster configured with Calico networking; all you need is you have kubectl configured to interact with the cluster.

Page 4: Deploying calico on kubernetes

After your Kubernetes is started and ready the first step is to install Project Calico using kubectl: kubectl apply -f https://docs.projectcalico.org/v2.4/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.6/calico.yaml

Page 5: Deploying calico on kubernetes

As you can see the following:

Page 6: Deploying calico on kubernetes

We will deploy pods in a Kubernetes Namespaces.Now, we need to create a namespace Object to launch applications in.We can do this using kubectl create followed by ns for namespace, and then the name of our namespace, like so: kubectl create ns policy-demo

Page 7: Deploying calico on kubernetes

As you can see the following namespace created:

Page 8: Deploying calico on kubernetes

Now let's create some nginx demo pods in the policy-demo namespace by using the kubectl run command : # Run the Pods.

kubectl run --namespace=policy-demo nginx --replicas=2 --image=nginx

Page 9: Deploying calico on kubernetes

As you can see the following "nginx" created:

Page 10: Deploying calico on kubernetes

And then expose the pods through a service using the kubectl expose command: # Create the Service.

kubectl expose --namespace=policy-demo deployment nginx --port=80

Page 11: Deploying calico on kubernetes

As you can see the following "nginx" exposed:

Page 12: Deploying calico on kubernetes

We will now apply our pod.yaml file.To apply the pod, we'll once again use kubectl create, but this time with the -f flag: kubectl create -f pod.yaml

Page 13: Deploying calico on kubernetes

As you can see the following :

Page 14: Deploying calico on kubernetes

Once the pod.yaml file is applied, we should be able to access the pod and receive back the nginx welcome page using the following command: kubectl exec -n policy-demo client -- wget -T 2 -q nginx -O -

Page 15: Deploying calico on kubernetes

As you can see the following :

Page 16: Deploying calico on kubernetes

Next, we need to annotate the policy-demo namespace to deny all incoming (ingress) traffic using the kubectl annotate command: kubectl annotate ns policy-demo "net.beta.kubernetes.io/network-policy={\"ingress\":{\"isolation\":\"DefaultDeny\"}}"

Page 17: Deploying calico on kubernetes

As you can see Calico will then prevent connections to pods in this Namespace and turn on isolation :

Page 18: Deploying calico on kubernetes

Now, remote access to this pod should be unavailable, and we should receive a timeout warning. kubectl exec -n policy-demo client -- wget -q nginx -T 2 -O -

Page 19: Deploying calico on kubernetes

We can see below :

Page 20: Deploying calico on kubernetes

Next, we'll allow access to the pod by applying the network-policy.yaml fileApply the network-policy.yaml file using the kubectl create command with the -f flag:

kubectl create -f network-policy.yaml

Page 21: Deploying calico on kubernetes

We can see below :

Page 22: Deploying calico on kubernetes

Now, using our network-policy.yaml file that we just applied, this should be allowing incoming traffic to pods running nginx. We can test this using the following command:

kubectl exec -n policy-demo client -- wget -q nginx -T 2 -O -

Page 23: Deploying calico on kubernetes

We can see below this will allow incoming connections from our Pod:

Page 24: Deploying calico on kubernetes

Now, we can say that we have now installed Project Calico, deployed a couple pods, isolated the pods by default, and then applied policies to enable access to pods running nginx.

Page 25: Deploying calico on kubernetes

We can see below this if we use the following commands:

kubectl get pods --all-namespaces

Page 26: Deploying calico on kubernetes