The software development industry, just like any other, is very susceptible to trends. When you hear about a certain tool or technology all the time, it is natural to start wondering if you need to quickly catch up and use that trendy thing as well. Kubernetes is something everyone seems to be talking about, but does your company really need it? And if yes, then why? Let’s try to find some answers to these fundamental questions.
What is Kubernetes
In order to understand what Kubernetes is and what it can help you with, let’s first take a look at containers. Cloud computing is quickly becoming the norm, and as it changes the software development landscape, it becomes more and more important to create applications that can work in multiple environments without any issues. One of the most popular modern ways to achieve this is using containers for deploying applications, and Docker is typically the go-to container solution.
Containers
Containers are a way to package and deliver the code of your application as lightweight, isolated, easily replaceable multiple instances that can be successfully deployed in different environments. Each container packages all the dependencies that a service or an app in the container requires, making them highly portable.
Even though containers as a concept were introduced even before Docker, it was thanks to Docker that the use of containers became mainstream. Docker did it by providing a toolkit that allows you to conveniently build container images. It is possible to deploy Docker containers on any platform that supports them, and, unlike a virtual machine, containers use the host OS resources more efficiently.
It is perhaps worth mentioning that containers are often imagined as closely linked to microservices architecture, and indeed if you have a microservices app, it is likely that the best way to manage it would be by using containers. However, in fact, containers are not mandatory for microservices.
So Docker helps you to create containers and handle them as well, but once the number of running containers increases, it becomes impossible to manage them without a special container orchestration tool. Container runtime APIs are better suited for managing individual containers, so if your application consists of multiple services, and you need to orchestrate hundreds of containers across multiple hosts, you will need more than Docker’s capabilities can offer.
Kubernetes
Although multiple container management tools exist, Kubernetes is definitely the most popular, and its popularity is only increasing. A report conducted by the Cloud Native Computing Foundation in 2021 showed that the percentage of developers who use Kubernetes grew by 67% in just one year. According to the same report, 96% of surveyed organizations are either already using Kubernetes or evaluating it.
So what exactly is Kubernetes? This container orchestration platform provides the capabilities to manage large numbers of containers, that is, deploy them across multiple environments, balance containerized workloads, ensure security, and so on. It was originally designed by Google for its own needs, but in 2014 Kubernetes was released as an open-source platform, and since then it has essentially become an industry standard for managing containerized apps.
Kubernetes: how it works
The main purpose of Kubernetes is to facilitate deployment and management of complex distributed systems using containers. But let’s try to understand what exactly the Kubernetes platform does for your containerized services and applications.
The basic building block of Kubernetes is a pod, which can run one or more containers on the same machine. Pods allow you to optimize the use of resources and reduce the network overhead. You can create pods manually or use configuration files to define them.
Configuration files are text files that describe how your application components will interact with each other and with the environment. They specify things like where to get the container images from (a local or remote container registry), how much resources to allocate, and how to connect containers to each other and to external resources. Configuration files also enable Kubernetes to create new pods when needed, for example, when a pod fails or when you need to scale up your application.
When the setup is done, Kubernetes monitors the system and fixes problematic situations, restoring the desired state if real events don’t match the configuration requirements. Kubernetes provides load balancing across a cluster, automates rollouts and rollbacks, service discovery, and secret and configuration management.
It is crucial to remember though, that Kubernetes itself is not a platform-as-a-service. Developer teams that don’t have any experience with Kubernetes deployment might have a hard time at the beginning, because Kubernetes has a pretty steep learning curve. However, Kubernetes also gives your team a lot of freedom in choosing the best deployment options, since it is OS-agnostic, platform-agnostic, and programming language-agnostic.
Why use Kubernetes
It is possible to use Docker and containers in general without using container orchestration tools, but if the number of your running containers reaches thousands, managing them manually will become an untenable task.
Besides actually running the containers, you need to be able to scale them up and down, ensure communication across the cluster, take care of fault tolerance, and perform other tasks. Without a special tool, DevOps teams would be forced to waste a lot of time on doing all this manually. But that is not the only reason to use Kubernetes, there are multiple other benefits.
Reliability
Kubernetes is a way to make your containerized applications more stable and reliable. It can automatically scale up pods of containers when the traffic increases. Kubernetes monitors containers and nodes and can restart or replace them, thus providing self-healing capabilities.
Kubernetes also allows you to redistribute workloads in a multi-node Kubernetes cluster, ensuring longer application uptime and high availability.
Automation
It doesn’t matter if you host your app on-premises, across a set of virtual machines, or in a public cloud, scaling your multi-container application or restoring it to a working state after a failure manually is often highly inefficient. Kubernetes provides you with automatic scaling and rollback capabilities, which allows your team to manage clusters and nodes, expending less time and effort.
Portability
One of the most prominent features of containers is being more agile and lightweight than virtual machines. With containers not only can you run multiple applications on the same server using fewer resources, but you can also easily move your applications to a different system if you want.
Combining Kubernetes with containers makes vendor lock-in even less probable, because you can run Kubernetes on any kind of underlying infrastructure, as long as the host OS is a version of Windows or Linux. Kubernetes is very flexible because it can work basically with any container runtime.
Faster development
It is often considered to be a benefit of using containers in general, that when your application consists of small modular elements, you can get from the first idea to the final product quicker. You need much smaller development teams, working on separate smaller components that make up your application, and the workflow becomes much more agile, because each team concentrates on their part of the app.
However, without Kubernetes, containers alone are often not enough to ensure faster development. You can concentrate on making each component and, respectively, a single container image, only be responsible for a specific part of the business logic because Kubernetes allows you to then manage a pod of containers together anyway.
Easy cloud migration
You might start building your containerized app using the infrastructure on-premises but with Kubernetes, moving to the cloud will always be an accessible option. Kubernetes clusters make the migration to a public cloud or a private cloud fast and simple. Moreover, with Kubernetes you can either choose a single cloud for your container workloads or spread them across several major cloud providers, like Google Cloud Platform, Amazon Web Services, and Microsoft Azure. All of these cloud providers offer integration with Kubernetes-managed apps.
Open-source ecosystem
Kubernetes is an open-source solution that grows more and more popular by the day. There is a vast ecosystem of other tools that are specifically designed to be used with it. Ever-increasing community support also means your investments in Kubernetes are secure, since it is not likely that the improvements will stop anytime soon. It is not likely to get locked in with a specific technology that might get outdated at some point.
Security
Kubernetes offers some robust secret and configuration management features that increase the security of your containerized apps. You can securely store and manage sensitive data, including SSH keys, OAuth tokens, and passwords. With Kubernetes you don’t even have to rebuild container images when you deploy and update the app configuration and secrets, and your stack configuration won’t expose the secrets.
When you need Kubernetes
With all the benefits that Kubernetes can offer, no wonder so many businesses are considering it. But adopting it just because everyone else is might be a big mistake. There are certain cases when Kubernetes is the right decision, and you need to consider your current situation very carefully before going with it.
For instance, if you already have a legacy application that has monolithic architecture, you most likely don’t need Kubernetes right now. Indeed, scaling a monolith can be a complicated task, but Kubernetes won’t be a magical solution that will automatically get rid of all the issues.
At the early stages of scaling out a monolith, it might be enough to use other solutions with much less administrative overhead. Configuration management tools like Ansible can help you with automatic configuration of new servers, for example, and a database bottleneck can be removed by using a high-performance in-memory data store, like Redis, to reduce the database load.
When your monolithic application becomes too large and you start thinking about moving to distributed architecture, you still might not need Kubernetes at once. If you start adding new services, even microservices, you might still be better off starting with a single-cloud platform, like AWS Fargate, and not a Kubernetes cluster that is much more difficult to manage.
What if you are starting from scratch and decide to go with microservices architecture from the beginning? Still, it is very likely you won’t need Kubernetes at once when you just have two or three services in your app, especially if your team is not ready to adopt this really complex solution yet.
So when you finally move away from the monolith completely to microservices, or when your small app with just a couple of microservices grows so much there are dozens of microservices, that would be the right time to use Kubernetes to orchestrate your microservices containers. This is when you are more likely to actually save some money using Kubernetes than waste it.
Kubernetes is a tool that has lots to offer when you know why you are using it and what exactly you are using it for. Consider your current business situation and your plans for the future, and you will be able to see very clearly if Kubernetes can help you achieve your goals.
If you are looking for more examples of possible Kubernetes usage, you might be interested in this article, where we described some Kubernetes use cases.
Is Kubernetes the only container orchestration tool?
These days there are multiple tools for managing containerized applications besides Kubernetes. Some of the most popular include Docker Swarm, Nomad by HashiCorp, Marathon for Apache Mesos, and ECS Container Service by AWS. All of these Kubernetes alternatives offer slightly different possibilities.
Docker Swarm, for example, is less complex than Kubernetes to set up at the beginning, but it’s efficient only if you plan to use your own underlying infrastructure. Docker Swarm can do some of the same things that Kubernetes can, like use declarative YAML configuration files to deploy your app, scale services across the cluster automatically to achieve the desired state, provide load-balancing, security, and access control.
However, Docker Swarm doesn’t have the same flexibility and all the features that Kubernetes offers, and typically works best when you don’t have that many workloads running. Also, as you might expect from its name, Docker Swarm can only work with Docker containers, while Kubernetes is not restricted to only containers created with Docker.
Apache Mesos is an open-source cluster management tool that provides APIs for apps to enable scheduling and resource management across the cluster. Mesos itself is not a complete alternative to Kubernetes, but it has a special framework for container orchestration, called Marathon. The main features of Marathon are similar to what Kubernetes offers, including service discovery, metrics, scalability support, and so on.
There are certain differences as well, for example, when managing stateful containers with Kubernetes you can create multiple types of persistent storage, while Mesos allows you to create persistent volumes only from the reserved resources. There are also certain differences in networking support, with Mesos allowing two types: network port-mapping and IP-per-container. Meanwhile, Kubernetes assigns a unique IP to each container pod which defines how pods can communicate across nodes and removes the necessity to map container ports to the host port.
Mesos with Marathon can be considered even more complex than Kubernetes, so when you start from scratch, if you plan to use only containers, then Kubernetes is your choice. You might want to think about Mesos if you want to handle both non-containerized and containerized workloads, or if you have to deal with very large clusters of up to 10000 agents.
ECS from AWS is another option. AWS offers its own autoscaling, flexible resource management, and network load-balancing functionality. In some cases it might be cheaper than Kubernetes and require a smaller DevOps team to manage containers on EC2 instances. However, if your plans include using multiple public cloud providers, a hybrid cloud environment, or on-premises infrastructure, then Kubernetes will enable you to manage your containerized app exactly the way you like. webinar
Conclusion
Implementing a new solution just because it comes highly recommended and everyone is talking about it, might turn out to be a big mistake. Consider Kubernetes and its advantages very carefully. You can’t really say that Kubernetes makes container management easy. The sheer number of available features can seem daunting and require a lot of learning by your software development teams.
However, in certain cases, Kubernetes definitely is the best solution with its impressive capabilities for automation, self-healing, load-balancing, and more, basically everything you need to successfully run the containers that make up your application either on-premises or in a public cloud.
Moreover, all major public cloud providers offer managed Kubernetes services, so that might be an easier, albeit not the cheapest, way to enjoy all the benefits that Kubernetes offers. Containers will definitely stay popular for quite some time, and Kubernetes is one of the most flexible and powerful tools for managing containers that is available at the moment.