> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-kubernetes-category/k8s-command-flags.md).

# Add Kubernetes Command Flags

Add Kubernetes command flags to customize the behavior of K8s steps.

Harness supports adding command flags to Kubernetes steps so you can customize how `kubectl` behaves during a deployment.

***

## What you will learn from this topic

* The difference between [command types and command flags](#overview) in Kubernetes
* [Where to add command flags](#where-you-can-add-command-flags-in-different-k8s-steps) in a Kubernetes step
* Which [command flags](#k8s-command-types-and-its-command-flags) are supported for `apply`, `delete`, `rollout`, and `patch`

***

## Overview <a href="#overview" id="overview"></a>

In Kubernetes, commands are made up of two main components:

Command types: These represent the core actions you can perform on your cluster resources, such as `get`, `apply`, `delete`, `patch`, and `logs`. Each type maps to a specific operational intent: retrieving, modifying, or managing resources.

Command flags: These are optional parameters that allow you to customize the behavior of each command. For example, flags like `--namespace`, `-o`, `--force`, or `--watch` let you specify the target namespace, output format, execution mode, and more.

Together, command types and flags give you powerful control over how you interact with your Kubernetes workloads using kubectl.

***

## Where you can add command flags in different k8s steps <a href="#where-you-can-add-command-flags-in-different-k8s-steps" id="where-you-can-add-command-flags-in-different-k8s-steps"></a>

Navigate to the executions tab of the deploy stage and select the k8s step you want to add. In the advanced tab of the step details, you can add the required command in the command flag dropdown.

Each k8s step supports a particular command type based on the type of execution the step performs.

***

## K8s command types and its command flags <a href="#k8s-command-types-and-its-command-flags" id="k8s-command-types-and-its-command-flags"></a>

### `kubectl apply` <a href="#kubectl-apply" id="kubectl-apply"></a>

**Description:**\
The `kubectl apply` command is used to create or update resources in a Kubernetes cluster from a configuration file (usually in YAML or JSON format). It is commonly used for deploying applications or updating configurations for existing resources.

| Flag                      | Description                                  |
| ------------------------- | -------------------------------------------- |
| `-f`                      | File or directory with manifests             |
| `--record`                | Record the command in resource annotation    |
| `--dry-run=client/server` | Preview changes without applying             |
| `--prune`                 | Delete objects not in the configuration file |
| `--force-conflicts`       | Force apply changes during conflicts         |

You can use this command in:

* [K8s Rolling Deploy](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-executions/create-a-kubernetes-rolling-deployment.md)
* [K8s Canary Deploy](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-executions/create-a-kubernetes-canary-deployment.md)
* [K8s Blue Green Deploy](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-executions/create-a-kubernetes-blue-green-deployment.md)
* [K8s Apply](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-k8s-ref/kubernetes-apply-step.md)
* [K8s Rollout Rollback](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-k8s-ref/kubernetes-rollout-step.md)

Go to the [Kubernetes documentation](https://kubernetes.io/docs/reference/kubectl/generated/kubectl_apply/) to learn more about the `kubectl apply` command.

### `kubectl delete` <a href="#kubectl-delete" id="kubectl-delete"></a>

**Description:**\
The `kubectl delete` command is used to remove resources (e.g., pods, services, deployments) from the Kubernetes cluster. It helps to clean up or remove unnecessary resources.

| Flag             | Description                                |
| ---------------- | ------------------------------------------ |
| `-f`             | Manifest file                              |
| `--grace-period` | Time to wait before forcefully terminating |
| `--force`        | Force deletion                             |
| `--wait`         | Wait for resource deletion to complete     |

You can use this command in the following step:

* [K8s Delete step](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-executions/delete-kubernetes-resources.md)

Go to the [Kubernetes documentation](https://kubernetes.io/docs/reference/kubectl/generated/kubectl_delete/) to learn more about the `kubectl delete` command.

### `kubectl rollout` <a href="#kubectl-rollout" id="kubectl-rollout"></a>

**Description:**\
The `kubectl rollout` command is used to manage the rollout process of deployments. It is used to view or manage the status of an application's deployment or perform rollbacks to previous versions.

| Flag         | Description                  |
| ------------ | ---------------------------- |
| `--revision` | Specify revision to rollback |
| `--watch`    | Watch status updates         |

This command can be added in the following step:

* [K8s Rollout step](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-k8s-ref/kubernetes-rollout-restart.md)

Go to the [Kubernetes documentation](https://kubernetes.io/docs/reference/kubectl/generated/kubectl_rollout/) to learn more about the `kubectl rollout` command.

### `kubectl patch` <a href="#kubectl-patch" id="kubectl-patch"></a>

**Description:**\
The `kubectl patch` command allows you to modify an existing Kubernetes resource. It applies changes to a specific part of a resource's configuration (using either JSON or a strategic merge patch).

| Flag                      | Description                                  |
| ------------------------- | -------------------------------------------- |
| `--patch`                 | The actual patch to apply (as a JSON string) |
| `--patch-type`            | One of: strategic, merge, json               |
| `-n, --namespace`         | Namespace of the target resource             |
| `--type`                  | Alias for `--patch-type`                     |
| `--dry-run=client/server` | Preview changes without applying             |
| `-o`                      | Output format (json, yaml, etc.)             |

You can use this command in the following step:

* [K8s Patch Step](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-k8s-ref/kubernetes-patch-step.md)

Go to the [Kubernetes documentation](https://kubernetes.io/docs/reference/kubectl/generated/kubectl_patch/) to learn more about the `kubectl patch` command.

***

## Next steps <a href="#next-steps" id="next-steps"></a>

* [K8s Rolling Deploy](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-executions/create-a-kubernetes-rolling-deployment.md): Add command flags to a rolling deployment step.
* [K8s Apply step](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-k8s-ref/kubernetes-apply-step.md): Apply manifests directly with command flags.

{% @harness-feedback/feedback %}
