Delete Kubernetes Resources

Updated 1 month ago by Michael Cretzman

Remove any deployed Kubernetes resources with the Delete step.

In this topic:

Before You Begin

Step 1: Add Delete Step

In your Harness Workflow, click Add Step, and select Delete. The Delete settings appear:

You can add a Delete step anywhere in your Workflow, but typically it is added in the Wrap Up section.

Wherever you add a Delete step, the resource you want to delete must already exist in the cluster. For example, if the resource is added in Phase 2 of a Canary Workflow, the Delete step should not be placed in Phase 1.

Step 2: Select Resources to Delete

In Resources, enter the resources to be deleted.

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

Harness Built-in Variables

Using the Harness built-in variable, ${k8s.canaryWorkload}.

At runtime, this will resolve to something like:

Deployment/harness-example-deployment-canary

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/${k8s.canaryWorkload}. For example: 

Deployment/harness-example-deployment-canary

Multiple Resources

Using a comma-separated list to delete multiple resources. For example:

Deployment/harness-example-deployment-canary,ConfigMap/harness-example-config

All Resources

Using an asterisk (*) deletes all of the releases specified in the Infrastructure Definition Release Name setting used by the Workflow. The namespace is not deleted.

Delete Namespaces

If you want to delete the namespace(s) defined in the Manifests section of the Harness Service used in this deployment, click the Delete all namespaces defined in the Manifests section of the Harness Service used in this deployment checkbox.

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

Example 1: Deleting ${k8s.canaryWorkload}

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 using * and the Delete all namespaces defined in the Manifests section of the Harness Service used in this deployment setting:

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

  • Canary Delete and Traffic Management —If you are using the Traffic Split step or doing Istio traffic shifting using the Apply step, move the Canary Delete step from Wrap Up section of the Canary phase to the Wrap Up section of the Primary phase.
    Moving the Canary Delete step to the Wrap Up section of the Primary phase will prevent any traffic from being routed to deleted pods before traffic is routed to stable pods in the Primary phase. See Create a Kubernetes Canary Deployment and Set Up Kubernetes Traffic Splitting.

Next Steps


How did we do?