1 of 11

Kubernetes

K. V. Raghavan

Indian Institute of Science, Bangalore

2 of 11

Containers alone do not suffice for a microservice architecture

  • It is a lot of manual work to
    • identify downed nodes/containers and bring them back up
    • implement a load balancer, which decides which replica is least lightly loaded and should be sent a new request
  • IP addresses nightmare
    • every microservice instance would have its own IP address
    • the IP address changes every time a container goes down and is potentially brought up on a different node
    • other microservices would not know which IP address to contact
  • Hence the need for a container management and orchestration tool

3 of 11

What is Kubernetes?

  • You provide a set of nodes (a cluster) under the management of Kubernetes
    • You can add nodes on-the-fly to the cluster (e.g., when existing nodes go down), but Kubernetes cannot discover nodes and works only with the given nodes
  • You specify declaratively the desired state of the application:
    • conceptually, the state is a set of objects with their attributes
    • e.g., the images of the microservices, the number of instances desired of each microservice, load balancing requirements
  • Kubernetes automatically monitors and drives the system towards the desired state whenever things break
  • Kubernetes basically is a distributed system/platform for hosting distributed applications

4 of 11

Basic Kubernetes objects

  • A pod is a collection of related containers, running on the same node
    • In most cases, a pod will contain a single container
    • Pod is the smallest unit of deployment. A pod can be deployed individually, although this is not usually done
  • A deployment is a set of pods
    • created from a single image if each pod contains a single container
    • created from two images if each pod is to have two containers, and so on
    • specified with desired number of replicas, or desired range of number of replicas
    • each pod will have its own IP address
    • the set of pods in a deployment can keep changing due to scale up or down, container crashes and restarts, etc.
      • when a pod is restarted, it will not retain its old IP address in general

5 of 11

Basic Kubernetes objects -- II

  • A service
    • is a wrapper around a deployment
    • is like a built-in microservice of Kubernetes, and is basically a load balancer
    • its only job is to direct each incoming request to one of the pods in the underlying deployment (no control of which pod it will choose for each request)
      • hence useful when our deployment is for a replicated, stateless service
    • service has an IP address which clients will use (they need not know the IP addresses of the individual pods)
      • service can also have a hostname using Kubernetes DNS service, so that in the code of other services they refer can refer to this logical hostname for their http requests (e.g., http://walletservice:8080)

6 of 11

Basic Kubernetes objects -- III

  • More on services
    • A service can be of two types (more types also exist, but we ignore them)
      • LoadBalancer, for providing externally visible IP address or hostname to outside clients
      • ClusterIP, for providing internal IP address or hostname visible only to other microservices within the same Kubernetes cluster
        • despite the name, this type also balances incoming requests to the different pods
    • A service in Kubernetes is not exactly the same as a service in SoA
      • Service in SoA is a conceptual collection of related business-level operations (typically stateful)
      • Whereas in Kubernetes, it is a concrete feature used for deploying a replicated, loadbalanced, set of stateless microservice instances (i.e., it is a way of deploying a loadbalanced microservice)

7 of 11

Basic Kubernetes objects -- IV

  • A StatefulSet
    • Is an alternative to a deployment
      • given an image, creates a set of pods out of it
    • You cannot wrap a service around a StatefulSet
    • The pods are given fixed logical hostnames
      • For a StatefulSet called name, the logical hostnames of the pods will be name-0, name-1, .., name-n, where n is the given replication factor
      • If a pod has to be restarted
        • it will retain its logical hostname
        • any disk volume that was mounted to it will be migrated and re-mounted and made available
    • Hence, StatefulSets are useful for deploying stateful microservices, as long as state is maintained by each pod within its disk volume and not in memory

8 of 11

Basic Kubernetes objects -- V

  • More on StatefulSets
    • Typically, clients will not want to directly send requests to pods
    • Therefore, a separate front-end sharding microservice may need to be implemented by the developer using code
      • This microservice receives all requests from the client
      • Inspects each request, decides which shard (which pod) the request needs to be sent to, and sends it there

9 of 11

Yaml/Json

  • The desired state we need can be specified using
    • a sequence of commands (kubectl commands)
    • or, by supplying YAML/JSON files using “kubectl apply -f yaml-file-name”
    • real applications typically use the latter approach above
  • We can update the desired state at runtime if we need to

10 of 11

Kubernetes control plane

  • Control plane is the controlling software within Kubernetes
    • Control plane software runs on all the nodes (in addition to the deployments/pods)
  • Keeps track of the health and status of all nodes and all pods
    • Uses standard protocols of distributed computing systems (DCS) to continually track the status of each node in the cluster, in spite of nodes or links going down, cluster-partitioning, etc.
  • Schedules the pods on the nodes when a new deployment or statefulset is submitted (by finding relatively less loaded nodes)
  • Restarts stopped containers on other nodes, moves disk volumes along with statefulset pods, etc.
  • Keeps track of IP addresses of nodes and pods, provides internal DNS service for IP addresses, etc.

11 of 11

Required reading and activities

  • Google Kubernetes tutorial
    • Required to read it
    • Recommended (but not mandatory) to try it out on Google Cloud
  • Notes by K. V. Raghavan, available on the course web page, on replicating the same tutorial above on your own computer using minikube
    • It is mandatory for you to actually carry out this tutorial on your machine
  • Brief introduction to Kubernetes
  • Official Kubernetes documentation
    • Read about only the parts covered in class