I have been fortunate enough to work in Devops for the past few years. During this time, I have taken an obsession in learning how to manage applications in production, and as a result trying to figure out:
- How easy is it to push new features to production and to roll back to a previous version predictably and as necessity dictates?
- How best is it to have a consistent environment where exactly what was tested in development is deployed to production?
- How can resource utilization be controlled to prevent Out Of Memory Exceptions which tend to lead to vital applications being terminated?
One of the latest technologies to revolutionize the way servers are managed are containers. Simply put, a container is an abstraction that packages code and dependencies together thus providing isolation from the surrounding environment. In addition to the code, it specifies the runtime, system tools, system libraries and settings required. As a result a container can provide isolation that can mitigate against unexpected mutability and resource over utilization. There are different flavours of containers, but the focus will be on Docker.
Container technology by itself, is but just one piece of the puzzle. However, there also needs to be a mechanism to deploy, scale and manage containerized applications in production i.e. container orchestration.
There are several container orchestration tools which include Docker swarm, Kubernetes and Mesos. Out of the major players in the market, Kubernetes has emerged to be the most popular orchestration tool, gaining significant traction and adoption in the last few years.
Kubernetes is an open source container orchestration tool based on the Google Borg cluster manager that is used to manage the Google platform.
At its elementary level, Kubernetes can schedule and run application containers on clusters of physical and/or virtual machines. It means that:
- Application deployments can happen quickly and predictably.
- Provides elasticity in that applications can be scaled up and down depending on load.
- Resource limitation can be implemented to minimize hardware usage of specific applications.
The foundational concept of Kubernetes is in the management of pods. A pod is one or more containers deployed together as a group within the same physical or virtual host machine colloquially known as a node. For example, a pod could have one container that hosts the application code and a separate container that handles the application monitoring and logging. Majority of what Kubernetes does is in:
- Managing the pod lifecycle.
- Managing how traffic is routed within, into and out of pods.
- Managing and controlling access to the pods, and so on.
Working with Django.
This blog series focuses on Django, which is one of the most popular python frameworks and is been used by companies like Bitbucket, Eventbrite, Instagram, Pinterest etc. As such, it forms a good candidate in figuring out how to deploy it in production using Kubernetes. Knowledge of Django is useful but not entirely necessary as the underlying ideas can be applied to other frameworks as well.
The code for this tutorial can be found in Github where each post is a specific branch in the repo.
The tutorial series progresses with increased complexity, where in:
- Part 2: A simple Django application is created in a docker container, the container is deployed into a local kubernetes cluster run using minikube.
- Part 3: Integration with a PostgresSQL database running as a pod in the cluster.
- Part 4: Adding a Redis cache as well as Celery for asynchronous task processing.
- Part 5: Deploy to AWS using Kops and using an external RDS PostgreSQL database.
- Part 6: Monitoring and logging will then be implemented, as is crucial to any serious application.
There are a lot of moving parts to get through, but hopefully at the end we will know more about Kubernetes than when we first began.
If you like this post, don’t forget to like and/or recommend it. You can find me on Twitter as @MarkGituma.