文章目录
- 路径 说明 /mnt/data 本地主机上的目录 /app/wiz minikube容器里的路径 /wiz/storage/ pod的路径
-
- 这里以WIZ为测试,具体可以参考为知笔记docker私有化部署 docker pull wiznote/wizserver
- 启动挂载 minikube start --mount --mount-string="/mnt/data:/app/wiz" 验证 minikube ssh cd /app/wiz # 创建一个文件再去主机上 /mnt/data 查看是否存在即可
- 配置文件wiz-pv.yaml apiVersion: v1 kind: PersistentVolume metadata: name: wiz-pv-volume labels: type: local spec: storageClassName: manual capacity: storage: 10Gi accessModes: - ReadWriteOnce hostPath: path: "/app/wiz" 部署 kubectl create -f wiz-pv.yaml 查看 kubectl get pv 删除 kubectl delete pv wiz-pv-volume
- 配置文件wiz-pvc.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: wiz-pv-claim spec: storageClassName: manual accessModes: - ReadWriteOnce resources: requests: storage: 3Gi 部署 kubectl create -f wiz-pvc.yaml 查看 kubectl get pvc 删除 kubectl delete pvc wiz-pv-claim
- 配置文件wiz.yaml kind: Deployment apiVersion: apps/v1 metadata: name: wiz #Deployment名称 labels: app: wiz spec: replicas: 2 #目标副本数量 selector: matchLabels: app: wiz template: metadata: labels: app: wiz spec: volumes: - name: wiz-pv-storage persistentVolumeClaim: claimName: wiz-pv-claim #PVC 存储名称 containers: - name: wizserver image: wiznote/wizserver:latest resources: {} imagePullPolicy: Always volumeMounts: #容器内挂载点 - mountPath: "/wiz/storage/" name: wiz-pv-storage #必须有名称 ports: #定义端口 - name: container-port #定义pod名称 containerPort: 80 #定义pod端口 protocol: TCP #定义TCP restartPolicy: Always terminationGracePeriodSeconds: 30 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 25% maxSurge: 25% revisionHistoryLimit: 10 progressDeadlineSeconds: 600 部署 kubectl create -f wiz.yaml
- 配置文件wiz-service.yaml apiVersion: v1 kind: Service metadata: name: wiz-service spec: type: NodePort selector: app: wiz ports: - protocol: TCP port: 8888 targetPort: 80 部署 kubectl create -f wiz-service.yaml
最近了解这个k8s在PVC存储这儿卡了两天,今天终于算是大概搞明白是个怎么回事了。
以下是该过程的总结:
- 创建由物理存储支持的 PersistentVolume。你不会将卷与任何 Pod 关联。
-
创建一个 PersistentVolumeClaim, 它将自动绑定到合适的 PersistentVolume。
-
创建一个使用 PersistentVolumeClaim 作为存储的 deployment
-
https://kubernetes.io/zh/docs/tasks/configure-pod-container/configure-persistent-volume-storage/

| 路径 | 说明 |
|---|---|
/mnt/data |
本地主机上的目录 |
/app/wiz |
minikube容器里的路径 |
/wiz/storage/ |
pod的路径 |
- 这里以WIZ为测试,具体可以参考为知笔记docker私有化部署
docker pull wiznote/wizserver
docker pull wiznote/wizserver
- 启动挂载
minikube start --mount --mount-string="/mnt/data:/app/wiz"
- 验证
minikube ssh
cd /app/wiz
# 创建一个文件再去主机上 /mnt/data 查看是否存在即可
minikube start --mount --mount-string="/mnt/data:/app/wiz"
minikube ssh
cd /app/wiz
# 创建一个文件再去主机上 /mnt/data 查看是否存在即可
- 配置文件
wiz-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: wiz-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/app/wiz"
- 部署
kubectl create -f wiz-pv.yaml
- 查看
kubectl get pv
- 删除
kubectl delete pv wiz-pv-volume
wiz-pv.yamlapiVersion: v1
kind: PersistentVolume
metadata:
name: wiz-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/app/wiz"
kubectl create -f wiz-pv.yaml
kubectl get pv
kubectl delete pv wiz-pv-volume
- 配置文件
wiz-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wiz-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
- 部署
kubectl create -f wiz-pvc.yaml
- 查看
kubectl get pvc
- 删除
kubectl delete pvc wiz-pv-claim
wiz-pvc.yamlapiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wiz-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
kubectl create -f wiz-pvc.yaml
kubectl get pvc
kubectl delete pvc wiz-pv-claim
- 配置文件
wiz.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: wiz #Deployment名称
labels:
app: wiz
spec:
replicas: 2 #目标副本数量
selector:
matchLabels:
app: wiz
template:
metadata:
labels:
app: wiz
spec:
volumes:
- name: wiz-pv-storage
persistentVolumeClaim:
claimName: wiz-pv-claim #PVC 存储名称
containers:
- name: wizserver
image: wiznote/wizserver:latest
resources: {}
imagePullPolicy: Always
volumeMounts: #容器内挂载点
- mountPath: "/wiz/storage/"
name: wiz-pv-storage #必须有名称
ports: #定义端口
- name: container-port #定义pod名称
containerPort: 80 #定义pod端口
protocol: TCP #定义TCP
restartPolicy: Always
terminationGracePeriodSeconds: 30
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
- 部署
kubectl create -f wiz.yaml
wiz.yamlkind: Deployment
apiVersion: apps/v1
metadata:
name: wiz #Deployment名称
labels:
app: wiz
spec:
replicas: 2 #目标副本数量
selector:
matchLabels:
app: wiz
template:
metadata:
labels:
app: wiz
spec:
volumes:
- name: wiz-pv-storage
persistentVolumeClaim:
claimName: wiz-pv-claim #PVC 存储名称
containers:
- name: wizserver
image: wiznote/wizserver:latest
resources: {}
imagePullPolicy: Always
volumeMounts: #容器内挂载点
- mountPath: "/wiz/storage/"
name: wiz-pv-storage #必须有名称
ports: #定义端口
- name: container-port #定义pod名称
containerPort: 80 #定义pod端口
protocol: TCP #定义TCP
restartPolicy: Always
terminationGracePeriodSeconds: 30
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
kubectl create -f wiz.yaml
- 配置文件
wiz-service.yaml
apiVersion: v1
kind: Service
metadata:
name: wiz-service
spec:
type: NodePort
selector:
app: wiz
ports:
- protocol: TCP
port: 8888
targetPort: 80
- 部署
kubectl create -f wiz-service.yaml
wiz-service.yamlapiVersion: v1
kind: Service
metadata:
name: wiz-service
spec:
type: NodePort
selector:
app: wiz
ports:
- protocol: TCP
port: 8888
targetPort: 80
kubectl create -f wiz-service.yaml
