CKA-Day02:工作负载、存储
0、学习资料
工作负载和调度
-
部署以及如何执行滚动更新和回滚
- Deployments 文档:了解 Deployments 的基本概念和如何使用它们进行应用部署。
- 更新和回滚 Deployments:学习如何对 Deployments 进行更新和回滚操作。
-
使用 ConfigMaps 和 Secrets 配置应用程序
- ConfigMap 文档:了解如何使用 ConfigMap 来配置 Pod。
- Secrets 文档:了解如何使用 Secrets 来存储敏感信息。
-
了解如何扩展应用程序
- 自动扩展:学习如何使用 Horizontal Pod Autoscaler 来自动扩展应用程序。
-
了解用于创建健壮的、自修复的应用程序部署的原理
- 自我修复:了解 Kubernetes 如何自动修复失败的 Pod。
-
了解资源限制如何影响 Pod 调度
- 资源配额和限制:了解资源配额和限制如何影响 Pod 的调度。
-
了解清单管理和通用模板工具
- 使用 kubectl 管理 Kubernetes 对象:学习如何使用 kubectl 命令行工具来管理 Kubernetes 对象。
- 编写 Kubernetes 对象配置文件:了解如何编写和使用 Kubernetes 对象的配置文件。
存储
-
了解存储类(Storage Classes)
- 存储类:介绍了存储类的基本概念和如何使用它们来配置持久卷的存储特性。
-
了解持久卷(Persistent Volumes, PV)
- 持久卷:解释了持久卷是什么以及它们在 Kubernetes 中的作用。
-
了解卷模式(Volume Modes)
- 卷模式:介绍了文件系统、块和共享卷模式的区别和使用场景。
-
了解访问模式(Access Modes)
- 访问模式:解释了 ReadWriteOnce、ReadOnlyMany 和 ReadWriteMany 这三种访问模式。
-
了解卷回收策略
- 回收策略:介绍了 Retain、Recycle 和 Delete 三种回收策略。
-
理解持久容量声明原理(Persistent Volume Claims, PVC)
- 持久卷声明:解释了持久卷声明的工作原理和如何请求存储资源。
-
了解如何配置具有持久性存储的应用程序
- 使用持久卷和持久卷声明:提供了如何为 Pod 配置持久性存储的步骤和示例。
1、部署、滚动更新、回滚
Deployments
使用set image命令更新镜像
kb get deploy -owide
kb get pod -w
rollout history
rollout status
rollout undo
暂停、恢复Deployment的上线过程
rollout pause
rollout resume
StatefulSet
kb create sts -h 命令行不能创建sts资源?
spec:
podManagementPolicy: OrderedReady
replicas: 3
revisionHistoryLimit: 10
selector:
matchLabels:
app: nginx
serviceName: nginx
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
ports:
- containerPort: 80
name: web
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /usr/share/nginx/html
name: www
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 10
updateStrategy:
rollingUpdate:
partition: 0
type: RollingUpdate
volumeClaimTemplates:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
name: www
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: csi-localpv
volumeMode: Filesystem
status:
phase: Pending
访问模式
制备
回收
PersistentVolumeClaim保留
Service
spec:
clusterIP: 246.96.132.18
externalTrafficPolicy: Cluster
ports:
- name: 380-80
nodePort: 30021
port: 380
protocol: TCP
targetPort: 80
selector:
app: nginx
sessionAffinity: None
type: NodePort
2、存储
ConfigMaps
Read-only file system
Secret
kubectl create secret 【Secret类型】 【Secret名称】
kb create secret
Create a secret using specified subcommand.
Available Commands:
docker-registry Create a secret for use with a Docker registry
generic Create a secret from a local file, directory or literal value
tls Create a TLS secret
Usage:
kubectl create secret [flags] [options]
Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all commands).
在使用 echo “secret” |base64 命令时,实际得到的结果是 c2VjcmV0Cg== 而不是 c2VjcmV0,这是因为 echo 命令默认会添加一个换行符(\n)。
所以你实际上是在对 “secret\n” (包含一个换行符)进行 base64 编码,而不只是 “secret”。
如果你想避免 echo 命令添加的换行符,你可以使用 -n 选项,如下:
hostPath
rollout restart sts ?