Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions 15.KubeCon_NA_2025_Demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# AWS Credentials
.env.aws

# Python virtual environment
.venv/
venv/
env/

# Jupyter Notebook checkpoints
.ipynb_checkpoints/

# Environment variables
.env
.env.sh

# Generated files from notebooks
crossplane/
kubevela/
test/
setup/

# Python cache
__pycache__/
*.pyc
*.pyo

# OS files
.DS_Store
Thumbs.db

# IDE files
.vscode/
.idea/
*.swp
*.swo
352 changes: 352 additions & 0 deletions 15.KubeCon_NA_2025_Demo/00-Env-cleanup.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,352 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# KubeCon NA 2025 Demo - Cleanup\n",
"\n",
"This notebook tears down the demo environment and cleans up all resources.\n",
"\n",
"## What will be cleaned up:\n",
"- k3d cluster (including all deployments and data)\n",
"- Local cluster configuration\n",
"- Any running containers from the cluster\n",
"\n",
"**Warning:** This operation is destructive and cannot be undone. Make sure you have saved any important data before proceeding."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Configuration loaded: Will delete cluster 'kubecon-demo'\n",
"\n",
"⚠️ WARNING: This will delete all cluster data!\n",
"Cluster to be deleted: kubecon-demo\n"
]
}
],
"source": [
"import yaml\n",
"import os\n",
"\n",
"# Load configuration\n",
"config_file = 'config.yaml'\n",
"\n",
"if os.path.exists(config_file):\n",
" with open(config_file, 'r') as f:\n",
" config = yaml.safe_load(f)\n",
" cluster_name = config['cluster']['name']\n",
" print(f\"Configuration loaded: Will delete cluster '{cluster_name}'\")\n",
"else:\n",
" cluster_name = 'kubecon-demo'\n",
" print(f\"Config file not found, using default cluster name: '{cluster_name}'\")\n",
"\n",
"print(\"\\n⚠️ WARNING: This will delete all cluster data!\")\n",
"print(f\"Cluster to be deleted: {cluster_name}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 1: Check Current Cluster Status\n",
"\n",
"Let's verify what clusters currently exist before deletion."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=== Current k3d Clusters ===\n",
"NAME SERVERS AGENTS LOADBALANCER\n",
"kubecon-demo 1/1 0/0 true\n",
"\n",
"=== Current kubectl context ===\n",
"k3d-kubecon-demo\n"
]
}
],
"source": [
"%%bash\n",
"echo \"=== Current k3d Clusters ===\"\n",
"k3d cluster list\n",
"\n",
"echo \"\"\n",
"echo \"=== Current kubectl context ===\"\n",
"kubectl config current-context 2>/dev/null || echo \"No active context\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 2: Optional - Export Resources\n",
"\n",
"If you want to save any configurations before deletion, run this cell to export key resources."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Resource export is disabled by default. Uncomment the code above to enable.\n"
]
}
],
"source": [
"%%bash\n",
"# Uncomment the following lines if you want to export resources\n",
"\n",
"# EXPORT_DIR=\"exports/$(date +%Y%m%d_%H%M%S)\"\n",
"# mkdir -p \"$EXPORT_DIR\"\n",
"#\n",
"# echo \"Exporting resources to $EXPORT_DIR...\"\n",
"#\n",
"# # Export Crossplane resources\n",
"# kubectl get providers -o yaml > \"$EXPORT_DIR/providers.yaml\" 2>/dev/null || true\n",
"# kubectl get compositions -o yaml > \"$EXPORT_DIR/compositions.yaml\" 2>/dev/null || true\n",
"# kubectl get xrds -o yaml > \"$EXPORT_DIR/xrds.yaml\" 2>/dev/null || true\n",
"#\n",
"# echo \"✓ Resources exported to $EXPORT_DIR\"\n",
"\n",
"echo \"Resource export is disabled by default. Uncomment the code above to enable.\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 3: Delete the k3d Cluster\n",
"\n",
"This will remove the entire cluster and all its resources."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=== Deleting k3d Cluster: kubecon-demo ===\n",
"Found cluster 'kubecon-demo', deleting...\n",
"\u001b[36mINFO\u001b[0m[0000] Deleting cluster 'kubecon-demo' \n",
"\u001b[36mINFO\u001b[0m[0002] Deleting cluster network 'k3d-kubecon-demo' \n",
"\u001b[36mINFO\u001b[0m[0003] Deleting 1 attached volumes... \n",
"\u001b[36mINFO\u001b[0m[0003] Removing cluster details from default kubeconfig... \n",
"\u001b[36mINFO\u001b[0m[0003] Removing standalone kubeconfig file (if there is one)... \n",
"\u001b[36mINFO\u001b[0m[0003] Successfully deleted cluster kubecon-demo! \n",
"✓ Cluster 'kubecon-demo' deleted successfully\n",
"\n",
"Remaining k3d clusters:\n",
"NAME SERVERS AGENTS LOADBALANCER\n"
]
}
],
"source": [
"%%bash\n",
"set -e\n",
"\n",
"CLUSTER_NAME=\"kubecon-demo\"\n",

@cubic-dev-ai cubic-dev-ai Bot Oct 25, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup cells hardcode CLUSTER_NAME="kubecon-demo", so if someone changes cluster.name in config.yaml the teardown will skip the actual cluster/context and leave resources running. Please feed the configured name into these bash cells instead of the literal string.

Prompt for AI agents
Address the following comment on 15.KubeCon_NA_2025_Demo/00-Env-cleanup.ipynb at line 170:

<comment>The cleanup cells hardcode `CLUSTER_NAME=&quot;kubecon-demo&quot;`, so if someone changes `cluster.name` in config.yaml the teardown will skip the actual cluster/context and leave resources running. Please feed the configured name into these bash cells instead of the literal string.</comment>

<file context>
@@ -0,0 +1,352 @@
+    &quot;%%bash\n&quot;,
+    &quot;set -e\n&quot;,
+    &quot;\n&quot;,
+    &quot;CLUSTER_NAME=\&quot;kubecon-demo\&quot;\n&quot;,
+    &quot;\n&quot;,
+    &quot;echo \&quot;=== Deleting k3d Cluster: $CLUSTER_NAME ===\&quot;\n&quot;,
</file context>
Fix with Cubic

"\n",
"echo \"=== Deleting k3d Cluster: $CLUSTER_NAME ===\"\n",
"\n",
"# Check if cluster exists\n",
"if k3d cluster list | grep -q \"$CLUSTER_NAME\"; then\n",
" echo \"Found cluster '$CLUSTER_NAME', deleting...\"\n",
" \n",
" if k3d cluster delete \"$CLUSTER_NAME\"; then\n",
" echo \"✓ Cluster '$CLUSTER_NAME' deleted successfully\"\n",
" else\n",
" echo \"✗ Failed to delete cluster\"\n",
" exit 1\n",
" fi\n",
"else\n",
" echo \"⚠ Cluster '$CLUSTER_NAME' not found (may already be deleted)\"\n",
"fi\n",
"\n",
"echo \"\"\n",
"echo \"Remaining k3d clusters:\"\n",
"k3d cluster list"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 4: Clean Up kubectl Context\n",
"\n",
"Remove the cluster context from kubectl configuration."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=== Cleaning up kubectl context ===\n",
"⚠ Context 'k3d-kubecon-demo' not found\n",
"\n",
"Current kubectl contexts:\n",
"CURRENT NAME CLUSTER AUTHINFO NAMESPACE\n",
" k3d-k3s-default k3d-k3s-default admin@k3d-k3s-default \n",
" loft-vcluster_vcluster1_tenantproject loft-vcluster_vcluster1_tenantproject loft-vcluster_vcluster1_tenantproject \n",
"* loft-vcluster_vclustera_default loft-vcluster_vclustera_default loft-vcluster_vclustera_default \n",
" rancher-desktop rancher-desktop rancher-desktop \n"
]
}
],
"source": [
"%%bash\n",
"CLUSTER_NAME=\"kubecon-demo\"\n",
"CONTEXT_NAME=\"k3d-$CLUSTER_NAME\"\n",
"\n",
"echo \"=== Cleaning up kubectl context ===\"\n",
"\n",
"# Delete context if it exists\n",
"if kubectl config get-contexts \"$CONTEXT_NAME\" &>/dev/null; then\n",
" kubectl config delete-context \"$CONTEXT_NAME\" 2>/dev/null || true\n",
" echo \"✓ Context '$CONTEXT_NAME' removed\"\n",
"else\n",
" echo \"⚠ Context '$CONTEXT_NAME' not found\"\n",
"fi\n",
"\n",
"# Delete cluster entry if it exists\n",
"if kubectl config get-clusters | grep -q \"$CONTEXT_NAME\"; then\n",
" kubectl config delete-cluster \"$CONTEXT_NAME\" 2>/dev/null || true\n",
" echo \"✓ Cluster entry '$CONTEXT_NAME' removed\"\n",
"fi\n",
"\n",
"echo \"\"\n",
"echo \"Current kubectl contexts:\"\n",
"kubectl config get-contexts || echo \"No contexts available\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 5: Verification\n",
"\n",
"Verify that cleanup was successful."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=== Cleanup Verification ===\n",
"\n",
"k3d clusters:\n",
"NAME SERVERS AGENTS LOADBALANCER\n",
"\n",
"kubectl contexts:\n",
"CURRENT NAME CLUSTER AUTHINFO NAMESPACE\n",
" k3d-k3s-default k3d-k3s-default admin@k3d-k3s-default \n",
" loft-vcluster_vcluster1_tenantproject loft-vcluster_vcluster1_tenantproject loft-vcluster_vcluster1_tenantproject \n",
"* loft-vcluster_vclustera_default loft-vcluster_vclustera_default loft-vcluster_vclustera_default \n",
" rancher-desktop rancher-desktop rancher-desktop \n",
"\n",
"Docker containers (k3d related):\n",
"NAMES STATUS\n",
"\n",
"✓ Cleanup verification complete\n"
]
}
],
"source": [
"%%bash\n",
"echo \"=== Cleanup Verification ===\"\n",
"echo \"\"\n",
"\n",
"echo \"k3d clusters:\"\n",
"k3d cluster list\n",
"echo \"\"\n",
"\n",
"echo \"kubectl contexts:\"\n",
"kubectl config get-contexts 2>/dev/null || echo \"No contexts\"\n",
"echo \"\"\n",
"\n",
"echo \"Docker containers (k3d related):\"\n",
"docker ps -a --filter \"name=k3d\" --format \"table {{.Names}}\\t{{.Status}}\" 2>/dev/null || echo \"No k3d containers\"\n",
"echo \"\"\n",
"\n",
"echo \"✓ Cleanup verification complete\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cleanup Complete!\n",
"\n",
"The demo environment has been successfully torn down.\n",
"\n",
"### What was cleaned up:\n",
"- ✓ k3d cluster deleted\n",
"- ✓ kubectl context removed\n",
"- ✓ Docker containers stopped and removed\n",
"\n",
"### To start fresh:\n",
"Run the `00_Env-setup.ipynb` notebook again to recreate the environment.\n",
"\n",
"### Remaining artifacts:\n",
"- Configuration files (config.yaml) - kept for reuse\n",
"- Setup manifests (setup/ directory) - kept for reuse\n",
"- Python environment and packages - kept for reuse\n",
"\n",
"If you want to remove these as well, you can manually delete them from the file system."
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading