Destroy an OpenShift cluster created by create-cluster command
Destroys an OpenShift cluster and cleans up all cloud resources safely.
/plugin marketplace add openshift-eng/ai-helpers/plugin install openshift@ai-helpers[install-dir]openshift:destroy-cluster
/openshift:destroy-cluster [install-dir]
The destroy-cluster command safely destroys an OpenShift Container Platform (OCP) cluster that was previously created using the /openshift:create-cluster command. It locates the appropriate installer binary, verifies the cluster information, and performs cleanup of all cloud resources.
This command is useful for:
⚠️ WARNING: This operation is irreversible and will permanently delete:
Before using this command, ensure you have:
Installation directory from the original cluster creation
{cluster-name}-install-{timestamp} by defaultOpenShift installer binary that matches the cluster version
~/.openshift-installers/openshift-install-{version}Cloud Provider Credentials still configured and valid
Network connectivity to the cloud provider
./my-cluster-install-20251028-120000The command performs the following steps:
If install-dir is not provided:
*-install-* or containing .openshift_install_state.jsonIf install-dir is provided:
Read cluster details from the installation directory:
# Read cluster metadata
if [ -f "$INSTALL_DIR/metadata.json" ]; then
CLUSTER_NAME=$(jq -r '.clusterName' "$INSTALL_DIR/metadata.json")
INFRA_ID=$(jq -r '.infraID' "$INSTALL_DIR/metadata.json")
PLATFORM=$(jq -r '.platform' "$INSTALL_DIR/metadata.json")
fi
# Try to extract version from cluster-info or log files
VERSION=$(grep -oE 'openshift-install.*v[0-9]+\.[0-9]+\.[0-9]+' "$INSTALL_DIR/.openshift_install.log" | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+[^"]*' | head -1)
Show the user what will be destroyed:
Cluster Information:
Name: ${CLUSTER_NAME}
Infrastructure ID: ${INFRA_ID}
Platform: ${PLATFORM}
Installation Directory: ${INSTALL_DIR}
Version: ${VERSION}
⚠️ WARNING: This will permanently destroy the cluster and all its resources!
This action will delete:
- All cluster VMs and compute resources
- Load balancers and networking resources
- Storage volumes and persistent data
- DNS records
- All cluster configuration
Are you sure you want to destroy this cluster? (yes/no):
Important: Require the user to type "yes" (not just "y") to confirm destruction.
Find the installer binary that matches the cluster version:
INSTALLER_DIR="${HOME}/.openshift-installers"
INSTALLER_PATH="$INSTALLER_DIR/openshift-install-${VERSION}"
# Check if the version-specific installer exists
if [ ! -f "$INSTALLER_PATH" ]; then
echo "Warning: Installer for version ${VERSION} not found at ${INSTALLER_PATH}"
echo "Searching for alternative installers..."
# Look for any installer in the installers directory
AVAILABLE_INSTALLERS=$(find "$INSTALLER_DIR" -name "openshift-install-*" -type f 2>/dev/null)
if [ -n "$AVAILABLE_INSTALLERS" ]; then
echo "Found installers:"
echo "$AVAILABLE_INSTALLERS"
echo ""
echo "You may use a different version installer, but this may cause issues."
echo "Would you like to:"
echo " 1. Use an available installer from the list above"
echo " 2. Extract the correct installer from the release image"
echo " 3. Cancel the operation"
else
echo "No installers found. Would you like to extract the installer? (yes/no):"
fi
fi
# Verify installer works
"$INSTALLER_PATH" version
Offer to backup key files before destruction:
Would you like to backup cluster information before destroying? (yes/no):
If yes, create a backup:
BACKUP_DIR="${INSTALL_DIR}-backup-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$BACKUP_DIR"
# Backup key files
cp "$INSTALL_DIR/metadata.json" "$BACKUP_DIR/" 2>/dev/null
cp "$INSTALL_DIR/auth/kubeconfig" "$BACKUP_DIR/" 2>/dev/null
cp "$INSTALL_DIR/auth/kubeadmin-password" "$BACKUP_DIR/" 2>/dev/null
cp "$INSTALL_DIR/.openshift_install.log" "$BACKUP_DIR/" 2>/dev/null
cp "$INSTALL_DIR/install-config.yaml.backup" "$BACKUP_DIR/" 2>/dev/null
echo "Backup created at: $BACKUP_DIR"
Execute the destroy command:
cd "$INSTALL_DIR"
echo "Starting cluster destruction..."
echo "This may take 10-15 minutes..."
"$INSTALLER_PATH" destroy cluster --dir=. --log-level=debug
DESTROY_EXIT_CODE=$?
Monitor the destruction progress and display status updates.
After the destroy command completes:
Check exit code:
if [ $DESTROY_EXIT_CODE -eq 0 ]; then
echo "✅ Cluster destroyed successfully"
else
echo "❌ Cluster destruction failed with exit code: $DESTROY_EXIT_CODE"
echo "Check logs at: $INSTALL_DIR/.openshift_install.log"
fi
Verify cloud resources (platform-specific):
kubernetes.io/cluster/${INFRA_ID}List any remaining resources:
If any resources remain, provide commands to manually clean them up.
Ask the user if they want to remove the installation directory:
The cluster has been destroyed. Would you like to delete the installation directory? (yes/no):
Directory: $INSTALL_DIR
Size: $(du -sh "$INSTALL_DIR" | cut -f1)
If yes:
rm -rf "$INSTALL_DIR"
echo "Installation directory removed"
If no:
echo "Installation directory preserved at: $INSTALL_DIR"
echo "You can manually remove it later with: rm -rf $INSTALL_DIR"
Show final summary:
Cluster Destruction Summary:
Cluster Name: ${CLUSTER_NAME}
Status: Successfully destroyed
Platform: ${PLATFORM}
Duration: ${DURATION}
Backup: ${BACKUP_DIR} (if created)
Next steps:
- Verify your cloud console for any lingering resources
- Check your cloud billing to ensure resources are no longer incurring charges
- Remove installation directory if not already deleted: ${INSTALL_DIR}
If destruction fails, the command should:
.openshift_install.logCommon failure scenarios:
Timeout errors:
# Some resources may take longer to delete
# Retry the destroy command:
"$INSTALLER_PATH" destroy cluster --dir="$INSTALL_DIR"
Permission errors:
Error: Cloud credentials may have expired or lack permissions
Solution:
1. Verify cloud credentials are still valid
2. Check IAM permissions for resource deletion
3. Re-run the destroy command after fixing credentials
Partial destruction:
Warning: Some resources could not be deleted automatically.
Remaining resources:
- Load balancer: ${LB_NAME}
- Security group: ${SG_NAME}
- S3 bucket: ${BUCKET_NAME}
Manual cleanup commands:
[Platform-specific commands to delete remaining resources]
/openshift:destroy-cluster
The command will search for installation directories and prompt you to select one.
/openshift:destroy-cluster ./my-cluster-install-20251028-120000
/openshift:destroy-cluster /home/user/clusters/test-cluster-install-20251028-120000
Installation directory not found:
Installer binary not found:
~/.openshift-installers/Cloud credentials expired:
Resources already deleted manually:
Destroy hangs or times out:
This command includes several safety measures:
/openshift:create-cluster - Create a new OCP cluster