对齐文件规范
This commit is contained in:
9
ansible/files/03-05/local-path-config-lab.json
Normal file
9
ansible/files/03-05/local-path-config-lab.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"nodePathMap": [
|
||||
{
|
||||
"node": "DEFAULT_PATH_FOR_NON_LISTED_NODES",
|
||||
"paths": ["/storage/storage"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
42
ansible/files/03-05/local-path-pvc-demo.yaml
Normal file
42
ansible/files/03-05/local-path-pvc-demo.yaml
Normal file
@@ -0,0 +1,42 @@
|
||||
# docs/03-05-k3s-local-path-pvc.md
|
||||
apiVersion: v1 # PVC:Kubernetes 核心 API
|
||||
kind: PersistentVolumeClaim # 持久卷声明(你“申请要用的存储”)
|
||||
metadata: # PVC 的元信息(名称/命名空间/其它元数据)
|
||||
name: local-pvc-demo # PVC 名称(Deployment 里会引用)
|
||||
namespace: default # PVC 所在命名空间
|
||||
spec: # PVC 的期望状态(访问模式/存储类/容量请求)
|
||||
accessModes: # 访问模式:RWO 表示同一时刻只能被一个节点上的一个 Pod 以读写方式挂载
|
||||
- ReadWriteOnce # 读写模式:单节点可读写
|
||||
storageClassName: local-path # 指定存储类:使用 K3s 的 local-path-provisioner(动态创建本地 PV)
|
||||
resources: # 资源请求(本例只关心 storage 容量)
|
||||
requests: # 容量配额请求(与 requests.storage 对应)
|
||||
storage: 1Gi # 申请容量大小(K8s quantity:常见后缀 Ki/Mi/Gi/Ti/…,示例:512Mi、1024Mi、1Gi、1G;也可写字节值)
|
||||
---
|
||||
apiVersion: apps/v1 # Deployment:apps API
|
||||
kind: Deployment # 部署器:管理 Pod 副本、滚动更新等
|
||||
metadata: # Deployment 的元信息
|
||||
name: nginx-local-pvc-demo # Deployment 名称
|
||||
namespace: default # 部署到的命名空间(Deployment 里引用 PVC 时也必须同 namespace)
|
||||
spec: # Deployment 的期望状态(副本数、选择器、Pod 模板等)
|
||||
replicas: 1 # Pod 副本数(用于验证持久化,保持单副本更直观)
|
||||
selector: # Deployment 选择器:用于匹配/管理模板 Pod
|
||||
matchLabels: # 标签匹配集合(必须与 template.metadata.labels 对上)
|
||||
app: nginx-local-pvc-demo # Deployment 用该 label 选择/管理自己的 Pod
|
||||
template: # Pod 模板(Deployment 用它创建/更新 Pod)
|
||||
metadata: # Pod 元信息
|
||||
labels: # Pod 标签:必须与 selector.matchLabels 对齐
|
||||
app: nginx-local-pvc-demo # Pod 模板 label:必须与 selector.matchLabels 对上
|
||||
spec: # Pod 规范
|
||||
nodeSelector: # 指定调度节点(本地盘绑定节点;请按实际节点主机名修改)
|
||||
kubernetes.io/hostname: ylc61 # 仅调度到主机名为 ylc61 的节点
|
||||
containers: # 容器列表
|
||||
- name: nginx # 容器名
|
||||
image: nginx:alpine # nginx 镜像
|
||||
volumeMounts: # 容器内挂载点(把卷挂到 mountPath)
|
||||
- name: data # 与下方 volumes[].name 对应:挂载哪个卷
|
||||
mountPath: /usr/share/nginx/html # 挂载点:写入此目录会落到 PVC/PV 上
|
||||
volumes: # Pod 内定义的卷列表
|
||||
- name: data # Pod 内的卷名(给 volumeMounts 用)
|
||||
persistentVolumeClaim: # 使用 PVC 作为卷来源
|
||||
claimName: local-pvc-demo # 绑定到哪个 PVC(必须与上面 PVC metadata.name 且同 namespace)
|
||||
|
||||
43
ansible/files/03-05/nginx-hostpath-demo.yaml
Normal file
43
ansible/files/03-05/nginx-hostpath-demo.yaml
Normal file
@@ -0,0 +1,43 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx-hostpath-demo
|
||||
namespace: default
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx-hostpath-demo
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx-hostpath-demo
|
||||
spec:
|
||||
nodeSelector:
|
||||
kubernetes.io/hostname: ylc61
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.27-alpine
|
||||
ports:
|
||||
- containerPort: 80
|
||||
volumeMounts:
|
||||
- name: app-data
|
||||
mountPath: /usr/share/nginx/html
|
||||
volumes:
|
||||
- name: app-data
|
||||
hostPath:
|
||||
path: /data/nginx-hostpath-demo
|
||||
type: DirectoryOrCreate
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx-hostpath-demo
|
||||
namespace: default
|
||||
spec:
|
||||
selector:
|
||||
app: nginx-hostpath-demo
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
type: ClusterIP
|
||||
Reference in New Issue
Block a user