如何重用现有的持久卷声明
How to reuse an existing persistent volume claims
我已经删除了我的 elasticsearch 集群,但现在在我部署了一个新集群后,我需要访问存储在 3 个持久卷 PV 上的旧数据,如下所述:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
storage-es-data-0 Bound pvc-19429b0b-ba42-11e7-979d-42010a840ff7 12Gi RWO standard 10d
storage-es-data-1 Bound pvc-36505962-ba42-11e7-979d-42010a840ff7 12Gi RWO standard 10d
storage-es-data-2 Bound pvc-422da328-ba42-11e7-979d-42010a840ff7 12Gi RWO standard 10d
这是对旧 PV 声明的描述:
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-19429b0b-ba42-11e7-979d-42010a840ff7 12Gi RWO Delete Bound default/storage-es-data-0 standard 10d
pvc-36505962-ba42-11e7-979d-42010a840ff7 12Gi RWO Delete Bound default/storage-es-data-1 standard 10d
pvc-422da328-ba42-11e7-979d-42010a840ff7 12Gi RWO Delete Bound default/storage-es-data-2 standard 10d
我的新部署描述如下:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: es-data
labels:
component: elasticsearch
role: data
spec:
replicas: 1
template:
metadata:
labels:
component: elasticsearch
role: data
spec:
initContainers:
- name: init-sysctl
image: busybox
imagePullPolicy: IfNotPresent
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
containers:
- name: es-data
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.3
imagePullPolicy: Always
ports:
- containerPort: 9300
name: transport
protocol: TCP
volumeMounts:
- name: storage
mountPath: /data
volumes:
- name: storage
persistentVolumeClaim:
claimName: storage-es-data-0
将我的 pod 连接到 Loadblance 服务后,我没有找到任何文件。我错过了什么吗?以及如何在同一个 POD 中使用三个 PV。
您的 deployment
yaml 文件是正确的。您应该能够在 Pod 的 /data
文件夹中的 pvc-19429b0b-ba42-11e7-979d-42010a840ff7
卷中找到文件。
为了在同一个 POD 中使用三个 PV,只需将它们添加到您的 deployment
yaml 中:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: es-data
labels:
component: elasticsearch
role: data
spec:
replicas: 1
template:
metadata:
labels:
component: elasticsearch
role: data
spec:
initContainers:
- name: init-sysctl
image: busybox
imagePullPolicy: IfNotPresent
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
containers:
- name: es-data
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.3
imagePullPolicy: Always
ports:
- containerPort: 9300
name: transport
protocol: TCP
volumeMounts:
- name: storage-0
mountPath: /data0
- name: storage-1
mountPath: /data1
- name: storage-2
mountPath: /data2
volumes:
- name: storage-0
persistentVolumeClaim:
claimName: storage-es-data-0
- name: storage-1
persistentVolumeClaim:
claimName: storage-es-data-1
- name: storage-2
persistentVolumeClaim:
claimName: storage-es-data-2
我已经删除了我的 elasticsearch 集群,但现在在我部署了一个新集群后,我需要访问存储在 3 个持久卷 PV 上的旧数据,如下所述:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
storage-es-data-0 Bound pvc-19429b0b-ba42-11e7-979d-42010a840ff7 12Gi RWO standard 10d
storage-es-data-1 Bound pvc-36505962-ba42-11e7-979d-42010a840ff7 12Gi RWO standard 10d
storage-es-data-2 Bound pvc-422da328-ba42-11e7-979d-42010a840ff7 12Gi RWO standard 10d
这是对旧 PV 声明的描述:
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-19429b0b-ba42-11e7-979d-42010a840ff7 12Gi RWO Delete Bound default/storage-es-data-0 standard 10d
pvc-36505962-ba42-11e7-979d-42010a840ff7 12Gi RWO Delete Bound default/storage-es-data-1 standard 10d
pvc-422da328-ba42-11e7-979d-42010a840ff7 12Gi RWO Delete Bound default/storage-es-data-2 standard 10d
我的新部署描述如下:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: es-data
labels:
component: elasticsearch
role: data
spec:
replicas: 1
template:
metadata:
labels:
component: elasticsearch
role: data
spec:
initContainers:
- name: init-sysctl
image: busybox
imagePullPolicy: IfNotPresent
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
containers:
- name: es-data
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.3
imagePullPolicy: Always
ports:
- containerPort: 9300
name: transport
protocol: TCP
volumeMounts:
- name: storage
mountPath: /data
volumes:
- name: storage
persistentVolumeClaim:
claimName: storage-es-data-0
将我的 pod 连接到 Loadblance 服务后,我没有找到任何文件。我错过了什么吗?以及如何在同一个 POD 中使用三个 PV。
您的 deployment
yaml 文件是正确的。您应该能够在 Pod 的 /data
文件夹中的 pvc-19429b0b-ba42-11e7-979d-42010a840ff7
卷中找到文件。
为了在同一个 POD 中使用三个 PV,只需将它们添加到您的 deployment
yaml 中:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: es-data
labels:
component: elasticsearch
role: data
spec:
replicas: 1
template:
metadata:
labels:
component: elasticsearch
role: data
spec:
initContainers:
- name: init-sysctl
image: busybox
imagePullPolicy: IfNotPresent
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
containers:
- name: es-data
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.3
imagePullPolicy: Always
ports:
- containerPort: 9300
name: transport
protocol: TCP
volumeMounts:
- name: storage-0
mountPath: /data0
- name: storage-1
mountPath: /data1
- name: storage-2
mountPath: /data2
volumes:
- name: storage-0
persistentVolumeClaim:
claimName: storage-es-data-0
- name: storage-1
persistentVolumeClaim:
claimName: storage-es-data-1
- name: storage-2
persistentVolumeClaim:
claimName: storage-es-data-2