Docker, Kubernetes and Microservices
What problems do developers face?
Its runs on my laptop/computer :)
We often hear developers say, “But it runs perfectly on my computer” while it doesn’t behave expectedly in production.
Scaling applications is expensive. Adding more Virtual Machines (VMs) can be expensive.
Lets say, our application requires integrating different services e.g Elastic Search. Should every developer install Elastic Search and all databases (e.g postgres) on their laptop?
What is Docker?
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers.
Docker enables developers to easily pack, ship, and run any application as a lightweight, portable, self-sufficient container, which can run virtually anywhere.
So what actually is a Container?
Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.
There are three main concepts regarding Docker
- Docker Images
- Containers
- Dockerfile
So what actually is a Container?
Docker is a technology that allows you to incorporate and store your code and its dependencies into a neat little package - an image.
A docker image holds your source code and the dependencies it needs. Lets say you have a Dot Net app, A docker image of your app will contain the code + the libraries and everything that’s needed to run your Dot Net application.
Dockerfile
A Dockerfile is a text file that contains a bunch of instructions which informs Docker how the Docker image should get built.
Here is an Angular project. Take a look at different Dockerfiles in the root folder. A different dockerfile for each environment.
Dockerfile
A Node.js Dockerfile
Why use Docker?
- Docker helps us set up local development environments that are exactly like a live production server.
- Suppose you are working on multiple projects. They all have different environments. One project uses Postgres 9, One uses Postgres 10. This is not a headache with Docker. It will install what is required.
- If you have 30 Docker containers that you want to run, you can run them all on a single virtual machine.
Why use Docker?
-
Docker has been designed in a way that it can be incorporated into most DevOps applications, including Puppet, Chef, Vagrant, and Ansible, or it can be used on its own to manage development environments.
-
Agile and CI / CD practices are very easy to implement in a docker environment.
Why use Docker?
-
The performance difference b/w Containers and VMs is 26:1.
- Your development team is able to create complex requirements for a microservice within an easy-to-write Dockerfile.
Docker Alternatives
Although Docker is the most popular container technology, but there many other container solutions out there:
- BSD Jails
- LXD
- RKT (pronounced as Rocket)
Container Orchestration
Like any other element of your IT infrastructure, containers need to be monitored and controlled. Otherwise, you literally have no idea what’s running on your servers.
That is where Orchestration comes in. There are 3 big players.
Docker Swarm, Kubernetes (built by Google), and Mesosphere (used by Twitter). Today, these are all still around, but Kubernetes is by far the most dominant cloud-orchestration program.
Kubernetes
Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.
“Designed on the same principles that allows Google to run billions of containers a week, Kubernetes can scale without increasing your ops team.”
We live on an island surrounded by a sea of ignorance. As our island of knowledge grows. so does the shore of our ignorance. ~ John Archibald Wheeler
Containers as a service
AWS Fargate. Just build apps and Amazon will manage the containers for you (scale automatically).
With AWS Fargate, there are no upfront payments and you only pay for the resources that you use.
Microservices
Microservices are an architectural approach to building applications.
The benefit to using microservices is that development teams are able to rapidly build new components of apps to meet changing business needs.
Microservices
Microservices can communicate with each other, usually statelessly, so apps built in this way can be more fault tolerant.
Microservices can be written in different languages depending on the use case and requirement. Modern application development essentially consists of composing an application from a variety of services.
Why not Docker?
When you want best speed. Docker containers have less overhead than virtual machines. But Docker does not have zero overhead. The only way to get true bare-metal speed from an application is to run it directly on a bare-metal server, without using containers or virtual machines.
Docker also creates new security challenges — such as the difficulty of monitoring so many moving pieces within a dynamic, large-scale Docker environment.
Why not Docker?
All the data stored inside a container will be lost forever once the container shuts down. Managing stateful applications in a docker environment is hard.
You have to think of ways to save your data somewhere else first. To keep data safe in Docker, you need to employ an additional tool – Docker Data Volumes. Yet, this solution is still quite clumsy and needs to be improved.
Thank You!
Link to slides: https://slides.com/alamgirqazi/docker-microservices
link to blog: https://alamgirqazi.github.io/tech-blog/docker-microservices/
Docker, Kubernetes and Microservices
By Alamgir Qazi
Docker, Kubernetes and Microservices
Link to blog: https://alamgirqazi.github.io/tech-blog/docker-microservices/
- 758