Kubernetes Up and Running

Authors: Kelsey Hightower, Brendan Burns, and Joe Beda
Reviewers: Ravish Bhatia, Sneha Ghosh

This book is a brilliant read for IT professionals and learners who are looking for a direction to start with Kubernetes or wish to get their basics right. The practical approach of the authors to define each K8 (short for Kubernetes) commands with explanation, makes it a delightful journey even for a reader with no prior understanding about the concept. Though, the authors have made best effort to explain the basics of dockers and containers, however, it is highly advisable to have some prior knowledge about it.

Chapter 1: Introduction

This chapter provides a quick introduction to Kubernetes illustrating its several benefits. Kubernetes is an open source tool for deploying containerized applications and can be used to deploy scalable, reliable distributed systems. It provides benefits like velocity, scaling, abstraction of infrastructure and efficiency. The authors also describe how these benefits are easily achieved by using Kubernetes for deployment.

Chapter 2: Creating and Running Containers

This chapter starts by discussing the problems that occur in distributed system such as applications having dependency on shared library or any dependency on asset files which causes failures or complexities when deployed in production. It also discusses how to solve this problem by using container immutable images to deploy the application. Kubernetes supports Docker, which is the most popular container image that can package an application. The authors then discuss how to package an application into Docker image, security related considerations to keep in mind while building images and how to optimize image sizes. The authors recommend storing images in remote repository describing its benefits. The book also illustrates how to start running the application using docker image, how to limit its resource usage and how to clean it up.

Chapter 3: Deploying a Kubernetes Cluster

This chapter focusses on how to install, deploy and manage a Kubernetes cluster. It provides a step-by-step guide on how to install a Kubernetes cluster on 3 major cloud providers - Google Cloud Platform, Amazon Web Services and Microsoft Azure. The book describes how minikube can be used to deploy a single node Kubernetes cluster on a local machine. It also mentions how the Kubernetes client kubectl can be used for exploring the cluster and verifying its health. It ends with describing various other components in a cluster including Kubernetes Proxy, Kubernetes DNS and Kubernetes UI and their respective roles within the cluster.

Chapter 4: Common kubectl Commands

In this chapter, the authors dive into one of the command line utilities of Kubernetes called, 'kubectl' which is basically responsible for creating objects and interacting with kubernetes APIs. Then they briefly talk about namespaces for the organization of objects in a cluster, and to permanently store the naming schema in the config file, 'context' is used. One of the important utility of kubectl apart from the creation of API objects is viewing them. Kubectl also enables users to create update and delete the kubernetes objects. Also, it enables the commands for debugging of the container and can execute the logs. The authors have discussed the annotations and labels of the objects as well, which has been discussed in details in Chapter 6.

Chapter 5: Pods

The authors explain the core concept of Kubernetes called 'Pods', which are considered as the smallest deployable unit in a kubernetes environment. It is a collection of multiple containers and volumes in a same execution environment. They explain the behavior of how application containers in the same pod will be different from containers in different pods to clarify the network understanding of the pods. Authors also exemplified the issues when two different applications are scaled with the same strategy within a pod, and how it could defeat the purpose of containers. To define a pod, users have to define the kubernetes API object details in a pod manifestation, which aligns with the declarative configuration principle. The authors further define technicalities and provide details in creating, running and listing of pods. To summarize the concept, authors also mention the multiple ways of using volumes with Pods.

Chapter 6: Labels and Annotations

After explaining the core concept of Pods, the authors immediately discuss the foundational concepts like Labels and Annotations. Authors feel that Labels and Annotations are often wrongly considered as the same concept and thus make a great effort in explaining the difference and why it is actually required to differentiate between the two. Authors state that 'labels' are basically key-value pair and are useful in attaching identifiable information to kubernetes objects like Pods. Whereas, 'annotations' are storage technique designed to hold unidentifiable information which can be used by tools and libraries. The authors further explain the application of labels and their modification with help of commands and examples. Further, the authors provide insight on annotation with detailed applicability.

Chapter 7: Service Discovery

The authors start by defining Service discovery and the characteristics of a good service discovery system. Since applications are placed dynamically in Kubernetes, service discovery is crucial to fully utilize the power of Kubernetes. The service object allows to expose services within and outside the cluster. Kubernetes associates a cluster IP to each service (which may contain multiple Pods) and also provides a DNS service which provides DNS names for these cluster IPs. The authors also describe how to add readiness check within deployment to track which pods are ready. Some advanced features like using Endpoints to communicate directly with the service are also discussed.

Chapter 8: ReplicaSets

Building on the information provided in the chapter 5: Pods, the authors in this sections explains the concept of ReplicaSets to ensure redundancy for making the system failure tolerant, scaling and sharding of the Pods. In a cluster, the ReplicaSets are important to support the declarative configuration of desired state and current state on the basis of reconciliation loops. The authors also discuss the loosely coupled relationship between Pods and ReplicaSets. The later part of the chapter involves a technical overview of the ReplicaSets with various specifications, templates and labels. The Authors have also provided with multiple commands and declarative configs for creating, inspecting,scaling and deleting a ReplicaSet. One of the interesting take away from the chapter is the auto-scaling based on the CPU usage which is commonly used for Pods scaling.

Chapter 9: DaemonSets

In this chapter, the authors present an in-depth discussion on DaemonSet, which is basically responsible for deploying the system daemons like log collectors and monitoring agent. Authors define the similarity and difference between the concept and use of ReplicaSet and DaemonSet. The relationship between these two components of Kubernetes gives great idea behind the 'decoupled architecture' of Kubernetes. The authors further explain the practical examples of creating, updating and deleting DaemonSet in a K8 environment. DaemonSets are critical in an autoscaled Kubernetes cluster where nodes may constantly be coming and going without user intervention.

Chapter 10: Jobs

Until now, the authors have only discussed the major components for running and maintaining the long-term processes, however, in this section, they have presented a discussion on short-lived or short-term process executing objects called 'jobs'. The basic idea behind jobs is to create pods until successful termination is received, that is, if a pod fails before a successful termination, the job object will create a new pod based on the declarative configuration template until successful termination is achieved. The authors have also explained in detail the two attributes of job patterns like 'completions' and 'parallelism'. The authors concluded the chapter by defining a job as low-level primitive which can be used for simple workloads but can be used for high-level orchestration systems.

Chapter 11: ConfigMaps and Secrets

In this chapter authors discuss about config maps and secrets, illustrating how they can make the container images reusable across environments or applications. Since config map is associated with the Pod before running, one can reuse the image and pod across many applications by using different config map. Authors also provide a code sample for creating and using a config map. For handling the sensitive information, Kubernetes API for secrets is used, which also allows container images to be reused across environments. Next the authors go in detail describing how to create and consume secrets and how to access images stored in private registries using secret API for storing credentials. In the end, the naming conventions for config maps and secrets and some more commands to manage them are described.

Chapter 12: Deployments

The authors had already covered most of the basics and command which will help the kubernetes go up and running. In this chapter, they finally discuss the deployment aspect of kubernetes. For this kubernetes uses deployment object which ensures the management of new release of any application. Kuberenetes in general support two strategies for this, namely, Recreate and Roll-out. In the later part of the chapter, a vivid description of the Roll-out strategy is given with flow diagram to explain the movement of the application during deployment. Along with this, the authors give a practical example of various kubectl commands for creating, managing, updating rolling back, deleting a new deployment.

Chapter 13: Integrating storage solutions and Kubernetes

In this chapter, the authors initialize with a discussion about the complexity of integrating a database or storage application with stateless microservices in general. They explain how integrating data with orchestration solutions could be very tricky. Thus to deal with it, they define various strategies which could be adopted for bringing together storage and container services in kubernetes. Authors explain the technique for importing external services with examples like DNS services and also briefly tell about the limitations.One of the major parts of the chapter is an introduction to the kubernetes-native storage with statefulsets which was exemplified a manually replicated MongoDB with statefulset YAML script.

Chapter 14: Deploying Real-World Applications

Until now, the authors have widely discussed all the components and basics involved in deploying and managing a cluster or a simple containerized application with Kubernetes. In this final installment of the book, the authors want to sum up by explaining the implementation of few real-world applications like Parse, Ghost and Redis server. To describe the implementation of each application, they start with prerequisites, followed by building of that application, and then end with deployment and testing of the application. A very practical approach has been maintained and all the configuration statements have been carefully explained.

SOURCE AND BOOK AVAILABILITY

E-BOOK: https://www.safaribooksonline.com/library/view/ kubernetes-up-and/9781491935668/

PAPERBACK: https://www.amazon.com/Kubernetes-Running-Dive- Future-Infrastructure/dp/1491935677