Kubernetes | Docker | Containers All you need to know.

Lately there has been a lot of buzz around Kubernetes, docker and containers. Chances are, you have come across one of these terms. These are technologies whose popularity is growing very fast, as a developer you have every reason to learn and understand these technologies.

In this article We are going to demystify everything about kubernetes, docker and containers. By the end of this article you will be able to:

  • Explain to Anyone what Kubernetes is and how to use it.
  • Understand the architecture of kubernetes.
  • Create containers using Docker.
  • Explain to anyone what a container is.
  • Understand the architecture of containers.

At the heart of both kubernetes and Docker are the containers.

So what are Containers?

Container technology refers to the packaging of an application with all its dependencies into a single portable package.

Imagine as a developer having your code working perfectly on your local development environment but your code fails in production environment due to reasons such as varying dependencies or even different operating system. Yes, you could be working in windows operating system but deploying your code to Linux servers.

How are containers solving this problem?

A container bundles an application runtime environment into one package. This runtime environment includes all the application’s code, its configuration files, binaries and all the libraries required to run the application. By containerizing an application the differences in operating system, underlying infrastructure or any other differences are abstracted. This means that your container image is completely independent of the underlying infrastructure.

containers2
Container Archtecture

All the above containers share the operating system kernel of the host OS.

Comparing the above container architecture to the traditional virtual machines, containers are small light weight and portable. If the above architecture was to use virtual machines to run our applications then we would have 4 virtual machines, each running an entire operating system with its own kernel and the application service itself. This is resource intensive and undesirable in most cases.

VM
Virtual Machine Architecture

Since we now understand what a container is, we can dive into kubernetes and docker.

Docker

Docker is an application containerization platform that enables developers to build and run containers.

It makes it very easy to package and ship an application into a container.

Docker dates back to 2008, when Solomon Hykes in Paris Created “Dotcloud” as a Platform as a service (PaaS), that would later be renamed to Docker. Docker was released as an open source project in 2013 and was widely accepted by the developer community.

Important Docker Terminologies.

Dockerfile

This is a text file that contains instructions on how to build the container image. It contains commands that the docker engine will need to run in order to create the image.

Docker images

A docker image is an executable application source code bundled together with all the tools, libraries, and dependencies that the application code needs to run as a container. When you run the Docker image, it automatically becomes a container. A container is an image in runtime.

Docker containers

A Docker container is a running instances of a Docker image as stated above. Containers are ephemeral and executable.

Docker daemon

Docker daemon is a service running on your operating system, eg ubuntu or MS windows that manages docker images. It acts as the control center and allows you to execute commands to manage your images.

Docker Hub

This is the main repository for all docker images. Developers and software vendors can upload their images here. It also stores certified images by the Docker Trusted Registry. Developers and vendors can share images on Docker hub.

Kubernetes

Kubernetes is a container orchestration engine. Container orchestration is the monitoring, controlling and scaling of containerized workloads.

Docker still comes with its own container orchestration engine called docker Swarm but most developers choose kubernetes instead. This is mainly because kubernetes has a large open source support community and is currently the market leader in container orchestration.

Kubernetes surfaced in 2014 after being developed by engineers at google. This came as a replacement for borg which was google’s internal cluster management system. Google arguably runs everything in a container, it runs over a mind-boggling 2 billion containers just is a single week!!, breaking this down means about 7000 containers every second are started.

Kubernetes Architecture

k88
Kubernetes Architecture

Nodes

Is the actual virtualized machine in which a Pod runs. A node can group together pods that function together. A node is not always virtualized, it can a bare metal server in a data center. Nodes can be grouped together into a cluster, A cluster must have at least one Node.

Pods

To put it simple, a Pod is a single running instance of an application within a node and is the smallest unit of execution in kubernetes. Each pod containers a containerized application(Pods can run one or several containers). Pods in one Node can reach each other via localhost and share the same services such as storage.

By default pods are ephemeral but they can run stateful applications by connecting them to a persistent storage volume. Pods can scale horizontally, ie they can increase the number of instances depending on your application needs and specifications.

The pod is the core unit of management in the Kubernetes ecosystem and acts as the logical boundary for containers that share resources and context. Differences in virtualization and containerization are mitigated by the pod grouping mechanism, which enables running multiple dependent processes together.

To achieve scaling, pods use replica sets, which maintain a specific desired number of pods. A pod or a replica set can be exposed by a service to internal or external consumers.

A Deployment is a declarative way of defining your application’s life cycle and pods assigned to the application. It communicates to kubernetes controller about your applications desired state. The controller will ensure that your application maintains your desired state.

A pod is tagged with a label, while a service uses a label selector to identify which service it proxies to. A service automatically discovers any match between a pod label and a selector.

The following is a sample deployment.yaml file for nginx.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 4
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.17.0
        ports:
        - containerPort: 80

Container Runtime

A container runtime is a software platform on which containers run. The most widely used container runtime is the docker engine. Kubernetes still supports other runtime environments such as runC, containered and CRI-O.

Kubelet

A kubelet ensures that containers are running in a pod. It runs on each node in a cluster. It acts as a link between the control plane and the container runtime. The control plane executes actions on the node through the kubelet, for example starting a pod or a container.

Kube-proxy

This is a network proxy that facilitates kubernetes networking services on the nodes. It handles all the network communications inside or outside of your cluster by maintaining the network rules.

Scheduler

It’s key role is to assign newly created pods to a node. It does so by first considering the resources required by the pod such as CPU and memory before assigning the pod to the appropriate node.

etcd

It is a consistent, distributed and fault-tolerant key value store database that is used by kubernetes as a backing store for all the cluster data.

Controller Manager

The controller manager is a daemon that manages different controller processes. Examples of controllers that come built-in in Kubernetes today are the replication controller, endpoints controller, namespace controller, and serviceaccounts controller. The controller Manager takes care of nodes, workloads, service accounts , workloads among other things. The controller processes watch the status of different services running in the cluster and ensure the desired state of the cluster is maintained.

API server

The Kubernetes API server makes it possible for a user to interact with kubernetes clusters. It is the front end of the kubernetes control plane. It handles both internal and external requests. You can access the API through REST calls.

The API server provides 2 options, command line interface(CLI) and User Interface(UI).

Advantages of using kubernetes

  1. Portable and flexible — Kubernetes supports virtually all container runtime engines. It also runs on almost any type of underlying infrastructure.

2. Increased productivity — Due to the declarative nature of kubernetes, it has significantly changed application deployment process. Teams can now deploy applications faster than ever before.

3. It is open source with large community support — You do not have to incur any charges to run kubernetes. It is a fully Open sourced project overseen by the  CNCF. On top of this, kubernetes has a large community support.

4. It is a market leader — Kubernetes has been widely accepted and adopted by the developer community. A recent research proved beyond doubt that kubernetes adoption is growing really fast with 57% of respondents reporting to be using kubernetes in production.

Disadvantages of using kubernetes.

Despite kubernetes having many advantages and being the future of applications, it still have some significant drawbacks.

The main disadvantage of kubernetes is its complexity which can potentially reduce productivity. Kubernetes is known for its complexity and is always very hard to understand especially for developers who are not familiar with infrastructure technologies it can be very hard to get things working with kubernetes.

Conclusion

Kubernetes docker and containers are inter-related technologies that are here to stay and are arguably the future of infrastructure. This article gave you a broad overview of the 3 technologies. You can check the official documentation of docker and kubernetes.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x