Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

A Complete Introduction to Kubernetes — an Orchestration Tool for Containers

DZone's Guide to

A Complete Introduction to Kubernetes — an Orchestration Tool for Containers

What tool orchestrates your containers with ease? KU-BER-NE-TES! You nodes and your ports, everything in between? KU-BER-NE-TES!

· Cloud Zone ·
Free Resource

See why enterprise app developers love Cloud Foundry. Download the 2018 User Survey for a snapshot of Cloud Foundry users’ deployments and productivity.

Kubernetes is Greek for “Captain” or “Pilot”. Kubernetes was born in Google. It was donated to CNCF in 2014 (open source). It is written in Go language. It focuses on building a robust platform for running thousands of containers in production.

Kubernetes repository is available on GitHub.

What is Kubernetes?

Kubernetes (or just K8s) is an open source orchestration system for Docker containers. It lets us manage containerized applications in a clustered environment. It simplifies DevOps tasks such as deployment, scaling, configuration, versioning, and rolling updates. Most of the distributed applications built with scalability in mind are actually made up of smaller services called microservices and are hosted and run through a container.

A container provides an isolated context in which an app/microservice together can run with its environment. But containers do need to be managed externally and must be scheduled, distributed, and load balanced to support the needs of modern apps and infrastructure. Along with this, data persistence and network configuration makes it hard to manage containers and therefore, however powerful containers are, they bring scalability challenges in a clustered environment.

Kubernetes provides a layer over the infrastructure to address these challenges. Kubernetes uses labels as name tags to identify its objects, and it can query based on these labels. Labels are open-ended and can be used to indicate role, name, or other important attributes.

Kubernetes Architecture:

Kubernetes ArchitectureKubernetes Master:

The controlling services in a Kubernetes cluster are called the master, or control plane, components. They are in charge of the cluster and monitor the cluster, make changes, schedule work, and respond to events.

Kubernetes Master

The Kubernetes Master is a collection of four processes that run on a single node in your cluster, which is designated as the master node. 

  1. Kube-apiserver

    It is the brain to the master and is front-end to the master or control plane. Kube-apiserver implements the RESTful API and consumes json via a manifest file. Manifest files declare the state of the app like a record of intent and are validated and deployed on the cluster. It exposes an endpoint (by default on port 443) so that kubectl (command line utility) can issue commands/queries and run on the master.
  2. Cluster Store

    It provides persistent storage and is stateful. It uses etcd. It is distributed, consistent and watchable. etcd – etcd is open source distributed key-value store that serves as the backbone of distributed systems by providing a canonical hub for cluster coordination and state management. Kubernetes uses etcd as the “source of truth” for the cluster. It takes care of storing and replicating data used by Kubernetes across the entire cluster. It is written in Go language and uses Raft protocol, which helps etcd in recovering from hardware failure and network partitions.
  3. Kube-controller-manager

    Kubernetes controller manager is a daemon that implants the core control loops shipped with Kubernetes. It is the controller of controllers. It watches the shared state of the cluster through the API server and makes changes attempting to move the current state towards the desired state. Examples of controllers that ship with Kubernetes today are the replication controller, endpoints controller, namespace controller, and service accounts controller. At the point when a change is seen, the controller reads the new information and implements the procedure that fulfills the desired state. This can involve scaling an application up or down, adjusting endpoints, and so forth. A Replication controller provides a pod template for creating any number of pod copies. It provides logic for scaling pod up or down. It can also be used for rolling deployments.
  4. Kube-scheduler

    This is the process that watches API-server for new pods and assigns workloads to specific nodes in the cluster. It is responsible for tracking resource utilization on each host to make sure that workloads are not scheduled in excess of the available resources.

Kubernetes Node:

The servers that do the actual work are called as nodes.

Image title

Each node in a cluster runs two processes:

  1. Kubelet

    • the main Kubernetes agent on the node
    • registers node with the cluster
    • watches API server for work assignment
    • instantiate pods for carrying out the work
    • reports back to master
    • exposes endpoint on port-10255. It lets you inspect the specs of a Kubelet.
  2. Kube-proxy

    It is like the network brain of the node. It is a network proxy which reflects Kubernetes networking services on each node. It ensures every pod gets its own unique IP. If there are multiple containers in a pod, then they all will share same IP. It load balances across all pods in a service.

Kubernetes Objects:

  1. Pod

    A pod is the basic building block of Kubernetes and is deployed as a single unit on a node in a cluster. A pod is a ring-fenced environment to run containers. Usually, you will run only one container inside a pod but in some cases where containers are tightly coupled, you can run two from a pod. A pod is connected via an overlay of networks to the rest of the environment. Each pod is assigned a unique IP address. Every container in a Pod shares the network namespace, including the IP address and network ports.
  2. Service

    Kubernetes Pods are mortal and when they die they can not be resurrected. As Kubernetes has to maintain the desired state of the app, when pods crash or go down, new pods will be added which will have a different IP address. This leads to problems with the pod discovery as there is no way to know which pods are added or removed. This brings service into action. A service is like hiding multiple pods behind a network address. Pods may come and go but the IP address and ports of your service remain the same. Any other applications can find your service through Kubernetes service discovery. A Kubernetes Service:
    • is persistent
    • provides discovery
    • load balances
    • provides VIP layer
    • identifies pods by label selector
  3. Volume

    A volume represents a location where containers can store and access information. On-disk files in a container are ephemeral and will be lost if a container crashes. Secondly, when running containers together in a Pod it is often indispensable to share files between those containers. A Kubernetes volume will outlive any containers that run within a pod and data is preserved across container restarts. For applications, volumes appear as part of a local file system. Volumes may be backed by other storage backends like local storage, EBS etc
  4. Namespace

Namespace functions as grouping mechanism within Kubernetes. Services, pods, replication controllers, and volumes can easily cooperate within a namespace. It provides a degree of isolation from other part of the cluster. Namespaces are intended for use in environments with many users spread across multiple teams, or projects. Namespaces are a way to divide cluster resources between multiple uses.

Conclusion

Kubernetes is exciting!! It is an amazing tool for microservices clustering and orchestration. It is relatively new and under active development. I believe it is going to bring a lot of functional improvements in how a clustered infrastructure is managed.


If you want to get started with deploying containerized apps to Kubernetes, then minikube is the way to go. Minikube is a tool that helps you deploy Kubernetes locally.

Cloud Foundry saves app developers $100K and 10 weeks on average per development cycle. Download the 2018 User Survey for a snapshot of Cloud Foundry users’ deployments and productivity. Find out what people love about the industry standard cloud application platform.

Topics:
kubernetes ,docker ,kubelet ,minikube ,container ,container management ,container deployment ,cloud

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}