As web applications become larger and more complex, the need to automate software development, infrastructure provisioning and maintenance is growing, too.
From tools that help with repetitive tasks such as deploying and updating apps on cloud native servers to full-fledged container orchestration solutions, automation in software development is a diverse and quickly developing field.
This article will present the benefits and shortcomings of two popular automation tools, Ansible and Kubernetes. Furthermore, it will provide use cases for each tool and suggest how you can use them together.
Ansible vs Kubernetes: Definitions
Ansible is an automation engine that automates application deployment, cloud provisioning, orchestration within a service and helps with configuration management. It is a declarative system that uses YAML-based Ansible Playbooks that use straightforward language to describe automation jobs.
Tools similar to Ansible are Jenkins, Puppet, Terraform Chef, Rudder, etc.
Note: Head to our blog for an in-depth comparison between Ansible, Terraform, and Puppet.
Kubernetes is an orchestration platform for automatization of deployment, management, and scaling of containerized apps. Kubernetes' primary function is cluster management. It also controls scheduling, execution, and management of Docker images on the server. It is compatible with many container tools and provides a unified API interface capable of managing complex systems spread across multiple servers and platforms.
For tools similar to Kubernetes, read the article featuring Best Container Orchestration Tools.
How Do They Work
Ansible works by pushing Ansible modules, standalone scripts contained in Ansible playbooks, to nodes. Ansible modules are designed to describe the desired state of the entire system, including the underlying infrastructure. They are executed over SSH and removed once the system reaches the desired state.
Ansible does not require servers, databases, or daemons. It uses a single "control node" to manage and monitor remote servers. The modules can be located on any server in the system. A simple INI file is used to list the managed machines in groups. Below is an example of the contents of one such file:
[webservers] www1.test.com www2.test.com [dbservers] db0.test.com db1.test.com db2.test.com
With Ansible, it is possible to add and remove machines from load balancers and monitoring windows, dynamically build configuration files, and centralize configuration management and deployment.
Kubernetes works by receiving user input through manifest files. These files contain the general description of the desired state of the cluster. Users interface with Kubernetes through kubectl, the default command-line interface. In turn, kubectl provides instruction to the Kubernetes API server.
The purpose of the API server is to automatically manage containers by following the declaration provided in the manifest file, ensuring that the current state of the cluster and the desired state are always the same.
Kubernetes clusters consist of sub-components, such as:
- Pods - Groups of containers on the same node that are configured to work together. Pods are the smallest unit of deployment in Kubernetes:
- Labels - Key/value pairs assigned to other elements to identify them
- Services - Pod groups operating under the same name and performing the same function. Services can be used as load balancers, controlling the distribution of traffic.
- Replication controllers - These are frameworks for ensuring that the correct number of pod replicas are scheduled and running at any given time.
For a more detailed explanation of how Kubernetes works, read this complete guide to Kubernetes.
For more comparison articles featuring Kubernetes, read:
Ansible: Pros and Cons
- Simple - Ansible is easy to set up and learn and features comprehensive and well-organized documentation. It is also simple to troubleshoot errors in Ansible because it runs tasks sequentially and halts upon encountering an error.
- Agentless - All communications regarding node management in Ansible are performed via SSH or the Paramiko module (an implementation of SSH2). In practice, this means that Ansible does not require any remote server agents, which improves the tool's performance and security.
- YAML-based - Ansible playbooks are essentially YAML files, which are easy to read and well-known to developers.
- Capable and efficient - The tool is able to handle complex workflows.
- Flexible - Many useful modules allow for easy customization of Ansible.
- Designed in Python - Python libraries are part of most Linux distributions, and developers often feel at home with Python.
- Free - Ansible is an open-source solution offered free of charge.
- Underdeveloped GUI - Ansible was conceived as a command-line tool. The later attempts to implement a GUI such as AWX and later Ansible Tower have not managed to transfer all the functionality of the CLI. The GUI can also fall out of sync with the CLI, resulting in inconsistent queries.
- Stateless - Unlike Terraform or Puppet, Ansible is a stateless system and does not keep track of dependencies. This may present a problem in scenarios where the environment changes.
- Poor Windows support - Currently, Ansible can be run on Windows, but Linux machines are still necessary to control Windows hosts. Ansible for Windows is a work in progress.
- Lack of community support - Ansible is relatively new in the market and has a smaller community of users than its competitors.
Kubernetes: Pros and Cons
- Highly scalable and efficient - Kubernetes allows horizontal scaling by adding or removing containers whenever the need arises to support increased or decreased workloads. This ability to adapt to circumstances is what makes Kubernetes an extremely resource-friendly tool.
- Enables container communication - Kubernetes provides a framework for containers to communicate and ensures they are always properly synchronized.
- Eliminates infrastructure lock-ins - With Kubernetes, organizations do not have to worry about the consequences of using multiple production and development environments. This is particularly useful in hybrid and multi-cloud scenarios.
- Declarative configuration - Kubernetes allows users to declare a desired state of the system and then makes sure that state is being maintained. Compared to imperative configuration, this approach is much less error-prone.
- Immutable - Building and deploying new container images is easy and safe, with the option to roll back the changes
- Self-healing - Kubernetes automates the process of monitoring replicas and introduces new ones in case of failure.
- Free - Kubernetes is an open-source project, available for free.
- Steep learning curve - Kubernetes is a complex system that uses many new technologies.
- Complexity - While applications for numerous and distributed users certainly benefit from Kubernetes' complexity, using the tool for simpler deployments can reduce productivity.
- Transition to Kubernetes can be difficult - Introducing it to your organization requires trained personnel and workflow adjustment.
How to Choose
Given the difference in the purpose of the two tools, you do not need to choose one or the other. Relying on one automation tool can be counter-productive in a software development environment. A broader automation strategy must be established before automation is introduced to an organization.
Kubernetes is not designed to manage the entire lifecycle of an application. Ansible is a good choice for the management of servers and applications inside of Kubernetes, and for the management of external integrations.
Kubernetes and Ansible can be used together and complement each other in a software development lifecycle as one highly cost-effective solution. While Kubernetes takes care of container health and management, Ansible can be used to deploy changes to hosts, configure systems, provision infrastructure and organize rolling updates and continuous deployments.
Lastly, Ansible is a great solution for automation of updates and other maintenance procedures of Kubernetes itself due to its easy-to-use nature and simple setup.
This article aimed to provide a comprehensive introduction to two popular automation tools, Ansible and Kubernetes. While they cannot be directly compared since they serve different purposes, Ansible and Kubernetes are both useful in application deployment and can be used to supplement each other.