Delete Kubernetes Resources

Updated 1 month ago by Michael Cretzman

Remove any deployed Kubernetes resources with the K8s Delete step.

Looking for Canary Delete? See Canary Delete Step.

In this topic:

Before You Begin

Step 1: Add Delete Step

In your Harness stage Execution, click Add Step, and select K8s Delete. The K8s Delete settings appear:

You can add a K8s Delete step anywhere in your stage.

Wherever you add a K8s Delete step, the resource you want to delete must already exist in the cluster. For example, if the resource is added in Canary phase of a stage, the K8s Delete step should not be placed in the Primary Deployment phase that follows it.

Enter a name for the step.

Step 2: Select Resources to Delete

In Delete resources by, select how you want to select the resources to be deleted.

There are a few ways to specify the resource to be removed.

Option: Resource Name

Using a resource name in the format [namespace]/Kind/Name, with namespace being optional.

You must add a Kind before the resource name, like this: 

Deployment/harness-example-deployment-canary

Enter multiple resources using Add.

To delete all resources, use the Release Name option, explained below.

Option: Manifest Path

Enter the path to the manifest for the resource you want to delete. The path is relative to the folder path entered in File/Folder Path in the Manifest Details settings:

Enter multiple resources using Add File.

Option: Release Name

During deployment Harness creates a ConfigMap listing the resources of the release and uses the release name for tracking them. The release name is defined in the Infrastructure settings, in Cluster Details, in Advanced.

If you want to delete all of the resources for a release, select Release Name.

If you select the Delete namespace option, Harness will delete the namespace(s) defined in the release.

Ensure that you are not deleting a namespace that is used by other deployments.

Example: Deleting a Deployment

Here is an example of the log from a Delete command:

Initializing..
...
Resources to delete are:
- Deployment/harness-example-deployment-canary
Done.

Example 2: Deleting All Resources and Namespaces

Here is an example deleting all resources in the release and the namespace:

All Resources are selected for deletion
Delete Namespace is set to: true
Fetching all resources created for release: release-44e74aca-279f-3b4a-bb15-06d750393a8d

Resources to delete are:
- adwait-12/Deployment/harness-example-deployment
- adwait-12/Service/harness-example-svc
- adwait-12/ConfigMap/release-44e74aca-279f-3b4a-bb15-06d750393a8d
- adwait-12/ConfigMap/harness-example-2
- adwait-12/ConfigMap/harness-example-1
- adwait-12/Secret/harness-example-2
- adwait-12/Secret/harness-example-1
- adwait-12/Namespace/adwait-12
Done.

Notes

  • Delete and Traffic Management: If you are splitting traffic or doing Istio traffic shifting using the Apply step, move the K8s Delete step after the traffic shifting. This will prevent any traffic from being routed to deleted pods before traffic is routed to stable pods.

See Also


Please Provide Feedback