In today’s world, applications need to be deployed frequently and promptly to be competitive. Microservices architecture has emerged to help businesses break down their monolith applications into smaller pieces, reducing the risk of breaking critical parts with each quick deployment cycle. Those microservices are typically deployed using containers, and with more and more containers deployed comes the need to have a container orchestration tool. The role of the orchestrator is to ensure that all containers are running and can communicate with each other if needed.
In this article, you will learn about containers and how to use container orchestration tools to manage them.
A container is a package that contains everything necessary to run an application. Imagine a ZIP file that would include your application’s source code, along with everything needed to run this application. This package would also contain any necessary configuration files or additional software required to run your software. This package is what you would then deploy to your servers.
For example, take an application written in PHP. Instead of dropping your files on an FTP server and hoping that your server has the correct version and modules, you would package everything in a container. This container would have the PHP files, along with a specific version of the
php executable. It could also contain a fully configured Apache
httpd server, ready to be used with this particular PHP runtime.
Because all the runtimes necessary for the application are included in the container, software developers can ensure that an application runs precisely the same in the production environment as it does in the development environment.
Another significant benefit of containers is that they run in complete isolation from each other. This isolation means that a container running on a host has no knowledge of the underlying operating system or other containers. Essentially, whatever happens in the container stays in the container.
One last thing to keep in mind with containers is that they are ephemeral in nature. This means that when a container is restarted, it will always be the same. Any changes that were done while it was running are lost when the container stops. This is a great feature that ensures that if something corrupts the container, it can always be restarted and have the expected behaviour.
As you have more and more microservices running in your servers, you will need a way to manage those containers throughout their lifecycle. There are many things that you might want to manage on those containers.
Container orchestration is the automation of all the processes needed to run, manage, and monitor a collection of containers.
When you have a limited number of containers, it is possible to perform those management tasks manually or with simple scripting. However, as the number of containers increases, it becomes harder and harder to do so. This is where container orchestration tools will come into play.
You can use other tools such as Kafka to let the containers communicate with each other. You can find out more about using Docker, Kubernetes, and Kafka with MongoDB in this blog post.
Container orchestration enables system administrators and DevOps engineers to maintain large server farms with thousands of containers. Without container orchestration, everything would need to be done manually and would quickly become unmanageable.
There are many benefits to using containers with container orchestration tooling.
Most modern container orchestration tools use configuration files, typically written in YAML, to describe the configuration for the containers. This configuration would include the name and location of the containers, the numbers of containers needed, the necessary network configurations, and so on.
Once this configuration file is applied to the orchestration tool, the tool will automatically manage the container based on the given specifications in the file.
The orchestrator will also monitor the health of the containers and restart them if needed, ensuring high availability and minimal downtime for your containers.
There are many orchestration tools available for containers; some of the most common are described here.
Kubernetes has gained much traction throughout the last few years and is now the most popular container orchestration tool available. Kubernetes is designed to work in multiple environments, including bare metal, on-premises VMs, and public clouds. These are the key components making up Kubernetes:
While MongoDB works very well with Kubernetes, setting up everything can be a lot of work. Thankfully, the Atlas Kubernetes Operator exists to make it much easier to add your Atlas instances to your Kubernetes environment.
Want to try out MongoDB on your laptop? Execute a single command, and you have a lightweight, self-contained sandbox; another command removes all traces when you're done. Need an identical copy of your application stack in multiple environments? Build your container image, and then your entire development, test, operations, and support teams can launch an identical clone environment.
Orchestration tools manage how multiple containers are created, upgraded, and made highly available. Orchestration also controls how containers are connected to build sophisticated applications from numerous microservice containers.
The rich functionality, simple tools, and powerful APIs make container and orchestration functionality a favorite for DevOps teams, integrating them into Continuous Integration (CI) and Continuous Delivery (CD) workflows.
Running MongoDB with containers and orchestration introduces some additional considerations:
It should be noted that while the orchestration framework might monitor the state of the containers, it is unlikely to monitor the applications running within the containers or backup their data. That means it's essential to use a robust monitoring and backup solution such as MongoDB Cloud Manager, included with MongoDB Enterprise Advanced. You can also use Kubernetes with Ops Manager in your infrastructure.
fuboTV provides a soccer streaming service in North America, and they run their full stack (including MongoDB) on Docker and Kubernetes; find out the benefits they see from this and how it's achieved in this case study.
Square Enix is one of the world’s leading providers of gaming experiences, publishing such iconic titles as Tomb Raider and Final Fantasy. They have produced an internal multi-tenant Database-as-a-Service using MongoDB and Docker—find out more in this case study.
Docker is a runtime to execute a container. It is used to manage the lifecycle of a single container at a time. Kubernetes is a container orchestration platform. It automates many processes around the management of containers.