Kubernetes, as an indispensable application for cloud deployment, facilitates the containerized deployment of applications. It provides an effective mechanism for deploying, planning, updating, and maintaining applications.
This article primarily introduces the basic concepts of Kubernetes.
Why Do We Need Kubernetes?
Three Stages of Application Deployment
Traditional Deployment:
- Manually deploy applications directly onto target machines.
- Due to lack of resource isolation, issues like resource contention and dependency conflicts are common.
Virtualization Deployment:
- Uses virtualization technologies like VMware to virtualize a physical machine into multiple machines.
- Improves server resource utilization.
- Provides a completely isolated environment (OS-level).
Containerized Deployment:
- Can be understood as lightweight virtualization (process-level), addressing the heaviness of virtualization technology.
- Directly shares host hardware resources and achieves resource isolation through system-provided technologies like namespaces, resulting in lower overhead and higher efficiency.
Features of Kubernetes
- Self-healing
- Elastic scaling
- Automated deployment and rollback
- Service discovery and load balancing
- Secret and configuration management
- Storage orchestration
- Batch processing
Introduction to Kubernetes
Various Components of Kubernetes
Master:
- Kube API Server: Handles API requests from users and other components, validates requests, and persists configuration data.
- Kube Scheduler: Assigns newly created Pods to appropriate nodes, considering node resources and constraints for scheduling decisions.
- Kube Controller Manager: Contains multiple controllers that monitor changes in cluster status and adjust according to desired states.
- Cloud Controller Manager: Responsible for running cloud platform-specific controllers.
- Etcd: A distributed key-value storage system used to save configuration data, state, and metadata of the cluster.
Node:
- Kubelet: An agent running on each node that communicates with the Master node, ensuring that the containers running on the node are in the expected state.
- Kube Proxy: Maintains network rules on the node, providing load balancing and proxy functionality for services, ensuring network communication between services.
- Container Runtime: Responsible for image management and the actual running of Pods and containers.
A Command Call Chain:
Various Resources of Kubernetes
Kubernetes Namespace Overview:
Methods of Creating Resources: Yaml / Command
Pod:
- A Pod (container group) includes one application container (or multiple containers in some cases), storage resources, a unique network IP address, and options that determine how containers should run.
- "One-container-per-pod" is the most common usage in Kubernetes; Pods can be thought of as wrappers for containers, with Kubernetes managing containers through Pods rather than directly.
- Container engines in Kubernetes Pods include Docker, Containerd, etc.
Volume:
- EmptyDir: Temporary storage, deleted when the Pod is destroyed.
- HostPath: Mounts an actual directory from the host into the Pod, not deleted when the Pod is destroyed.
- NFS: A separate network storage system.
- PV, PVC: PV defines the corresponding resource, while PVC defines the required resources; both are bound together and can be used in the Pod. They are not deleted when the Pod is destroyed (based on the destruction policy).
- ConfigMap (based on etcd)
- Secret (based on etcd)
- Container Storage Interface
Network:
- Service / Headless Service:
- ClusterIP: Used for internal communication.
- NodePort: Directly exposed for external access.
- Ingress (Nginx): Exposes internal services for external access, acting as an Nginx (reverse proxy, load balancing, Layer 7 load balancing).
- Service / Headless Service:
Pod Controllers
Stateless and Stateful (ref: Stateless and Stateful Overview):
Deployment (Stateless):
- Kubernetes Replication Controller.
ReplicaSet:
- label / select: Pod controllers depend on Pods, and labels can be set for Pods. The controller can then set a corresponding selector, achieving object association.
Create Replica Set / Pod
Upgrade / Rollback
Expand / Shrink
Pause / Resume
StatefulSet (Stateful):
- Headless Service (Stable Network Sign):
<pod name>.<service name>.<namespace name>.svc.cluster.local
- VolumeClaimTemplate (Stable Volume)
- Ordered Deployment / Expansion
- Ordered Shrink / Deletion
- Headless Service (Stable Network Sign):
DaemonSet
Job