Timeline
Timeline
2025-10-14
init
This article introduces the basic concepts, core features, and cluster architecture components of Kubernetes, summarizing the functions of Master and Node nodes as well as core concepts such as Pod, Controller, and Service. Additionally, it discusses methods for building clusters using kubeadm and binary packages, along with the kubectl command-line tool, YAML file configuration standards, and Pod implementation mechanisms and resource management strategies.
Kubernetes Overview and Features
K8s Overview
- K8s is a containerized cluster management system open-sourced by Google in 2014
- Deploy containerized applications using K8s
- Using K8s facilitates application scaling
- The goal of K8s is to make deploying containerized applications simpler and more efficient
K8s Features
- Automatic Bin Packing
- Self-Healing
- Horizontal Scaling
- Service Discovery
- Rolling Updates
- Version Rollback
- Secret and Configuration Management (Similar to Hot Deployment)
- Storage Orchestration
- Batch Processing
K8s Cluster Architecture Components
Master (Control Node) and Node (Worker Node)
(1) Master Components
- apiserver
Unified cluster entry point, stored in etcd via RESTful API
- scheduler
Node scheduling, selecting node for application deployment
- controller-manager
Handles routine background tasks in the cluster, one resource corresponds to one controller
- etcd
Storage system for saving cluster-related data
(2) Node Components
- kubelet
Representative dispatched from master to node, manages local containers
- kube-proxy
Provides network proxy, implements load balancing and other operations
K8s Core Concepts
- Pod
- Minimum deployment unit
- A collection of containers
- Shared network
- Lifecycle is ephemeral
- Controller
- Ensure the desired number of pod replicas
- Stateless application deployment
- Stateful application deployment
- Ensure all nodes run the same pod
- One-time tasks and scheduled tasks
- Service
Define access rules for a set of pods
**Master (control plane node)😗*The machine that controls Kubernetes nodes and is where job tasks are created.
**Node:**These machines execute assigned tasks under the control of the Kubernetes master node.
**Pod:**A set of one or more containers deployed as a single unit to a single node. Containers in the same pod share IP addresses, inter-process communication (IPC), hostname, and other resources. Pods abstract the underlying container network and storage, making container migration within the cluster more convenient.
**Replication controller:**Controls the number of instances of a pod running on the cluster.
**Service:**Separates service content from specific pods. The Kubernetes service proxy automatically distributes service requests to the correct pod, regardless of where the pod moves in the cluster, even if it is replaced.
**Kubelet:**This daemon runs on each worker node, responsible for obtaining the container list and ensuring that the declared containers are started and running normally.
**kubectl:**This is the command-line configuration tool for Kubernetes.
Building a K8s cluster
- Environment platform planning
- Single-master cluster

Disadvantage: If the master goes down, it’s game over.
- Multi-master cluster

High-availability cluster
- Server hardware configuration requirements
- Test environment:
master: 2 cores 4G 20G
node: 4 cores 8G 40G
- Production environment:
Higher requirements
- Methods for building k8s cluster deployment
- kubeadm
A k8s deployment tool that provides kubeadm init and kubeadm join for quickly deploying Kubernetes clusters
- Binary packages
Download the release binary packages from GitHub, each component must be deployed separately
Building with kubeadm
https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
1 | # Set server hostname |
- Install 3 virtual machines and install the operating system
- Initialize the three installed operating systems
- Install Docker, kubelet, kubeadm, and kubectl on the three nodes, and change the Docker source
- Execute the kubeadm init command on the master node to initialize
- Execute the kubeadm join command on the node nodes to add them to the current cluster
Binary package setup

- Create multiple virtual machines and install the Linux operating system
- Operating system initialization
- Self-signed certificates for etcd and apiserver
- Deploy etcd cluster
- Deploy master components
kube-apiserver,kube-controller-manager,kube-scheduler,etcd
- Deploy node components
kubelet,kube-proxy,docker,etcd
- Deploy cluster network
Kubernetes cluster command-line tool kubectl
kubectl is the command-line tool for Kubernetes clusters, allowing you to manage the cluster itself and install and deploy containerized applications on the cluster
1 | $ kubectl [command] [type] [name] [flags] |
YAML file description
File writing format
Indentation indicates hierarchical relationships
Do not use the Tab key for indentation
Add a space after the colon
Generally indent two spaces at the beginning
Indent one space after a character
— indicates the start of a new YAML file
Use # to represent comments
YAML file example

| Field | Description |
|---|---|
| apiVersion | API version |
| kind | Resource type |
| metadata | Resource metadata |
| spec | Resource specification |
| replicas | Number of replicas |
| selector | Label selector |
| template | Pod template |
| metadata | Pod metadata |
| spec | Pod specification |
| container | Container Configuration |
How to Quickly Write a YAML File
- Usekubectl createCommand to Generate a YAML File
1 | $ kubectl create deployment web --image=nginx -o yaml --dry-run > web1.yaml |
Kubernetes Core Technology
Pod
Pod Overview
A Pod is the smallest unit that can be created (deployed) and managed in the k8s system
k8s does not directly handle containers, but rather Pods; a Pod can contain multiple containers (a collection of containers)
A Pod shares the network namespace
Each Pod has a special Pause container called the “root container.” The image corresponding to the Pause container is part of the k8s platform. In addition to the Pause container, each Pod also contains one or more closely related user business containers.
Pods are ephemeral
The Purpose of Pods
- Creating containers uses Docker; one Docker corresponds to one container, one container has one process, and one container runs one application
- Pods are designed for multi-process, allowing multiple applications to run; a Pod has multiple containers, and each container runs one application
- Pods exist for intimate interaction:
- Interaction between two applications
- Calling between networks
- Two applications need frequent calls
Pod implementation mechanism
- Shared network
Containers themselves are isolated from each other. Kubernetes uses the Pod’s Pause container (info container) to add other business containers into the Pause container, so that all business containers are in the same namespace, enabling network sharing.
- Shared storage
Pod persistent data: log data, business data
Use Volume for persistent storage

Pod image pull policy

imagePullPolicy
IfNotPresent: default value, pull the image only if it does not exist on the host
Always: pull the image every time a Pod is created
Never: Pod will never actively pull this image; it needs to be pulled manually
Pod resource limits


1c = 1000m (1 core CPU)
Pod Restart Mechanism

restartPolicy
Always: Always restart the container after it terminates; default policy
OnFailure: Restart the container only when it exits abnormally (exit code non-zero)
Never: Never restart the container when it terminates
Pod Health Check
Container Check:
Cannot detect Java heap memory overflow (status remains running)
Application-Level Health Check:

echo $? indicates whether a command executed successfully on Linux
Pod Creation Process

- Master Node
createpod – apiserver – etcd
Scheduler -> API Server -> etcd -> Scheduling algorithm schedules the pod to a specific node
- node
kubelet --apiserver --reads etcd to get pods assigned to the current node --docker creates containers
attributes affecting scheduling
pod resource limits: resources
node selector labels affect Pod scheduling


need to label the node first
1 | $ kubectl label node k8snode1 env_role=prod |
- node affinity affects Pod scheduling

node affinitynodeAffinity is basically the same as the previous nodeSelector, it determines which nodes Pods are scheduled to based on node label constraints
(1) hard affinity (requireDuringSchedulingIgnoreDuringExecution)
constraints must be satisfied
(2) soft affinity (preferredDuringSchedulingIgnoredDuringExecution)
attempt to satisfy, not guaranteed
commonly used operators:
In NotIn Exists Gt Lt DoesNotExists
Anti-affinity: Using NotIn and DoesNotExist
- Taints and Tolerations
- Basic Introduction:
nodeSelector and nodeAffinity: Pods are scheduled to certain nodes, Pod attributes, implemented during scheduling
Taint: Nodes are not used for normal scheduling, it is a node attribute
- Scenarios
Dedicated Nodes
Configuring Nodes with Special Hardware
Eviction Based on Taints
1 | # View the taints of the current node |
There are three taint effects:
NoSchedule: Will not be scheduled
PreferNoSchedule: Try not to be scheduled
NoExecute: Will not be scheduled, and will also evict existing Pods on the Node
Add taint to node
kubectl taint node [node] key=value:Three taint values
1 | $ kubectl get pods |
Delete taint
1 | $ kubectl taint node k8snode1 env_role:NoSchedule- |
Taint toleration:

Controller
What is a Controller
An object that manages and runs containers on the cluster
Relationship between Pod and Controller
Pod achieves application operations such as scaling and rolling updates through Controller
- Relationship between Pod and Controller is established through labels

Pod and Controller establish relationship through labels

Deployment use cases
- Deploy stateless applications
- Manage Pods and ReplicaSets
- Deployment, rolling update, and other features
Use cases: web services, microservices
Deploy applications using Deployment (YAML)
1 | # Export YAML file |
Application upgrade, rollback, and auto-scaling
1 | # Application upgrade |
Difference between stateless and stateful
- Stateless
- Consider all Pods to be identical (replicas are identical)
- No ordering requirements
- No need to consider which node to run on
- Freely scale and expand
- Stateful
- All the above factors need to be considered
- Make each pod independent, maintain pod startup order and uniqueness (unique network identifier, persistent storage, ordered, such as MySQL master-slave)
Deploy stateful applications
- Headless service:
- ClusterIP: node
StatefulSetDeploy stateful applications


After execution, check the pods; there are 3 Pods, each with a unique name
Check svc, ClusterIP is None
Difference between deployment and statefulset: statefulset has identity (unique identifier)
- Generate domain name based on hostname + certain rules
- Unique domain name
Format: hostname.service name.namespace.svc.cluster.local
example: nginx-statefulset-0.nginx.default.svc
Deploy DaemonSet
- Run one pod on each node, newly added nodes also run a pod
- Example: Install data collection tool on each node

1 | $ kubectl delete statefulset --all |
Job (one-time task) and CronJob (scheduled task)

1 | $ kubectl create -f job.yaml |
Scheduled task:

1 | $ kubectl apply -f cronjob.yaml |
Service
What is a Service
Define access rules for a group of Pods
Purpose of Service
Prevent Pod disconnection (service discovery)

Service discovery Define a set of Pod access policies (load balancing)

Relationship between Pod and Service
Establish relationship based on label tags

Common Service types
- ClusterIP: used within the cluster
- NodePort: used for external access to applications
- LoadBalancer: used for external access to applications, public cloud
1 | $ kubectl get svc |
Applications deployed on nodes in the internal network are generally not accessible from the external network:
Use a machine with external network access, install nginx, reverse proxy
Manually add accessible nodes to nginx
LoadBalancer: public cloud, load balancer, controller
Configuration management
Secret
Function: Encrypt data stored in etcd, allowing Pod containers to access it by mounting a Volume
Scenario: Credentials
Base64 encoding
1 | $ echo -n "admin" | base64 |
- Create secret encrypted data

1 | $ kubectl create -f secret.yaml |
- Mount into the pod container as environment variables
valueFrom

1 | $ kubectl apply -f secret-val.yaml |
- Mount into a volume


1 | $ kubectl delete -f secret-val.yaml |
ConfigMap
Purpose: Store unencrypted data in etcd, allowing Pods to mount it into containers as environment variables or volumes
Scenario: Configuration files
- Create a configuration file
1 | $ kubectl delete secret --all |
- Create a ConfigMap
1 | $ kubectl create configmap redis-config --from-file=redis.properties |
- Mount into the Pod container as a volume

1 | $ kubectl apply -f cm.yaml |
- Mount as variables
(1) Create YAML, declare variable information, create ConfigMap

(2) Mount as variables
1 | $ kubectl apply -f myconfig.yaml |

1 | $ kubectl apply -f config-var.yaml |
K8s cluster installation mechanism
Overview
- Accessing a K8s cluster requires three steps to complete specific operations
(1) Authentication
(2) Authorization
(3) Admission control
- When accessing, the process must go through the apiserver, which acts as a unified coordinator, like a gatekeeper. During access, certificates, tokens, or username+password are required. If accessing a pod, a serviceAccount is needed.
First step: Authentication
- Transport security: Port 8080 is not exposed externally, only accessible internally; port 6443 is used externally.
- Authentication: Common methods for client identity authentication:
- HTTPS certificate authentication, based on CA certificate
- HTTP token authentication, identifying users via token
- HTTP basic authentication, username + password authentication
Step 2: Authorization
- Perform authorization operations based on RBAC
- Role-based access control
Step 3: Admission Control
- It is the list of admission controllers; if the list has content, it passes
RBAC: Role-Based Access Control
Role Based Access Control
- Role
Role: Access permissions for a specific namespace
ClusterRole: Access permissions for all namespaces
1 | # View namespaces |
- Role Binding
- roleBinding: Bind a role to a subject
- ClusterRoleBinding: Bind a cluster role to a subject
- Subject
- user: User
- group: Group
- serviceAccount: Service Account
RBAC Implements Authorization
1 | # 1. Create a Namespace |

1 | # 3. Create a Role |

1 | # 4. Create a Role Binding |
- Use Certificate

1 | $ vim rbac-user.sh |
Ingress
Overview
- Expose the port number externally, access via IP + port number, implemented using NodePort in Service
- NodePort Limitations
- A port is opened on each node; access is achieved through any node via the node’s IP and the exposed port
- This means each port can only be used once, with one port corresponding to one application
- In practice, domain names are used for access, redirecting to different port services based on different domain names
Relationship between Ingress and Pod
- Pods and Ingress are associated through Service
- Ingress acts as a unified entry point, with Service linking a group of Pods

Use Ingress
Expose Applications Externally Using Ingress
- Create an nginx application and expose the port externally
1 | $ kubectl create deployment web --image=nginx |
- Deploy Ingress Controller

1 | $ kubectl apply -f ingress-con.yaml |

1 | $ vim ingress-h.yaml |
Helm
Overview
Basic process of deploying applications previously:
Write yaml files: deployment, Service, Ingress
It is suitable to deploy a single application or a few services using the previous method
If deploying a microservices project with dozens of services, each service has its own set of yaml files, requiring maintenance of a large number of yaml files, making version management very inconvenient
What problems can using Helm solve?
- Using Helm, these yaml files can be managed as a whole
- Achieve efficient reuse of yaml
- Use Helm for application-level version management
Helm introduction
Helm is a package management tool for Kubernetes, similar to package managers like yum/apt on Linux, making it easy to deploy pre-packaged yaml files to Kubernetes
Three important concepts
helm
- Is a command-line client tool
Chart
- Is packaging yaml, a collection of yaml
Release
- Deploy entities based on charts, application-level version management

https://helm.sh/docs/intro/quickstart/
Install
https://helm.sh/docs/intro/install/
Add repository
1 | $ helm repo add brigade https://brigadecore.github.io/charts |
Use Helm to quickly deploy applications
- Search for applications using commands
1 | $ helm search repo 名称 |
- Select and install based on search results
1 | $ helm install 安装之后的名称 搜索之后的名称 |
- Check the status after installation
1 | $ helm list |
example
1 | $ helm search repo weave |
How to create your own Chart
- Create a chart using commands
1 | $ helm create mychart |
- Chart.yaml: Configuration information of the current chart
- templates: Write yaml files and place them in this directory
- values.yaml: Global variables that can be used by yaml files
- Create two yaml files under the templates folder
- deployment.yaml
- service.yaml
1 | $ kubectl create deployment web1 --images=nginx --dry-run -o yaml > deployment.yaml |
- Install mychart
1 | $ helm install web1 mychart/ |
- Application Upgrade
1 | $ helm upgrade chart名称 chart文件夹 |
Achieve efficient reuse of yaml
Dynamically render templates by passing parameters, generating yaml content with dynamically passed parameters
- Define variables and values in values.yaml
- Retrieve defined variables and values in specific yaml files
- Yaml files generally differ in these few places
- image
- tag
- label
- port
- replicas
- Define variables and values in values.yaml
1 | replicas: 1 |
- Use variables defined in values.yaml in the yaml files under templates
- Use global variables in expression form
1 | {{.Values.变量名称}} |
For example
1 | {{ .Release.Name}}-deploy |
1 | $ helm install --dry-run web2 mychart/ |
Persistent storage
The data volume emptydir is local storage. When a pod restarts, the data no longer exists, so persistent storage is needed.
NFS network storage
When a pod restarts, the data still exists.
Step 1: Find a server as the NFS server.
(1) Install NFS
1 | $ yum install -y nfs-utils |
(2) Set the mount path
1 | $ vim /etc/exports |
(3) The external mount path needs to be created first.
1 | $ mkdir /data/nfs |
Step 2: Install NFS on the node nodes of the Kubernetes cluster.
1 | $ yum install -y nfs-utils |
Step 3: Start the NFS service on the NFS server.
1 | $ systemctl start nfs |
Step 4: Deploy applications in the Kubernetes cluster using NFS persistent network storage.
1 | $ mkdir pv |

1 | $ kubectl describe pod nginx-dep1-79x79jg79-9sn8gx |
PV and PVC
- PV: Persistent storage, which abstracts storage resources and provides externally callable interfaces (producer).
- PVC: Users call it without needing to care about internal implementation details (consumer).
- Implementation process:

1 | $ vim pvc.yaml |


1 | $ kubectl apply -f pvc.yaml |
1 | $ vim pv.yaml |

1 | $ kubectl apply -f pv.yaml |
K8s cluster resource monitoring
Monitoring metrics
- Cluster monitoring
- Node resource utilization
- Number of nodes
- Running pods
- Pod monitoring
- Container metrics
- Application
Monitoring platform
prometheus+Grafana
(1) prometheus
- Open source
- Monitoring, alerting, database
- Periodically fetch the status of monitored components via HTTP protocol
- No complex inheritance process required, just use the HTTP interface to connect
(2) Grafana
- Open-source data analysis and visualization tool
- Supports multiple data sources
Deployment:
https://developer.aliyun.com/article/836300
Building a high-availability cluster

High-availability cluster technology

Deployment

https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/high-availability/
Deploying a Java project
Container delivery process


