停止/启动集群
您可以停止/启动集群以释放计算资源。当集群停止时,其计算资源将被释放,也就是说 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。
kubectl edit cluster mycluster -n demo
>
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: mycluster
spec:
clusterDefinitionRef: apecloud-mysql
clusterVersionRef: ac-mysql-8.0.30
terminationPolicy: Delete
componentSpecs:
- name: mysql
componentDefRef: mysql
disableExporter: true
replicas: 0
volumeClaimTemplates:
- name: data
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gikbcli cluster stop mycluster -n demo
查看集群状态,确认集群是否已停止。
- kbcli
- kubectl
kbcli cluster list mycluster -n demo
kubectl get cluster 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 数值调整为停止集群前的数量,再次启动集群。
kubectl edit cluster mycluster -n demo
>
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: mycluster
spec:
clusterDefinitionRef: apecloud-mysql
clusterVersionRef: ac-mysql-8.0.30
terminationPolicy: Delete
componentSpecs:
- name: mysql
componentDefRef: mysql
disableExporter: true
replicas: 3
volumeClaimTemplates:
- name: data
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gikbcli cluster start mycluster -n demo
查看集群状态,确认集群是否再次启动。
- kbcli
- kubectl
kbcli cluster list mycluster -n demo
kubectl get cluster mycluster -n demo