Intro to Kubernetes

Intro to Kubernetes

Getting started with Kubernetes

Kubernetes Introduction

  • Kubernetes is an open source container management tool which automates container deployment, container scaling and load balancing.
  • It schedules, runs and manages isolated containers which are running on virtual/physical/cloud machines.
  • All top cloud providers support Kubernetes.

  • History of Kubernetes

  • Google developed an internal system called 'borg' (later named as Omega) to deploy and manage thousands google application and services in their cluster.
  • In 2014, google introduced Kubernetes an open source platform writen in 'Golang' and later donated to CNCF(Cloud Native Computing Foundation)

  • Online Platform for K8s

  • Kubernetes Playground
  • Play with K8s
  • Play with kubernetes classroom

  • Cloud based K8s Service

  • GKE: Google Kubernetes Services
  • AKS: Azure Kubernetes Services
  • Amazon EKS: Elastic Kubernetes Services

  • Kubernetes installation tool

  • Minicube
  • Kubeadm

  • Problems with Scaling up the containers without kubernetes

  • Containers can't communicate with each other
  • Autoscaling and load balancing was not possible.
  • Containers had to be managed carefully.

  • Features of Kubernetes

  • Orchestration (Clustering of any no. of containers running on different networks)
  • Autoscaling(Vertical and horizontal scaling)
  • Auto-Healing
  • Load Balancing
  • Platform independent(cloud/virtual/physical)
  • Faulttolerance(Node/POD failure)
  • Rollback(going back to previous version)
  • Health monitoring of containers
  • Batch execution (one time, sequential, parallel)

  • Kubernetes vs Docker Swarm

    Features Kubernetes Docker swarm
    Installation and cluster configuration Complicated and time consuming Fast and Easy
    Supports K8s can work with almost all container types like Rocket, Docker containers. Work with docker only
    GUI GUI Available GUI not available
    Data Volumes Only shared with containers in same pod Can be shared with any other container
    Updated & Rollback Process scheduling to maintain services while updating Progressive updates & service health monitoring throughout the update
    Autoscaling Supports vertical and horizontal autoscaling Not support autoscaling
    Logging and monitoring Inbuilt tool present for monitoring Use 3rd party tools such like splunk

    There's also an another tool - Apache Marathon.


    Architecture of Kubernetes

    Cluster

    A cluster is all of the above components put together as a single unit.

    We've two main components in Kubernetes architecture-

  • Master
  • Worker(Nodes)
  • Working with Kubernetes

  • We create manifest(yml)
  • Apply this to cluster(to master) to bring into desired state.
  • Pod runs on node, which is controlled by master.
  • Control Plane(Master)

    The Kubernetes control plane is the main entry point for administrators and users to manage the various nodes. Operations are issued to it either through HTTP calls or connecting to the machine and running command-line scripts. As the name implies, it controls how Kubernetes interacts with your applications.

  • Kubernetes cluster contains containers running or bare metal/vm instances/cloud instances/ all mix.
  • Kubernetes designates one or mroe of these as master and all others workers.
  • The master is now going to run a set of k8s process. These processes will ensure smooth functioning of cluster. These processes are called Control Plane.
  • Can be multimaster for high availability.
  • Master runs Control Plane to run cluster smoothly.
  • Components of Control Plane

      ####
    1. Kube API Server The API server exposes a REST interface to the Kubernetes cluster. All operations against pods, services, and so forth, are executed programmatically by communicating with the endpoints provided by it.
      • This API server interacts directly with user(i.e we apply yml or json manifest to kube-apiserver)
      • This kube-api server is meant to scale automatically as per load.
      • Kube api-server is front-end of control plane.
      ####
    2. etcd etcd is a distributed key-value store that Kubernetes uses to share information about the overall state of a cluster. Additionally, nodes can refer to the global configuration data stored there to set themselves up whenever they are regenerated.
      • Stores metadata and states of cluster.
      • etcd is consistent and high availability store(key-value store)
      • Source of touch for cluster state(info about state of cluster)
      • etcd has following features:
        1. Fully replicated: The entire state is available on every node in the cluster
        2. Secure: Implements automate TLS with optional client-certificate authentication
        3. Fast: benchmarkes at 10000 writes per second.
      ####
    3. Scheduler The scheduler is responsible for assigning work to the various nodes. It keeps watch over the resource capacity and ensures that a worker node’s performance is within an appropriate threshold.
      • When user make request for the creation & management of pods, kube-scheduler is going to take action on these requests.
      • Handles POD creation and management.
      • Match/assign any node to create and run pods.
      • A scheduler watches for newly created Pods that have no node assigned. For every pod that the scheduler discovers, the scheduler becomes responsible for finding best node for that pod to run on.
      • Scheduler gets the information for hardware configuration from configuration files and schedules the Pods on node accordingly.
      ####
    4. Controller manager The controller-manager is responsible for making sure that the shared state of the cluster is operating as expected. More accurately, the controller manager oversees various controllers which respond to events (e.g., if a node goes down).
      • make sure actual state of cluster matches to desired state.
      • Two possible choices for control manager.
        1. If k8s on cloud, then it will be cloud controller manager.
        2. If k8s on non-cloud then it will be kube-controller-manager.
      #### Components on master that runs controller
      • Node-controller: For checking the cloud provider to determine if a node has been detected in the cloud after it steps responding.
      • Rout-controller: Responsible for setting up network, routes on your cloud.
      • Service-controller: Responsible for load balancer on your cloud against services of type load balancer.
      • Volume controller: For creating, attaching and monitoring volumes and interacting with the cloud provider to orchestrate volume.

    ### Nodes A Kubernetes node manages and runs pods; it’s the machine (whether virtualized or physical) that performs the given work. Just as pods collect individual containers that operate together, a node collects entire pods that function together. When you’re operating at scale, you want to be able to hand work over to a node whose pods are free to take it. ### Services A service is an abstraction over the pods, and essentially, the only interface the various application consumers interact with. As pods are replaced, their internal names and IPs might change. A service exposes a single machine name or IP address mapped to pods whose underlying names and numbers are unreliable. A service ensures that, to the outside network, everything appears to be unchanged. ### Worker node components
      ####
    1. Kubelet A Kubelet tracks the state of a pod to ensure that all the containers are running. It provides a heartbeat message every few seconds to the control plane. If a replication controller does not receive that message, the node is marked as unhealthy.
      • Agent running on the node.
      • Listens to kubernetes master.(communicates controller, pod create request)
      • Use Port- 10255
      • send success/fail report to master.
      ###
    2. Container Engine
      • Works with kubelet
      • Pulling images
      • Start/stop containers
      • Exposing containers on ports specified in mainfest.
      ####
    3. Kube proxy The Kube proxy routes traffic coming into a node from the service. It forwards requests for work to the correct containers.
      • assign IP to each pod.
      • It is required to assign IP addresses to PODs(dynamic)
      • Kube-proxy runs on each node & will get its own unique IP address.

    Pods

    A Kubernetes pod is a group of containers, and is the smallest unit that Kubernetes administers. Pods have a single IP address that is applied to every container within the pod. Containers in a pod share the same resources such as memory and storage. This allows the individual Linux containers inside a pod to be treated collectively as a single application, as if all the containerized processes were running together on the same host in more traditional workloads. It’s quite common to have a pod with only a single container, when the application or service is a single process that needs to run. But when things get more complicated, and multiple processes need to work together using the same shared data volumes for correct operation, multi-container pods ease deployment configuration compared to setting up shared resources between containers on your own.

    • Smallest unit in kubernetes.
    • POD is a group of one or mroe containers that one deployed together on the same host.
    • A cluster is a group of nodes.
    • A cluster has atleast one worker node and master node.
    • In kubernetes, the control unit is the POD, not containers.
    • Consist of one or mroe tightly coupled containers.
    • POD runs on node, which is controlled by master.
    • Kubernetes only knows about PODS.(does not know aboout individual containers)
    • Can't start containers without a POD.
    • One POD usually contains one container.

    Multi-Container PODS

    • Share access to memory space.
    • connect to each other using localhost.
    • Share access to the same volume.
    • Containers within pod are deployed in an all-or-nothing manner.
    • Entire pod is hsoted on the same node(Scheduler will decide about which node )

    Limitations of POD

    • No auto-healing or scaling.
    • POD crashes.

    Higher level kubernetes Objects

    • Replication Set:
      Scaling and healing
    • Deployment:
      Versioning and Rollback
    • Service:
      Static(non-ephemeral) IP and networking
    • Volume:
      Non ephemeral storage.

    Important Commands

    • kubectl
      For single cloud
    • kubeadn
      On premise
    • kubefed
      Hybrid clouds


    Did you find this article valuable?

    Support KubeKode Blogs by becoming a sponsor. Any amount is appreciated!