Scalable and Resilient Django with Kubernetes

Scalable and Resilient Django with Kubernetes

A brief introduction to containers and Kubernetes, and how they can help you deploy your Django application in a scalable and resilient fashion.

0cdb3410ac64c43dc8ef29f0ef7a7b47?s=128

Harish Narayanan

March 15, 2016
Tweet

Transcript

  1. Scalable and Resilient Django with Kubernetes Harish Narayanan @copingbear https://harishnarayanan.org/writing/kubernetes-django/

    https://github.com/hnarayanan/kubernetes-django
  2. None
  3. Platform as a Service to the rescue!

  4. Platform as a Service to the rescue! … but they’re

    inflexible.
  5. Traditional VMs to the rescue! ������� ��� ������� ��������� ���������

    ������� ������ �������� ������������ ��� ������ ������ ���� Layout of a non-trivial Django application
  6. Traditional VMs to the rescue! ������ ������ ������� ��� �������

    ��������� ��������� ������� ������ �������� ������������ ��� ������ ������ ���� All pieces making up the app on a single machine
  7. Traditional VMs to the rescue! �������� ������ ����������� ������ �

    ����������� ������ � ����������� ������ � ���� �������� ������� �������� ������������ ��� ������� ��������� ��� ��� ������� ��������� ��� ��� ������� ��������� ��� ��� ������ ������� ���� ���� ���� ���� ������ ������ Running many instances of the app, talking to a single database
  8. … but they have their own problems too • It’s

    annoying to provision, setup and keep up-to-date one server for each component • You generally have poor resource utilisation because you’re setup to handle peak load • There is poor resource isolation if multiple components share a server
  9. What if we could shift our attention from managing servers

    to simply running the pieces of our app? ���� � ���� � ���� � ������� �������� ������������ ��� ������� ��������� ��� ��� ������� ��������� ��� ��� ������� ��������� ��� ���������� ���� ���� �������� ���� ���� ���� ���� ������� �������� ������� ������� ������� ���� The application running on an abstract collection of resources
  10. That’s the promise of containers and Kubernetes

  11. A brief look at Docker containers docker build -t container:tag

    . docker push container:tag Docker Architecture A Dockerfile for Django (Gunicorn)
  12. Now we just need to ensure that the containers are

    running and talking to one another ���� � ���� � ���� � ������� �������� ������������ ��� ������� ��������� ��� ��� ������� ��������� ��� ��� ������� ��������� ��� ���������� ���� ���� �������� ���� ���� ���� ���� ������� �������� ������� ������� ������� ���� The application running on an abstract collection of resources
  13. This is exactly what Kubernetes does! • Kubernetes is an

    open-source system for managing clusters and deploying “containerised” applications • Project spearheaded by Google, and written in Go • http://kubernetes.io
 https://github.com/kubernetes/kubernetes
  14. You control Kubernetes via an elegant REST API ���������� ������

    ���������� ���� � ���������� ���� � ������ ��������� ��� ������ ��������� ������� ������� ���������� ������� ���� ������ ���������� ������ ���������� Simplified architecture of Kubernetes
  15. • Building and publishing of Docker containers • Provisioning of

    a Kubernetes cluster and monitoring it • Deploying our app and database (pods, labels, replication controllers, services) • Resilience to failure • Scaling and rolling updates • Not seen today: Secrets, Persistent Volumes and Claims, Static Assets to CDN (but are/will be in demo repo!) Demo: Deploying our app with this new toolset, and things we could see along the way
  16. Some closing thoughts • Philosophical shift from managing servers to

    running services ideally • Setup of a Kubernetes cluster is non-trivial and the experience is heavily dependent on the capabilities of the underlying provider (GCP, AWS, Others) • Do play around to gauge if complexity is worth it • Try 1.2 (any day now!) for improved feature set, e.g. easier Secrets and Horizontal Auto-Scaling
  17. Questions? Harish Narayanan @copingbear https://harishnarayanan.org/writing/kubernetes-django/ https://github.com/hnarayanan/kubernetes-django