[英]Deleting Kubernetes cluster should not delete persistance disk
I have created a kubernetes cluster using terraform with persistance disk (pd-ssd).我使用带有持久性磁盘 (pd-ssd) 的 terraform 创建了一个 kubernetes 集群。 I have also created storage class and persistance volume claim as well.我还创建了存储类和持久性卷声明。
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-claim
labels:
app: elasticsearch
spec:
storageClassName: ssd
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 30G
---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: ssd
provisioner: kubernetes.io/gce-pd
parameters:
type: pd-ssd
reclaimPolicy: Retain
---
apiVersion: v1
kind: Service
metadata:
name: elasticsearch
labels:
name: elasticsearch
spec:
type: NodePort
ports:
- name: elasticsearch-port1
port: 9200
protocol: TCP
targetPort: 9200
- name: elasticsearch-port2
port: 9300
protocol: TCP
targetPort: 9300
selector:
app: elasticsearch
tier: elasticsearch
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: elasticsearch-application
labels:
app: elasticsearch
spec:
strategy:
type: Recreate
template:
metadata:
labels:
app: elasticsearch
tier: elasticsearch
spec:
hostname: elasticsearch
containers:
- image: gcr.io/xxxxxxxxxxxx/elasticsearch:7.3.1
name: elasticsearch
ports:
- containerPort: 9200
name: elasticport1
- containerPort: 9300
name: elasticport2
env:
- name: discovery.type
value: single-node
volumeMounts:
- mountPath: /app/elasticsearch/gcp/
name: elasticsearch-pv-volume
volumes:
- name: elasticsearch-pv-volume
persistentVolumeClaim:
claimName: pvc-claim
The pvc-claim and storage classes bound perfeclty and I have set the reclamin policy as retain. pvc-claim 和存储类完美绑定,我已将 reclamin 策略设置为保留。 so the persistance disk should not be deleted when the kubernetes cluster is deleted.所以在删除kubernetes集群时,不应该删除持久化磁盘。 But the cluster and other data's deletes with cluster但是集群和其他数据的删除与集群
My scenerio is I need a persitance disk and when the cluster is deleted also my data's should not be deleted.我的场景是我需要一个持久磁盘,当集群被删除时,我的数据也不应该被删除。 The disk should remain as it is.磁盘应保持原样。 Is there any fesible solution to my scenerio.我的场景是否有任何可行的解决方案。
I have created kubernetes cluster using kOps in AWS.我在 AWS 中使用 kOps 创建了 kubernetes 集群。 When I deleted my cluster I faced same issue as you.当我删除我的集群时,我遇到了和你一样的问题。 The EBS volume that I used for my Database got deleted.我用于数据库的 EBS 卷被删除。 Luckily, I had snapshot to create a volume out of it.幸运的是,我有快照来创建一个卷。
Solution: Remove the tags of the volume from AWS UI.解决方案:从 AWS UI 中删除卷的标签。 And then delete your kubernetes cluster.然后删除您的 kubernetes 集群。 Then the volume will not get removed.然后该卷将不会被删除。 I hope this is possible in GCP too.我希望这在 GCP 中也是可能的。
For more details, have a look at this video and this post有关更多详细信息,请查看此视频和此帖子
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.