Kubernetes Overview
Feature
![[images/24a08702-ae93-4466-83d7-1520ebc1f938.png]]
Kubernetes is an open-source system for automating deployment scaling, and management of containerized applications.
Kubernetes 提供了一个可弹性运行分布式系统的框架
- Service Discovery / Load Balancing
- Storage Orchestration
- Automate Rollouts / Rollbacks
- Self-healing
- Secret and Configuration Management
- Horizontal Scaling
Infrastructure
$$\text{K8S Cluster} = N\ \text{Master Nodes} + N\ \text{Worker Nodes} (N\geq1)$$
![[images/截屏2026-03-18 15.52.44.png]]
Pods and Containers
![[images/截屏2026-03-18 15.54.21.png]]
- 一个 Pod 中可有多个 Container
- 一个 Node 中也可有多个 Pod
Building Blocks
![[images/截屏2026-03-27 14.12.52.png]]
- Service: Pod 和外界、和 Pod 之间进行交流
- Deployment: 部署
Communicating with kubectl
![[images/截屏2026-03-18 16.09.01.png]]
- Store (etcd): 存储主节点所需的信息(K-V 形式)
- Controller Manager: 处理请求,并使用 Scheduler 进行任务调度
- Scheduler: 任务调度,控制 Nodes 或 Pods 的运行
- API Server: A RESTful server. 接收由
kubectl提供的命令并转发给 Controller Manager 执行
![[images/image.png]]
Node
![[images/截屏2026-03-18 16.16.15.png]]
- Kubelet: Agent running on each node. 该代理向集群注册该节点并与管理器来回通信
- Container Runtime: Run containers within the pods
- Kube-Proxy: 为每个 Pod 提供唯一 IP 地址,并与服务进行绑定
Use Cases
- Emulate production locally
- Move from Docker Compose to Kubernetes
- Create an end-to-end test environment
- Ensure application scales properly
- Ensure secrets/config are working properly
- Performance testing scenarios
- Workload scenarios (CI/CD …)
- Learn how to leverage deployment options
- Help DevOps create resources and solve problems
Ways to Deploy
- minikube
- Docker Desktop
- kubeadm
- kind
kubectl
| Command | Function |
|---|---|
kubectl version |
Check version |
kubectl cluster-info |
View cluster information |
kubectl get all |
Retrieve information about Kubernetes Pods, Deployments, Services, and more |
kubectl get pods |
Get only pods |
kubectl run [container-name] --image=[image-name] |
Simple way to create a Deployment for a Pod |
kubectl port-forward [pod] [ports] |
Forward a port to allow external |
kubectl expose |
Expose a port for a Deployment/Pod |
kubectl create [resource] |
Create a resource |
kubectl apply [resource] |
Create or modify a resource |
可以为 kubectl 设置别名
Windows:
Set-Alias -Name k -Value kubectl
Mac/Linux
alias k="kubectl"
Web UI Dashboard (Mac)
旧版原生 Dashboard 已经弃用,现使用 Headlamp
安装后即可直接查看本地运行的 cluster
Troubleshoot
Log
# View the logs for a Pod's container
kubectl logs [pod_name]
# View the logs for a specific container within a Pod
kubectl logs [pod_name] -c [container_name]
# View the logs for a previously running Pod
kubectl logs -p [pod_name]
# Stream a Pod's logs
kubectl logs -f [pod_name]
# Watch a resource
kubectl get [pod_name] --watch
Describe
# Describe a Pod
kubectl describe pod [pod_name]
# Change a Pod's output format
kubectl get pod [pod_name] -o yaml
# Change a Deployment's output format
kubectl get deployment [deployment_name] -o yaml
Shell Into
kubectl exec -it [pod-name] -- sh
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 木素音的小站!