停止/启动集群
您可以停止/启动集群以释放计算资源。停止集群后,其计算资源将被释放,也就是说 Kubernetes 的 Pod 将被释放,但其存储资源仍将被保留。您也可以重新启动该集群,使其恢复到停止集群前的状态。
停止集群
步骤:
-
配置集群名称,并执行以下命令来停止该集群。
- OpsRequest
- 编辑集群 YAML 文件
- kbcli
kubectl apply -f - <<EOF
apiVersion: apps.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: ops-stop
namespace: demo
spec:
clusterName: mycluster
type: Stop
EOF将 replicas 设为 0,删除 Pods。
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: mycluster
namespace: demo
spec:
clusterDefinitionRef: mongodb
clusterVersionRef: mongodb-5.0
terminationPolicy: Delete
componentSpecs:
- name: mongodb
componentDefRef: mongodb
disableExporter: true
replicas: 0
volumeClaimTemplates:
- name: data
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gikbcli cluster stop mycluster -n demo
-
检查集群的状态,查看其是否已停止。
- kubectl
- kbcli
kubectl get cluster mycluster -n demo
kbcli cluster list mycluster -n demo
启动集群
-
配置集群名称,并执行以下命令来启动该集群。
- OpsRequest
- 编辑集群 YAML 文件
- kbcli
kubectl apply -f - <<EOF
apiVersion: apps.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name:ops-start
namespace: demo
spec:
clusterName: mycluster
type: Start
EOF将 replicas 数值调整为停止集群前的数量,再次启动集群。
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: mycluster
namespace: demo
spec:
clusterDefinitionRef: mongodb
clusterVersionRef: mongodb-5.0
terminationPolicy: Delete
componentSpecs:
- name: mongodb
componentDefRef: mongodb
disableExporter: true
replicas: 1
volumeClaimTemplates:
- name: data
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gikbcli cluster start mycluster -n demo
-
查看集群状态,确认集群是否再次启动。
- kubectl
- kbcli
kubectl get cluster mycluster -n demo
kbcli cluster list mycluster -n demo