Manually delete an environment

Updated at:

This topic describes how to manually delete environment resources in AppStack for specific scenarios. This process ensures system cleanliness and efficient resource utilization.

Delete non-workload resources

You can directly delete non-workload resources, such as Service, Ingress, ConfigMap, Secret, and PersistentVolumeClaim, using kubectl commands or other methods.

For example, you can run the following command to delete a Service resource with a .metadata.name of service-demo. For more information about kubectl commands, see the kubectl overview.

kubectl delete service service-demo

Delete workload resources

AppStack enhances deployments using the Open Application Model (OAM). Because AppStack uses OAM to manage workloads, resources are recreated if you delete them directly. You must follow these steps to delete them manually:

Note: The following examples use kubectl and assume a connection to the cluster from a local development machine. The workload to be deleted has a .metadata.name of deploy-demo and is in the namespace-demo namespace.

1. Confirm the workload

Run the following command to view the workload that you want to delete.

kubectl get application deploy-demo -n namespace-demo
kubectl get componentdefinition deploy-demo -n namespace-demo

2. Identify the locator labels

If the orchestration object and component definition from Step 1 exist, run the following command to view the orchestration object.

kubectl get application deploy-demo -n namespace-demo -o=yaml

The orchestration object is similar to the following:

metadata:
  name: "deploy-demo"
  namespace: "namespace-demo"
  annotations:
    app.oam.dev/rollout-template: "true"
    app.oam.dev/rolling-components: "deploy-demo"
    appstack.aliyun.com/change-made-by: "1f061dfd-d612-4628-914f-14b4c207fe5f"
  labels:
    appstack/appconfig-selector: "deploy-demo"
    appstack/current-revision: "deploy-demo-v1"
    devops.aliyun.com/app-name: "app1028836"
    devops.aliyun.com/env-name: "production"
    devops.aliyun.com/org-id: "5ebbc0******************"
apiVersion: "core.oam.dev/v1beta1"
kind: "Application"
spec:
  components:
  - name: "deploy-demo"
    type: "deploy-demo"
    properties: {}
    traits: []

Find the following three labels in the orchestration object. They correspond to the application name, environment name, and Apsara DevOps organization ID:

devops.aliyun.com/app-name: "app1028836"
devops.aliyun.com/env-name: "production"
devops.aliyun.com/org-id: "5ebbc0******************"

3. Use labels to delete the deployment helper object (approllout)

Use the labels for the application name, environment name, and Apsara DevOps organization ID that you identified in Step 2. Run the following command to delete the deployment helper object (approllout).

kubectl delete approllout -l devops.aliyun.com/app-name=app1028836,devops.aliyun.com/env-name=production,devops.aliyun.com/org-id=5ebbc0****************** -n namespace-demo

Run the following command to confirm the deletion of the helper object. The deletion is complete when the kubectl output shows that the object cannot be found.

kubectl get approllout -l devops.aliyun.com/app-name=app1028836,devops.aliyun.com/env-name=production,devops.aliyun.com/org-id=5ebbc0****************** -n namespace-demo

4. Delete the OAM workload management object

Run the following command to delete the OAM workload management objects.

kubectl delete application deploy-demo -n namespace-demo

Run the following command to confirm that the OAM workload management objects are deleted. The deletion is complete when the kubectl output indicates that the objects are not found.

kubectl get application deploy-demo -n namespace-demo

If you want to confirm the deletion progress of the deployment, you can run the following command. When the kubectl command returns no results, the cascade cleanup of the deployment is complete.

kubectl delete componentdefinition deploy-demo -n namespace-demo

5. Clean up the component definition metadata

Run the following command to delete the component definition metadata.

kubectl delete componentdefinition deploy-demo -n namespace-demo

Run the following command to confirm the deletion of the component definition metadata. The deletion is complete when the kubectl output shows that the object cannot be found.

kubectl get componentdefinition deploy-demo -n namespace-demo

This completes the cleanup of the workload resources.