teardown-secrets-demo.sh reverses everything created by deploy-secrets-demo.sh, deleting all secrets demo resources in the correct dependency order. It is the "spin down" half of the secrets demo lifecycle.
The script is fully non-interactive. All configuration is driven by the same environment variables as the deploy script (loaded from .env via Docker Compose). No user input or confirmation prompts are required.
Switches to the guest cluster kubeconfig and deletes the secrets-demo namespace. This cascading delete removes all namespaced resources:
- sslip.io Ingress and TLS Certificate (if
USE_SSLIP_DNSwas enabled) secrets-dashboardDeployment + LoadBalancer Service (releases the NSX external IP)- Redis Deployment + ClusterIP Service
- PostgreSQL Deployment + ClusterIP Service
internal-app-tokenOpaque Secret (copied supervisor token)test-service-accountServiceAccount + token Secret- vault-injector pod, Service, and all namespaced RBAC resources
If the kubeconfig file is not found (e.g., the cluster was already torn down), this phase is skipped gracefully.
Deletes cluster-scoped resources created by the vault-injector package that are not removed by namespace deletion:
vault-injector-clusterroleClusterRolevault-injector-clusterrolebindingClusterRoleBindingvault-injector-cfgMutatingWebhookConfiguration
Switches back to the supervisor context (via VCF CLI) and deletes:
redis-credsKeyValueSecret (viavcf secret delete)postgres-credsKeyValueSecret (viavcf secret delete)internal-appServiceAccountinternal-app-tokenSecret (the long-lived token in the supervisor)
- Docker and Docker Compose installed
- The
vcf9-devcontainer running (docker compose up -d) - A populated
.envfile with the same variables used by the deploy script
The teardown script uses a subset of the deploy script's variables:
| Variable | Description | Example |
|---|---|---|
CLUSTER_NAME |
VKS guest cluster name | my-project-01-clus-01 |
VCF_API_TOKEN |
API token from the VCFA portal | uT3s3jCY8GIPzK... |
VCFA_ENDPOINT |
VCFA hostname (no https:// prefix) |
vcfa01.vmw-lab1.example.com |
TENANT_NAME |
SSO tenant/organization | org-rax-01 |
CONTEXT_NAME |
Local VCF CLI context name | my-dev-automation |
Optional: NAMESPACE (default: secrets-demo), KUBECONFIG_FILE (default: ./kubeconfig-<CLUSTER_NAME>.yaml).
The Secrets Demo teardown is integrated into the Teardown VCF Stacks workflow:
- Go to Actions → "Teardown VCF Stacks" → "Run workflow"
- Enter the cluster_name
- Ensure the appropriate teardown checkboxes are selected
- The workflow handles kubeconfig retrieval and supervisor context switching automatically
docker exec \
-e CLUSTER_NAME=my-project-01-clus-01 \
vcf9-dev bash examples/deploy-secrets-demo/teardown-secrets-demo.shIf you need to tear down resources manually:
# 1. Delete guest cluster namespace
export KUBECONFIG=./kubeconfig-<CLUSTER_NAME>.yaml
kubectl delete ns secrets-demo --ignore-not-found
# 2. Delete cluster-scoped vault-injector resources
kubectl delete clusterrole vault-injector-clusterrole --ignore-not-found
kubectl delete clusterrolebinding vault-injector-clusterrolebinding --ignore-not-found
kubectl delete mutatingwebhookconfiguration vault-injector-cfg --ignore-not-found
# 3. Switch to supervisor context and delete secrets + service account
unset KUBECONFIG
vcf context use <CONTEXT_NAME>
vcf secret delete redis-creds
vcf secret delete postgres-creds
kubectl delete sa internal-app --ignore-not-found
kubectl delete secret internal-app-token --ignore-not-foundA successful run produces output like this:
[Step 1] Deleting secrets-demo namespace in guest cluster...
✓ Namespace 'secrets-demo' deleted (or did not exist)
[Step 2] Deleting cluster-scoped resources from guest cluster...
✓ ClusterRole 'vault-injector-clusterrole' deleted
✓ ClusterRoleBinding 'vault-injector-clusterrolebinding' deleted
✓ MutatingWebhookConfiguration 'vault-injector-cfg' deleted
[Step 3] Switching to supervisor context and cleaning up supervisor resources...
✓ KeyValueSecret 'redis-creds' deleted
✓ KeyValueSecret 'postgres-creds' deleted
✓ ServiceAccount 'internal-app' deleted
✓ Secret 'internal-app-token' deleted
=============================================
VCF 9 Secrets Demo — Teardown Complete
=============================================
Namespace: secrets-demo (deleted)
Secrets: redis-creds, postgres-creds (deleted)
ServiceAccount: internal-app (deleted)
=============================================
| Phase | Duration |
|---|---|
| Phase 1 (Namespace deletion) | 10–30s |
| Phase 2 (Cluster-scoped cleanup) | ~5s |
| Phase 3 (Supervisor cleanup) | ~10s |
| Total | ~25s–1 min |
The teardown script is safe to run multiple times. If resources are already deleted, each phase skips gracefully:
- Missing kubeconfig → skips guest cluster cleanup (Phases 1 and 2)
- Missing namespace →
--ignore-not-foundprevents errors - Missing ClusterRole / ClusterRoleBinding / MutatingWebhookConfiguration →
--ignore-not-foundon all deletes - Missing KeyValueSecrets →
vcf secret deleteexits cleanly - Missing ServiceAccount / Secret →
--ignore-not-foundon all deletes - VCF CLI context issues → attempts to recreate the context before proceeding
No phase aborts on failure — the script continues to the next resource and reports status in the teardown summary.