// Module included in the following assemblies:
//
// * hosted_control_planes/hcp-destroy/hcp-destroy-ibmz.adoc

:_mod-docs-content-type: PROCEDURE
[id="destroy-hc-ibmz-cli_{context}"]
= Destroying a hosted cluster on x86 bare metal with {ibm-z-title} compute nodes

[role="_abstract"]
To destroy a hosted cluster and its managed cluster on `x86` bare metal with {ibm-z-name} compute nodes, you can use the command-line interface (CLI).

.Procedure

. Scale the `NodePool` object to `0` nodes by running the following command:
+
[source,terminal]
----
$ oc -n <hosted_cluster_namespace> scale nodepool <nodepool_name> \
  --replicas 0
----
+
After the `NodePool` object is scaled to `0`, the compute nodes are detached from the hosted cluster. In {product-title} version 4.17, this function is applicable only for {ibm-z-title} with KVM. For z/VM and LPAR, you must delete the compute nodes manually.
+
If you want to re-attach compute nodes to the cluster, you can scale up the `NodePool` object with the number of compute nodes that you want. For z/VM and LPAR to reuse the agents, you must re-create them by using the `Discovery` image.
+
[IMPORTANT]
====
If the compute nodes are not detached from the hosted cluster or are stuck in the `Notready` state, delete the compute nodes manually by running the following command:
[source,terminal]
----
$ oc --kubeconfig <hosted_cluster_name>.kubeconfig delete \
  node <compute_node_name>
----
====
If you are using an OSA network device in Processor Resource/Systems Manager (PR/SM) mode, auto scaling is not supported. You must delete the old agent manually and scale up the node pool because the new agent joins during the scale down process. 

. Verify the status of the compute nodes by entering the following command:
+
[source,terminal]
----
$ oc --kubeconfig <hosted_cluster_name>.kubeconfig get nodes
----
+
After the compute nodes are detached from the hosted cluster, the status of the agents is changed to `auto-assign`.

. Delete the agents from the cluster by running the following command:
+
[source,terminal]
----
$ oc -n <hosted_control_plane_namespace> delete agent <agent_name>
----
+
[NOTE]
====
You can delete the virtual machines that you created as agents after you delete the agents from the cluster.
====

. Destroy the hosted cluster by running the following command:
+
[source,terminal]
----
$ hcp destroy cluster agent --name <hosted_cluster_name> \
  --namespace <hosted_cluster_namespace>
----
