Day 21 - Containers, Docker, and K8s
In this post, we'll provide a high-level overview of these powerful tools and show you how to get started using Docker and Kubernetes.
One of the technologies that are less than 10 years old but is commonly used today is Docker and the concept of Containerization of software.
In this post, we'll provide a high-level overview of these powerful tools and show you how to get started using Docker and Kubernetes.
At a super high level, Docker, Kubernetes, and all the other "containerization" platforms help with breaking down the code to microservices and running them across different environments with ease (or as easy as it gets 😬). It's the most common way for companies to build Saas products today.
You might recognize the DevOps and Microservices above which we explained before. 😎
Get the slides for this post for quick review.
What is Containerization?
Containerization is a software development technique in which applications are packaged and deployed in lightweight, standalone containers. Containers allow applications to be run in isolated environments, which helps to ensure that they are portable and can be easily deployed and run on any machine.
For engineers, Containerization simplifies the process of developing, testing, and deploying applications by eliminating the need to worry about differences in infrastructure and dependencies. It allows engineers to focus on writing code, rather than worrying about the underlying infrastructure.
It can also make it easier to scale applications and deploy them to different environments, such as between development, staging, and production environments. Remember Environments? 😉
What containerization platforms are out there?
There are a number of containerization platforms that are popular among developers for packaging and deploying applications in containers. Some of the most popular include:
Docker
Docker is a containerization platform that is widely used for developing, deploying, and running applications in containers. It is easy to use and has a large ecosystem of tools and resources.
Kubernetes
Kubernetes is an open-source container orchestration platform that is designed to be scalable and flexible. It is often used to manage large-scale deployments of containerized applications, and it is supported by all major cloud providers.
🤓 Have you seen Kubernetes being written as "K8s"? (which is still pronounced the same as "Kubernetes"). This technique of abbreviating is called "Numeronym". In the case of K8s, it's the first letter K, the last letter s, and 8 is the number of letters in between.
You might have also seeni18n
which is short for "Internationalisation", just like K8s.
Apache Mesos
Apache Mesos is a cluster manager that can be used to manage containers as well as other types of workloads. It is designed to be highly scalable and is used in a number of large-scale deployments.
Amazon Elastic Container Service (ECS)
Amazon ECS is a fully managed container orchestration service provided by Amazon Web Services (AWS). It is designed to be easy to use and integrates seamlessly with other AWS services.
Azure Container Service (ACS)
Azure Container Service is a fully managed container orchestration service provided by Microsoft Azure. It supports a number of different container orchestrators, including Kubernetes, and Docker Swarm.
We'll cover Docker and Kubernetes in this post.
What is Docker?
Docker is a containerization platform that allows developers to package and deploy applications in lightweight, standalone containers. Containers allow applications to be run in isolated environments, which helps to ensure that they are portable and can be easily deployed and run on any machine.
Using Docker can simplify the process of developing, testing, and deploying applications by eliminating the need to worry about differences in infrastructure and dependencies. It allows engineers to focus on writing code, rather than worrying about the underlying infrastructure.
Docker is widely used today because it offers a number of benefits, including:
Portability: Docker containers can be easily moved between different environments, such as between development, staging, and production environments.
Isolation: Docker containers provide isolated environments for running applications, which helps to ensure that applications do not interfere with each other.
Resource efficiency: Docker containers are lightweight and can be more resource-efficient than traditional virtual machines.
Common terms in Conterization-verse
Or more correctly, in Docker-world!
Dockerfile
A Dockerfile is a text file that contains instructions for building a Docker image. It is used to automate the process of building and deploying applications in containers.
It allows developers to define the steps needed to build an image and package an application in a container, which can make it easier to deploy the application to different environments.
A Dockerfile typically starts with a base image, which is an image that provides the foundation for the container. The base image might be an operating system image, such as Ubuntu or CentOS, or it might be an image containing a specific application or framework.
Image
An image is a blueprint for a container. It is a package that contains the code, libraries, and dependencies needed to run an application.
Container
A container is a lightweight, standalone package that contains an application and its dependencies. It is designed to be portable and can be easily run on any machine.
Containerization platform
A containerization platform is a piece of software that allows developers to package and deploy applications in containers. Examples of containerization platforms include Docker and Kubernetes.
Registry
A registry is a repository of images. It is a place where images can be stored, shared, and downloaded.
All in all, putting all the concepts together, here are the pieces of Docker put together:
Kubernetes
Kubernetes is an open-source platform for automating the deployment, scaling, and management of containerized applications. It consists of a number of components that work together to provide a flexible and powerful platform for managing containers.
At a high level, Kubernetes works by deploying containers onto a cluster of machines and then managing the containers to ensure that they are running as intended. The Kubernetes control plane is responsible for coordinating the activities of the various components in the cluster and making decisions about how to manage the containers.
Here are some of the key components of Kubernetes and how they work together:
Master nodes: The master nodes are the central control plane of the cluster. They consist of a number of components, including the API server, scheduler, and controller manager, which work together to manage the cluster.
Worker nodes: The worker nodes are the machines on which the containers are actually deployed and run. Each worker node runs a kubelet, which is responsible for managing the containers on that node.
Pods: A pod is the basic unit of deployment in Kubernetes. It is a logical host for one or more containers, and all the containers in a pod share the same network namespace and storage.
Deployments: A deployment is a higher-level object that manages the deployment of a set of replicas of a pod. It ensures that the specified number of replicas are running at all times, and it can be used to roll out updates to the pods.
Services: A service is an abstract way to expose a set of pods to external traffic. It provides a stable IP address and DNS name for the pods, and it can load balance traffic to the pods.
Overall, Kubernetes is a complex system with many components that work together to provide a flexible and powerful platform for managing containerized applications.
Docker vs. K8s
Docker and Kubernetes are both tools for developing and deploying applications in containers, but they have some key differences:
Scope: Docker is primarily a containerization platform, while Kubernetes is a container orchestration platform. This means that Docker is focused on building and running individual containers, while Kubernetes is focused on managing a cluster of containers and scaling applications across multiple machines.
Architecture: Docker uses a client-server architecture, with a daemon running on the host machine and a command-line interface (CLI) for interacting with the daemon. Kubernetes has a more complex architecture, with a number of components that work together to manage the cluster, including the API server, scheduler, and controller manager.
Ecosystem: Docker has a large ecosystem of tools and resources, including a registry for sharing images and a number of third-party tools for managing containers. Kubernetes also has a large ecosystem, but it tends to be more focused on enterprise-grade tools and solutions.
Deployment: Docker can be used to deploy applications in a variety of settings, including cloud and on-premises environments. Kubernetes is particularly well-suited to cloud deployments, and it is supported by all major cloud providers.
Container vs. Virtual Machines
You might have heard about Virtual Machines (from somewhere 👀). Containers and virtual machines are both technologies that allow developers to run applications in isolated environments. However, they have some key differences:
Isolation: Both containers and virtual machines provide isolation by running applications in separate environments, but they achieve this in different ways. Virtual machines use hardware virtualization to create a completely separate environment for each application, including a separate operating system and hardware resources. Containers, on the other hand, use operating system-level virtualization to share the host operating system and hardware resources but provide isolation for applications at the process and namespace levels.
Resource usage: Containers are generally more lightweight and resource-efficient than virtual machines, as they do not require a separate operating system and hardware resources for each application. This can make them more cost-effective for running applications in the cloud or on other shared resources.
Deployment: Virtual machines are typically deployed as a single entity, with the operating system and application bundled together. This can make them more difficult to deploy and manage at scale, as they require more resources and take longer to start up. Containers, on the other hand, are designed to be lightweight and portable, and they can be easily deployed and scaled using container orchestration platforms like Kubernetes.
Containers may be a good choice for applications that require isolation and portability, but have modest resource requirements, while virtual machines may be a better fit for applications with more demanding resource requirements or that require a dedicated operating system.
If you want to test them out
Getting Started with Docker
To get started using Docker, you'll need to install it on your machine. You can download the Docker Desktop for Windows or macOS from the Docker website.
Once Docker is installed, you can use the docker run
command to pull an image from a registry (such as Docker Hub) and run it as a container. For example, to run an Ubuntu container, you could use the following command:
docker run -it ubuntu
This will pull the latest version of the Ubuntu image from Docker Hub and run it as a container. You can then use the docker exec
command to execute commands inside the container. For example, to start a bash shell inside the container, you could use the following command:
docker exec -it <container-name> bash
Getting Started with Kubernetes
To get started using Kubernetes, you'll need to install it on your machine. You can download the Kubernetes command-line tool, kubectl, from the Kubernetes website.
Once kubectl is installed, you can use it to interact with a Kubernetes cluster. You can use the kubectl create
command to create resources in the cluster, such as pods and deployments. For example, to create a deployment that runs a single replica of an nginx container (more on this later), you could use the following command:
kubectl create deployment nginx --image=nginx
You can use the kubectl get
command to list the resources in the cluster, and the kubectl describe
command to get more information about a particular resource.
Summary
Docker and Kubernetes are powerful tools for developing, deploying, and managing applications. They can help to streamline the development and deployment process and make it easier to scale applications.
I hope this post has provided a useful introduction to these tools and has given you the confidence to start using them in your projects.
Happy containerizing!