Container 102
Hi everyone in the previous article, last time I talked about container technology, the difference between VM and Containers, Docker and its components. Now I will talk about container orchestration. Before I start explaining container orchestration, we must understand what is orchestration.
Orchestration
"describes automated arrangement, coordination, and management of complex computer systems, and services. It is often discussed as having an inherent intelligence or even implicitly autonomic control, but those are largely aspirations or analogies rather than technical descriptions."
For example, let's say we want to automate common tasks that do not require human interaction, let's assume we have a text file called config.txt
name = Omar
size = 3g
and we want to change the size from 3g to 5g, we can manually edit the file but we want to automate the edit. So we will create a workflow to edit this file after we create the workflow and automate the steps, the orchestration is deciding what better workflow or set of workflow to use to do a certain task. For more information about orchestration click here.
Container Orchestration
When there is thousands of container running it becomes difficult to manage all these containers so we want some way to manage these containers, we will use a container orchestration software and container orchestration for management of the deployment, placement, managing a set of containers, and it's also used to automate tasks and more.
A quick example of using container orchestration. Let's say we have a java application, first, we will create a Docker image that contains the java app. Then, we will put the image in a repository. After that, we will use the container orchestration software to run the java app in a container inside a cluster, and we can choose how many of replicas(copies) of the java app, and we can scale the java app, and if the app fails to start it will automatically kill the container then create a new one, without a container orchestration it will be hard to manage the app.
There are many orchestration software available in the market. Now I will start explaining Kubernetes.
What is Kubernetes
is an open-source system for automating deployment, scaling, and management of containerized applications.
Kubernetes is a portable, extensible for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.
Google open-sourced the Kubernetes project in 2014. Kubernetes builds upon a decade and a half of experience that Google has with running production workloads at scale, combined with best-of-breed ideas and practices from the community.
Kubernetes has a number of features. It can be thought of as:
- Scheduling: decide where containers should run
- Health: check the health of a container.
- Scaling: make sets of containers more or less
- Load balancing: distribute traffic across a set of containers
- Service Discovery: which tells Kubernetes where the container is in the Cluster
- A container platform for running applications, and abstracting away infrastructure.
- A microservices platform.
- A portable cloud platform and a lot more.
- Manage applications, not machines.
Kubernetes architecture
Here is the Kubernetes architecture and details features.
Kubernetes Cluster: consists of at least one master node and multiple worker nodes, and the node may be a virtual or a physical machine.
Master Node is a collection of processes are:
- Kubernetes API is used to exposes API for managing Kubernetes and could be used by Kubectl CLI
- Controller (kube-controller-manager) is a daemon that embeds the core control loops shipped with Kubernetes. In applications of robotics and automation, a control loop is a non-terminating loop that regulates the state of the system. In Kubernetes, a controller is a control loop that watches the shared state of the cluster through the apiserver and makes changes attempting to move the current state towards the desired state.
- Scheduler: selects the worker node for each pods runs
- Etcd: a highly-available key-value store and stores all cluster data
Worker Node is a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster. Each Node is managed by the Master. A Node can have multiple pods, and the Kubernetes master automatically handles scheduling the pods across the Nodes in the cluster. The Master's automatic scheduling takes into account the available resources on each Node.
Kubelet is an agent, which manages the node, and communicates with the master. Each worker also has tools for managing containers, such as Docker.
Docker (Container runtime): software that executes containers and manages container images on a node.
Kubectl is a command-line tool can be used to create, update, delete, and get API objects
Pod can be described as:
- Smallest deployment unit in Kubernetes
- Represents a running process on your cluster
- Consist of either a single container or a small number of containers that are tightly coupled and that share resources
- Has its own IP address
- Share resources like a PID namespace, network, and hostname
Service is an abstraction which defines a logical set of Pods and a policy by which to access them. The set of Pods targeted by a Service is (usually) determined by a Label Selector.
As an example, once the deployment is created and we have three worker node and the app may be run inside worker node 1 or 2 or 3, let's say runs inside worker node 1, to access the app we cannot access direct to the pod, if the pod's deleted or killed we will use the service to access the app
Another example, consider an image-processing backend which is running with 3 replicas. Those replicas are fungible - frontends do not care which backend they use. While the actual Pods that compose the backend set may change, the frontend clients should not need to be aware of that or keep track of the list of backends themselves. The Service abstraction enables this decoupling.
Namespace: Kubernetes supports multiple virtual clusters backed by the same physical cluster. These virtual clusters are called namespaces. In real-world scenarios, you can create a namespace for your development (dev), testing (QA), and production (prod) environments.
Volume is consistent storage that is independent of the Container. Container’s file system lives only as long as the Container does. So when a Container terminates and restarts, filesystem changes are lost.
The volume type:
- node-local types such as emptyDir or hostPath
- file-sharing types such as nfs
- cloud provider-specific types like ibmc-file-bronze, awsElasticBlockStore, azureDisk, or gcePersistentDisk
- distributed file system types, for example glusterfs or cephfs
- special-purpose types like secret, gitRepo
- A special type of volume is PersistentVolume is the low-level representation of a storage volume
Yaml file (.yaml) is a human-readable data serialization language. It is commonly used for configuration files, but could be used in many applications where data is being stored or transmitted.
When you create an object in Kubernetes, you must provide the object spec that describes its desired state, as well as some basic information about the object (such as a name). When you use the Kubernetes API to create the object (either directly or via kubectl), that API request must include that information as JSON in the request body. Most often, you provide the information to kubectl in a .yaml file. kubectl converts the information to JSON when making the API request.
What Next ?
I recommend to start trying Kubernetes hand-on, you can run a single node cluster locally or you can create Kubernetes service in the cloud.
To understand more I recommend you to build your own image using docker, then push it in docker hub then deploy your app in Kubernetes cluster, and try to scale your app and all useful features in Kubernetes. I recommend starting with this lab.
- You can try it locally by using Minikube
- You can try it in the Cloud By using IBM Kubernetes service
- You can find useful hands-on labs
- Start learn Helm, Helm helps you manage Kubernetes applications - Helm Charts help you define, install, and upgrade even the most complex Kubernetes application.
Conclusion
In this article, we learn about orchestration, container orchestration, Kubernetes, and its components. I hope you’re now familiar with the concept of container orchestration and maybe even use it in a project one day. Please share your comments or questions below.
Information Technology Security Consultant at IBM
5 年Great article
Solution Consultant @ ServiceNow | Software Engineering | Entrepreneurship | Digital Transformation | Product Management
5 年Nice Omar Alfawzan ????