删除后重新创建 K8S 中的 Statefulsets
Statefulsets in K8S are being recreated after deletion
我正在使用 Elasticsearch 运算符 Kubernetes 并创建了两个有状态集(参见 https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-orchestration.html):
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: quickstart
spec:
version: 7.12.1
nodeSets:
- name: master-nodes
count: 3
config:
node.roles: ["master"]
volumeClaimTemplates:
- metadata:
name: elasticsearch-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: standard
- name: data-nodes
count: 3
config:
node.roles: ["data"]
volumeClaimTemplates:
- metadata:
name: elasticsearch-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: standard
问题是我无法删除状态集。删除后会自动重新创建:
my-PC:~$ kubectl get sts
NAME READY AGE
quickstart-es-data-nodes 0/0 14m
quickstart-es-master-nodes 0/0 18m
my-PC:~$ kubectl delete sts quickstart-es-data-nodes --force --grace-period=0
warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
statefulset.apps "quickstart-es-data-nodes" force deleted
my-PC:~$ kubectl get sts
NAME READY AGE
quickstart-es-data-nodes 0/3 3s
quickstart-es-master-nodes 0/0 18m
在删除之前,我已经将 statefulset 缩小为 0,以确保所有 pods 都被终止。但是在删除之后,有状态被重新创建(参见 quickstart-es-data-nodes)。
那么,有人知道如何删除有状态集而不重新创建吗?
您必须删除自定义对象。运营商拥有这些 StatefulSets 并将不断更新它们以匹配其预期内容。
这是因为您为 Elasticsearch 使用的运算符。运营商管理 statefulset,如果您删除它,将会更新。
Behind the scenes, ECK translates each NodeSet specified in the
Elasticsearch resource into a StatefulSet in Kubernetes.
如果您阅读文档:https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-orchestration.html#k8s-statefulsets
https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#on-delete
我终于得到答案了...我需要运行以下命令进行删除:
kubectl delete elasticsearch quickstart
这最终删除了快速入门示例。
我正在使用 Elasticsearch 运算符 Kubernetes 并创建了两个有状态集(参见 https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-orchestration.html):
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: quickstart
spec:
version: 7.12.1
nodeSets:
- name: master-nodes
count: 3
config:
node.roles: ["master"]
volumeClaimTemplates:
- metadata:
name: elasticsearch-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: standard
- name: data-nodes
count: 3
config:
node.roles: ["data"]
volumeClaimTemplates:
- metadata:
name: elasticsearch-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: standard
问题是我无法删除状态集。删除后会自动重新创建:
my-PC:~$ kubectl get sts
NAME READY AGE
quickstart-es-data-nodes 0/0 14m
quickstart-es-master-nodes 0/0 18m
my-PC:~$ kubectl delete sts quickstart-es-data-nodes --force --grace-period=0
warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
statefulset.apps "quickstart-es-data-nodes" force deleted
my-PC:~$ kubectl get sts
NAME READY AGE
quickstart-es-data-nodes 0/3 3s
quickstart-es-master-nodes 0/0 18m
在删除之前,我已经将 statefulset 缩小为 0,以确保所有 pods 都被终止。但是在删除之后,有状态被重新创建(参见 quickstart-es-data-nodes)。
那么,有人知道如何删除有状态集而不重新创建吗?
您必须删除自定义对象。运营商拥有这些 StatefulSets 并将不断更新它们以匹配其预期内容。
这是因为您为 Elasticsearch 使用的运算符。运营商管理 statefulset,如果您删除它,将会更新。
Behind the scenes, ECK translates each NodeSet specified in the Elasticsearch resource into a StatefulSet in Kubernetes.
如果您阅读文档:https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-orchestration.html#k8s-statefulsets
https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#on-delete
我终于得到答案了...我需要运行以下命令进行删除:
kubectl delete elasticsearch quickstart
这最终删除了快速入门示例。