496-Kubernetes: Up & Running-Kelsey Hightower- Container-2016
Barack
2023/12/14
"Kubernetes: Up & Running", first published in 2016. This book explores how Kubernetes and container technology can help you achieve new levels of speed, agility, reliability, and efficiency. It explains how the system fits into the life cycle of distributed applications. You'll learn how to use tools and APIs to automate scalable distributed systems, whether they're online services, machine learning applications, or clusters of Raspberry Pi computers.
Kelsey Hightower was born in Long Beach, California in 1981. is an American software engineer, developer advocate, and speaker known for his work on Kubernetes, open-source software, and cloud computing. He joined CoreOS as an early team member in early 2014 and began making significant contributions to the Kubernetes project. Hightower has been working as an engineer and developer advocate in Google's cloud computing division since November 2015. As of October 2022, Hightower is a Distinguished Engineer at Google Cloud with an Individual Contributor Level 9 (L9). On June 26, 2023, Hightower announced his retirement from Google on Twitter, saying that "if everything goes as planned, this will be his last job."
Containerization, in software engineering, is operating system-level virtualization or application-level virtualization across multiple network resources so that software applications can be run in isolated user spaces called containers in any cloud or non-cloud environment regardless of type or supplier. A container is basically a fully functional and portable cloud or non-cloud computing environment that surrounds an application and makes it independent of other environments running in parallel. Each container individually emulates a different software application and runs independent processes by bundling related configuration files, libraries, and dependencies. However, in general, multiple containers share a common operating system kernel (OS). In recent years, containerization technology has been widely adopted by cloud computing platforms such as Amazon Web Services, Microsoft Azure, Google Cloud Platform, and IBM Cloud.
Kubernetes was first released in September 2014. It is an open-source container orchestration system for automated software deployment, scaling, and management. The project was originally designed by Google and is now maintained by the Cloud Native Computing Foundation. The name Kubernetes comes from ancient Greek, meaning "helmsman" or "pilot." Kubernetes is often abbreviated as K8s, counting the eight letters between K and s (the number). Kubernetes works with various container runtimes, such as containers and CRI-O. It is suitable for running and managing large-scale cloud-native workloads, so it has been widely adopted in data centers. The platform is available in multiple distributions - from independent software vendors (ISVs) as well as cloud-hosted offerings from all major public cloud providers.
Table of Contents
Chapter 1. Introduction
Chapter 2. Creating and Running Containers
Chapter 3. Deploying a Kubernetes Cluster
Chapter 4. Common kubectl Commands
Chapter 5. Pods
Chapter 6. Labels and Annotations
Chapter 7. Service Discovery
Chapter 8. ReplicaSets
Chapter 9. DaemonSets
Kubernetes is a container orchestration tool whose core is a series of APIs that enable users to manage containers more effectively. Containers are lightweight virtualization technologies at the operating system level or application level that have several significant advantages. First, speed. Speed here not only means enabling developers to quickly iterate their applications and services but also means that services can continue to run without interruption during the iteration process. We are now accustomed to real-time updates of software. For example, when using taxi-hailing software, this software must run online, and users have almost no awareness of the update process. Another feature of Kubernetes is its ease of operation. It enables better scaling of services. Because cloud products need to support an uncertain number of users, they must have strong scalability. For example, reduce the number of servers when the number of users is small, and dynamically increase the number of servers when the number of users increases. Third, Kubernetes improves the understandability and reusability of infrastructure by abstracting your infrastructure. Finally, efficiency. Compared with traditional virtualization technologies (such as hypervisor-based virtualization), container-based virtualization (containerization) is implemented at the operating system level or application level, which means that it requires less resource overhead. Therefore, under the same resource conditions, it can support more virtual machine instances, thereby improving efficiency.
Before understanding Kubernetes, let us first sort out container technology and its relationship with Kubernetes. First, imagine we have a physical machine. An operating system is running on this physical machine, and the operating system schedules resources on the physical machine through APIs such as assembly instructions. This operating system is what we usually call Kernel. On top of the operating system, we can run multiple containers. Each container is like an independent virtual machine, and it communicates with the operating system through APIs. What Kubernetes provides is a set of APIs for managing these containers. It is an orchestration tool used to manage containers on top of the operating system, or it can also be called a scheduling tool. Several advantages of Kubernetes include: First, the declarative nature of configuration. Kubernetes allows users to declaratively configure the required resources. For example, if you declare that you need three copies of a container, Kubernetes will ensure that there are always three copies running. If a container changes, its replicas are updated accordingly. Second, high efficiency. Kubernetes improves efficiency by decoupling services. Different services, such as the three ABC services, can share the same physical machine or run on different containers in the same cluster. This means that developers do not need to care about which machine the service is running on. Kubernetes will automatically schedule computing resources based on the demand for these services. Third, scalability. Because Kubernetes decouples the relationship between services and physical machines, when the service requires more computing resources, the service can be easily scaled by increasing the number of containers. This flexibility is similar to placing containers from different companies in a large factory. Compared with purchasing land and building buildings, this method is more flexible and efficient in resource allocation.
Kubernetes is designed for cloud-native environments. The so-called "cloud-native applications" refer to those applications that specifically run in the public cloud, private cloud, or hybrid cloud environments. A core characteristic of these applications is their high degree of scalability, that is, their ability to flexibly adapt to changes in service requirements. To achieve this goal, developers often split the application into numerous microservices. The coupling between these microservices is low, but they work together to complete complex business requirements. These microservices usually run in containers, such as common open-source container technologies such as Docker. In this, Kubernetes plays a crucial role. It is essentially an API library for managing containers, used for container deployment, management, scheduling, etc. From the perspective of the entire development life cycle, developers can also use methods and tools such as DevOps or CICD (continuous integration and continuous deployment) to achieve continuous updates and maintenance of cloud products and services without interrupting services. A key advantage of container technology is isolation - its ability to isolate services running within the container from the external environment. It's like a container. No matter where it is moved, the environment inside the container is not affected by the outside world.
Kubernetes uses "declarative configuration", which focuses on the state that the system should achieve rather than the specific steps of the execution process. This is in contrast to "imperative configuration", which focuses on specific operation steps rather than the state of the system after the operation is completed. For example, if my configuration goal is to maintain three backups, then in a declarative configuration, all I care about is ensuring that three backups exist at all times. This approach defines the state the system should reach. In the imperative configuration, if specific copy steps are configured, such as copying A first, then copying B from A, and then copying C from B, this method defines the specific operations to be performed. In this case, the number of backups after the operation is completed is undefined. In terms of the specific method to achieve this goal, there is a key component in Kubernetes called "Operator", which is essentially an extension of the Kubernetes API. The Operator continuously monitors the current state. If it finds that the current state is inconsistent with the declared target state, it will automatically take various measures to ensure that the current state is consistent with the declared state.
In Kubernetes, there are several core concepts that need to be understood: First, Pod (a group). Pod is the basic running unit of Kubernetes and can contain one or more tightly coupled containers. Containers in the same Pod share computing resources, which makes the Pod the smallest unit in the Kubernetes architecture. Secondly, Cluster. Cluster is a high-level concept that consists of multiple physical machines, usually including a master node (for management and scheduling) and multiple worker nodes (for performing specific tasks). In parallel computing, when the computing power of one physical machine is insufficient, a cluster composed of multiple physical machines is used. In a Cluster, multiple Pods can be running, and each Pod can be responsible for different microservices. Third, Namespace. Namespace is a method of dividing a larger cluster into smaller sub-clusters, which determines the scope of the command. You can think of it as a defined circle. Inside the circle is a sub-cluster. Your command only takes effect on the resources in this sub-cluster and does not affect other parts outside the circle. Fourth, Ingress: The Ingress object is an API object in Kubernetes and is mainly responsible for managing ingress traffic. It defines the way for external access to the internal services of the Kubernetes cluster, including how to route external requests to various services within the cluster.