Skip to main content

Kubernetes Delete

Last updated on

The Kubernetes Delete step removes resources from a Kubernetes cluster. Use it to clean up resources that are no longer needed: for example, deleting a canary workload manually, removing a Job after it completes, or tearing down a full release.


Before you begin

Before you configure the step, make sure you have the following in place:

  • A Kubernetes service: Go to Kubernetes services to set up service manifests and artifact source.
  • A Kubernetes infrastructure: Go to Kubernetes infrastructure to connect your cluster and namespace.
  • A Harness delegate in target cluster: The delegate runs deployment steps in the cluster.
  • Runtime configuration: Every Kubernetes stage requires a runtime block specifying the connector and namespace. Go to Kubernetes runtime configuration to understand the required fields.

Add the Kubernetes Delete step

To add the step:

  1. In your pipeline, go to the Kubernetes stage.
  2. Select + Add Step in the execution section.
  3. Search for Kubernetes Delete and select it.
  4. Configure the step parameters described below.
  5. Select Apply Changes.

Configure the step

The following parameters are available on the Kubernetes Delete step.

ParameterDescriptionRequired
NameDisplay name for the step in the pipeline.Required
Kubeconfig PathPath to the kubeconfig file, derived from the infrastructure configuration. Default: ${{infra.kube_config_path}}.Required
ResourcesComma-separated list of resources to delete, in namespace/Kind/name format. For example, default/Deployment/my-app,default/Service/my-svc.Conditional*
Release NameThe Harness release name. Harness deletes all resources associated with this release from the cluster release history.Conditional*
Manifest PathsComma-separated list of manifest file paths. Harness parses the files and deletes all resources defined in them.Conditional*
Include Namespace ResourcesWhen enabled, includes namespace-scoped resources in the deletion. Default: false.Optional
NamespaceCluster namespace used when a resource entry does not include a namespace prefix. Default: default.Optional
Command FlagsAdditional flags passed to the kubectl delete command. Use JSON format: [{"Delete": "--force --grace-period=0"}].Optional
TimeoutMaximum time the step can run before it is marked as failed. Default: 5m.Optional

*At least one of Resources, Release Name, or Manifest Paths must be provided. The step is skipped silently if all three are empty.


Choose a deletion source

You can specify what to delete in three ways, and you can combine them:

Resources: Provide explicit resource identifiers in namespace/Kind/name format. Harness deletes each resource directly. Use this when you know the exact resources to delete.

Release Name: Provide the Harness release name. Harness looks up all resources tracked under that release in the cluster release history secret and deletes them. Use this when you want to tear down an entire managed release.

Manifest Paths: Provide paths to rendered manifest files on the Harness workspace. Harness parses each file, extracts the resource kinds and names, and deletes them. Use this when you want to delete exactly the resources defined in a set of manifests.


YAML example

- name: Kubernetes Delete
id: k8sDeleteStep
template:
uses: k8sDeleteStep
with:
resources:
- default/Deployment/my-app
- default/Service/my-svc

To delete by release name:

- name: Kubernetes Delete
id: k8sDeleteStep
template:
uses: k8sDeleteStep
with:
release_name: '<+infra.releaseName>'

Advanced settings

The following advanced settings are available on the Kubernetes Delete step.

  • Timeout duration: Maximum time the step is allowed to run before being terminated.
  • On failure: Define what happens if the step fails, such as retry, mark as success, or abort.
  • Strategy: Configure a looping strategy to run this step over a list of values.
  • Conditional execution: Run this step only when a specified condition is true.

Next steps