k8s pvc 被多个pod使用
一个pvc(pv)被多个container(pod)、volumeMounts使用,进而达到一个工作区独立存储,并按照目录结构进行划分内部的volume
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: smartide-go-claim0
spec:
accessModes:
- ReadWriteOnce # 多个pod使用
resources:
requests:
storage: 100Mi
# storageClassName: standard
# volumeName: test-pv
# selector:
# matchLabels:
# release: test-pv
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: smartide-go
spec:
replicas: 1
selector:
matchLabels:
smartide-cli.service: smartide-test
strategy:
type: Recreate
template:
metadata:
labels:
smartide-cli.service: smartide-test
spec:
containers:
-
image: registry.cn-hangzhou.aliyuncs.com/smartide/smartide-golang-v2-vscode:1749
name: smartide-go-dev
ports:
- containerPort: 3000
- containerPort: 22
resources: {}
volumeMounts:
- mountPath: /home/project/repo
name: smartide-go-claim-storage
subPath: project01/service-name/repo
- mountPath: /home/project/repo/.git
name: smartide-go-claim-storage
subPath: project01/service-name/repo/.git
- mountPath: /home/root/.ssh
name: smartide-go-claim-storage
subPath: project01/service-name/.ssh
-
image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "123"
resources: {}
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: smartide-go-claim-storage
mountPath: /var/lib/mysql
subPath: project01/service-mysql/data
restartPolicy: Always
volumes:
- name: smartide-go-claim-storage
persistentVolumeClaim:
claimName: smartide-go-claim0
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: smartide-go2
spec:
replicas: 1
selector:
matchLabels:
smartide-cli.service: smartide-go2
strategy:
type: Recreate
template:
metadata:
labels:
smartide-cli.service: smartide-go2
spec:
containers:
-
image: registry.cn-hangzhou.aliyuncs.com/smartide/smartide-golang-v2-vscode:1749
name: smartide-go-dev
ports:
- containerPort: 3000
- containerPort: 22
resources: {}
volumeMounts:
- mountPath: /home/project/repo
name: smartide-go-claim-storage
subPath: project01/service-name/repo
restartPolicy: Always
volumes:
- name: smartide-go-claim-storage
persistentVolumeClaim:
claimName: smartide-go-claim0
status: {}
欢迎在评论区留下你宝贵的意见,不论好坏都是我前进的动力(cnblogs 排名提升)!
如果喜欢,记得点赞、推荐、关注、收藏、转发 ... ;)