Delete Kubernetes Resource

Action ID: kube:delete
NPM Package:

@devangelista/backstage-scaffolder-kubernetes

Description

Deletes a specified Kubernetes resource in the designated namespace from the specified cluster.

Input Schema

PropertyTypeDescriptionRequired
kindstringThe kind of the resource
namestringThe name of the resource
tokenstringAn optional OIDC token that will be used to authenticate to the Kubernetes cluster
namespacestringThe namespace of the resource
apiVersionstringThe apiVersion of the resource
clusterNamestringThe name of the Kubernetes cluster to use (from app-config)

Output Schema

No output schema defined for this action.

Usage Examples

Delete a preview Deployment when a pull request closes

Removes an ephemeral Deployment created for a pull request preview environment. Run this after fetch:template when cleaning up PR resources.

Copy
steps:
  - id: fetch-skeleton
    action: fetch:template
    input:
      url: https://github.com/acme/templates/service-skeleton/archive/main.zip
      targetPath: .
      values:
        serviceName: ${{ parameters.serviceName }}
        owner: ${{ parameters.owner }}

  - id: delete-preview-deployment
    action: kube:delete
    input:
      apiVersion: apps/v1
      kind: Deployment
      name: ${{ parameters.serviceName }}-pr-${{ parameters.prNumber }}
      namespace: preview-pr-${{ parameters.prNumber }}
      clusterName: dev-cluster

Remove a stale ConfigMap in staging

Deletes a ConfigMap so that a fresh one can be recreated during deployment. Use this after fetch:template when rotating configuration.

Copy
steps:
  - id: fetch-config
    action: fetch:template
    input:
      url: https://github.com/acme/platform-config/archive/main.zip
      targetPath: .
      values:
        env: ${{ parameters.env }}
        app: ${{ parameters.app }}

  - id: delete-staging-configmap
    action: kube:delete
    input:
      apiVersion: v1
      kind: ConfigMap
      name: app-config
      namespace: ${{ parameters.env }} # e.g. staging

Clean up a completed Job in the CI namespace

Deletes a completed or failed Job so a pipeline can recreate it with the correct spec. Run this after fetch:template in CI workflows that manage database migrations.

Copy
steps:
  - id: fetch-migration-spec
    action: fetch:template
    input:
      url: https://github.com/acme/db-migrations/archive/main.zip
      targetPath: .
      values:
        releaseTag: ${{ parameters.releaseTag }}

  - id: delete-ci-job
    action: kube:delete
    input:
      apiVersion: batch/v1
      kind: Job
      name: db-migration-${{ parameters.releaseTag }}
      namespace: ci
      clusterName: build-cluster
      token: ${{ parameters.kubeOidcToken }}

Delete an obsolete Ingress in production cluster

Removes an Ingress that is no longer needed after cutover to a new domain or service. Use this after fetch:template when finalizing a migration.

Copy
steps:
  - id: fetch-routing
    action: fetch:template
    input:
      url: https://github.com/acme/networking/ingress-ops/archive/main.zip
      targetPath: .
      values:
        app: web-frontend
        env: prod

  - id: delete-prod-ingress
    action: kube:delete
    input:
      apiVersion: networking.k8s.io/v1
      kind: Ingress
      name: web-frontend
      namespace: prod
      clusterName: prod-east-1

Remove an HPA before switching to cluster autoscaler

Deletes a HorizontalPodAutoscaler to avoid conflicts with new scaling policies. Run this after fetch:template when decommissioning per workload autoscaling.

Copy
steps:
  - id: fetch-hpa-state
    action: fetch:template
    input:
      url: https://github.com/acme/ops/hpa-maintenance/archive/main.zip
      targetPath: .
      values:
        serviceName: ${{ parameters.serviceName }}
        team: ${{ parameters.team }}

  - id: delete-hpa
    action: kube:delete
    input:
      apiVersion: autoscaling/v2
      kind: HorizontalPodAutoscaler
      name: ${{ parameters.serviceName }}
      namespace: team-a
      clusterName: dev-eu