使用来自@yvesonline 的建议,我能够实现上面的选项 1。
- 填充我的原始卷后,拍摄快照
gcloud compute disks snapshot [PD-name] --zone=[zone] --snapshot-names=mysql-seed-snapshot-21022020 --description="Snapshot of the /var/lib/mysql folder"
- 使用快照创建新磁盘
gcloud compute disks create pvc-example-1 --source-snapshot=mysql-seed-snapshot-21022020 --zone=europe-west2-a
- 在集群中新建pv和pvc:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-demo
spec:
persistentVolumeReclaimPolicy: Delete
storageClassName: ""
capacity:
storage: 30Gi
accessModes:
- ReadWriteOnce
gcePersistentDisk:
pdName: pvc-example-1
fsType: ext4
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-claim-demo
spec:
# It's necessary to specify "" as the storageClassName
# so that the default storage class won't be used, see
# https://kubernetes.io/docs/concepts/storage/persistent-volumes/#class-1
storageClassName: ""
volumeName: pv-demo
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 30Gi
- 然后使用上面创建的 pvc 启动新部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:5.7
name: mysql
env:
# Use secret in real usage
- name: MYSQL_ROOT_PASSWORD
value: root
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: task-pv-storage
mountPath: /var/lib/mysql
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: pv-claim-demo
一旦在 GKE 中更确定了 K8s 中的卷克隆,这将更容易,但同时此解决方案也可以!