我正在尝试创建一个Kubernetes pod,其中包含一个单独的容器,该容器上挂载了两个外部卷。我的.yml pod文件如下:
apiVersion: v1
kind: Pod
metadata:
name: my-project
labels:
name: my-project
spec:
containers:
- image: my-username/my-project
name: my-project
ports:
- containerPort: 80
name: nginx-http
- containerPort: 443
name: nginx-ssl-https
imagePullPolicy: Always
volumeMounts:
- mountPath: /home/projects/my-project/media/upload
name: pd-data
- mountPath: /home/projects/my-project/backups
name: pd2-data
imagePullSecrets:
- name: vpregistrykey
volumes:
- name: pd-data
persistentVolumeClaim:
claimName: pd-claim
- name: pd2-data
persistentVolumeClaim:
claimName: pd2-claim
我正在使用持久卷和持久卷声明,如下所示:
PV
apiVersion: v1
kind: PersistentVolume
metadata:
name: pd-disk
labels:
name: pd-disk
spec:
capacity:
storage: 250Gi
accessModes:
- ReadWriteOnce
gcePersistentDisk:
pdName: "pd-disk"
fsType: "ext4"
PVC
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pd-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 250Gi
我最初使用以下命令创建了我的磁盘:
$ gcloud compute disks create --size 250GB pd-disk
第二个磁盘、第二个PV和PVC也是如此。当我创建pod时,似乎一切正常,没有出现错误。现在出现了奇怪的情况:其中一个路径被正确挂载(因此是持久的),而另一个路径每次重新启动pod时都会被删除...我已经尝试从头开始重新创建所有内容,但没有任何改变。此外,从pod的描述中,两个卷似乎都被正确挂载:
$ kubectl describe pod my-project
Name: my-project
...
Volumes:
pd-data:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: pd-claim
ReadOnly: false
pd2-data:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: pd2-claim
ReadOnly: false
非常感谢您的帮助。谢谢。
kubectl delete -f my-project.yml
然后跟着使用kubectl create -f my-project.yml
。 - AdelaNkubectl version
的输出是什么? - Yu-Ju HongClient Version: version.Info{Major:"1", Minor:"1", GitVersion:"v1.1.4", GitCommit:"a5949fea3a91d6a50f40a5684e05879080a4c61d", GitTreeState:"clean"} Server Version: version.Info{Major:"1", Minor:"1", GitVersion:"v1.1.7", GitCommit:"e4e6878293a339e4087dae684647c9e53f1cf9f0", GitTreeState:"clean"}
- AdelaN