> 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-k8s-ref/kubernetes-apply-step.md).

# Kubernetes Apply step

Reference for the Kubernetes Apply step settings, used to deploy independent workloads outside the primary deployment manifests.

The Kubernetes Apply step deploys workloads outside of the primary and sidecar workloads of your deployment. Use this step when you want to deploy an additional resource only after Harness has verified the deployment of the main resources in the **Manifests** section.

For a walkthrough of using this step, go to [Deploy manifests separately using the Apply step](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-executions/deploy-manifests-using-apply-step.md).

***

## What you will learn from this topic

* **When to use the Apply step:** How the Apply step differs from the Rolling Deployment step and when to choose it.
* **Manifest sources:** How to configure the step to apply manifests from the service definition or from a remote Git repository.
* **Step settings:** What each setting controls, including timeout, dry run, steady state check, and manifest rendering.
* **Namespace behavior:** How the Apply step resolves the target namespace from infrastructure and manifest settings.

***

## Workloads and deployment strategy

### What workloads can I deploy?

Go to [What can I deploy in Kubernetes?](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-k8s-ref/what-can-i-deploy-in-kubernetes.md) to review supported workload types for the Apply step.

### Rolling vs Apply

The Rolling Deployment step and the Apply step serve different purposes. The following table summarizes the key differences.

|                             | **Jobs** | **Rollback** |
| --------------------------- | -------- | ------------ |
| **Rolling Deployment step** | No       | Yes          |
| **Apply step**              | Yes      | No           |

The Rolling Deployment step is the default for a Rolling strategy. The Apply step can be used with any strategy and supports Jobs, but does not support rollback.

***

## Step settings reference

This section describes each setting in the Kubernetes Apply step.

### Name

Enter a name for the Apply step. Harness automatically generates a step ID from the name. The step ID is used to reference the step by its Fully Qualified Name (FQN), for example `<+execution.steps.[step Id].name>`.

If the step ID is `Apply`, the FQN expressions for the step settings are:

* `<+execution.steps.Apply.name>`
* `<+execution.steps.Apply.spec.filePaths>`
* `<+execution.steps.Apply.spec.skipDryRun>`
* `<+execution.steps.Apply.spec.skipSteadyStateCheck>`
* `<+execution.steps.Apply.timeout>`

### Apply manifests from a remote source

{% embed url="<https://www.loom.com/share/492afdbb9cb8484980b6d1617830a399?sid=90c41fc9-a556-44e0-82e4-59206bbf493e>" %}

Harness provides two options for applying Kubernetes manifests:

* **Service option:** When you configure from the service, you can provide a file path within the manifest source repository configured in the service definition.
* **Remote option:** When you configure the remote option, you can provide a Harness Git connector, a repository location, and a file path to apply any Kubernetes manifest. You can also provide a `values.yaml` file for Go templating in the configuration.

{% hint style="warning" %}
**GitHub file size limitation**

When using a GitHub connector to fetch manifest files, the GitHub Contents API has a 1 MB file size limit. If your manifest file exceeds 1 MB, the Apply step fails.

To work around this, use the platform-agnostic Git connector instead of the GitHub connector. The Git connector uses `git clone`, which does not have the same file size limitation. Go to [Connect to a code repo](https://developer.harness.io/docs/platform/connectors/code-repositories/connect-to-code-repo#use-the-platform-agnostic-git-connector) to connect to your code repository without the file size constraint.

Alternatively, split your large manifest file into multiple smaller files, each under 1 MB.
{% endhint %}

{% hint style="info" %}
**Kubernetes resource size limits**

Even when using the Git connector, Kubernetes enforces size limits on certain resources:

* **ConfigMaps:** Cannot exceed 1 MB in total size.
* **Custom Resource Definitions (CRDs):** Default etcd limit of 1.5 MB.

Go to the [Kubernetes ConfigMap documentation](https://kubernetes.io/docs/concepts/configuration/configmap/#motivation) to understand ConfigMap size constraints, and go to the [etcd documentation](https://etcd.io/docs/latest/dev-guide/limit/) to understand etcd object size limits.
{% endhint %}

When **Remote Manifest** is selected, the logs show output similar to the following:

```
Trying to fetch default values yaml file for manifest with identifier: [APPLY_STEP_MANIFEST_SOURCE_ID]

Fetching K8sManifest files with identifier: APPLY_STEP_MANIFEST_SOURCE_ID
Git connector Url: https://github.com/wings-software/PipelinesNgAutomation.git
Branch: tarun-test-3

Fetching following Files :
- k8s/manifests/k8s/basicManifests/templates/values.yaml
No values.yaml found for manifest with identifier: APPLY_STEP_MANIFEST_SOURCE_ID.

Fetching K8sManifest files with identifier: APPLY_STEP_MANIFEST_SOURCE_ID
Git connector Url: https://github.com/wings-software/PipelinesNgAutomation.git
Branch: tarun-test-3

Fetching following Files :
- k8s/manifests/k8s/basicManifests/values.yaml
Successfully fetched following files:
- k8s/manifests/k8s/basicManifests/values.yaml

Git Fetch Files completed successfully.

Starting Kubernetes Apply

Fetching K8sManifest files with identifier: APPLY_STEP_MANIFEST_SOURCE_ID
Git connector Url: https://github.com/wings-software/PipelinesNgAutomation.git
Branch: tarun-test-3

Fetching manifest files at path:
- k8s/manifests/k8s/basicManifests/templates
- k8s/manifests/k8s/basicManifests/simple-manifest-2/deployment.yaml
Successfully fetched following files:
- k8s/manifests/k8s/basicManifests/simple-manifest-2/deployment.yaml
- k8s/manifests/k8s/basicManifests/templates/deployment.yaml
- k8s/manifests/k8s/basicManifests/templates/service.yaml
- k8s/manifests/k8s/basicManifests/templates/namespace.yaml

...


kubectl --kubeconfig=config apply --filename=manifests.yaml
namespace/tarun-ng configured
secret/githubsdas configured
secret/githubsdas-dockercfg unchanged
configmap/githubsdas unchanged
service/githubsdas-svc unchanged
deployment.apps/githubsdas unchanged
deployment.apps/myapp-deployment-2 unchanged

Done.
```

### File path configuration for the service option

Enter the path to a manifest file. The **File Path** field has the following requirements:

* The path to the manifest for the Apply step must be subordinate to the path for the manifest in the **Manifests** section of the Service Definition. The manifest cannot be in the same folder as **Manifests**.
* The path must include the folder name and the file name.

In the following example, the path used in the **Manifests** section of the Service Definition is `default-k8s-manifests/Manifests/Files/templates/`. The **Apply** step uses a Job manifest in the subfolder `jobs/job.yaml`.

![Kubernetes Apply step file path configuration showing a Job manifest in a subordinate jobs subfolder](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-e0152fafc1bcec0cc1d9e949458396c5cf3f6ce6%2Fkubernetes-apply-step-00.png?alt=media)

You can enter multiple file paths in **File Path** by clicking **Add file**.

### Timeout

Enter how long Harness should run this step before failing it. Enter a minimum of `10m` to account for network activity in your target environment.

### Skip dry run

By default, Harness uses the `--dry-run` flag on the `kubectl apply` command during the **Initialize** step. This prints the object that would be sent to the cluster without sending it.

Select **Skip Dry Run** to disable this behavior. Harness does not use the `--dry-run` flag when this option is selected.

### Skip steady state check

By default, Harness checks whether a deployed workload has reached steady state. Select **Skip Steady State Check** to disable this check.

### Skip K8s manifest(s) rendering

By default, Harness uses Go templating and a `values.yaml` file for manifest templating. If your manifests use a different formatting method, select **Skip K8s Manifest(s) Rendering** to skip Go template rendering.

Go to [Deploy manifests separately using the Apply step](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-executions/deploy-manifests-using-apply-step.md) to review manifest rendering behavior.

### Advanced settings

The following advanced settings are available for the Kubernetes Apply step:

* Go to [Delegate selector](https://developer.harness.io/docs/platform/delegates/manage-delegates/select-delegates-with-selectors) to control which delegate runs this step.
* Go to [Conditional execution](https://developer.harness.io/docs/platform/pipelines/step-skip-condition-settings) to configure when this step runs.
* Go to [Failure strategy](https://developer.harness.io/docs/platform/pipelines/failure-handling/define-a-failure-strategy-on-stages-and-steps) to define how Harness handles step failures.
* Go to [Looping strategy](https://developer.harness.io/docs/platform/pipelines/looping-strategies/looping-strategies-matrix-repeat-and-parallelism) to run this step across a matrix or in parallel.
* Go to [Command flags](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-kubernetes-category/k8s-command-flags.md) to pass additional flags to the `kubectl` command.
* Go to [Policy enforcement](https://developer.harness.io/docs/platform/governance/policy-as-code/harness-governance-overview) to apply governance policies to this step.

***

## Frequently asked questions

<details>

<summary>Where does the Harness Kubernetes Apply step run by default?</summary>

In a Kubernetes or Native Helm deployment type, the Apply step runs in the target cluster namespace specified in the Harness pipeline stage **Infrastructure** under **Environment**.

</details>

<details>

<summary>How do I configure the Apply step to run in a different namespace than the one defined in the infrastructure definition?</summary>

Any namespace defined in the manifest you are deploying takes precedence over the namespace specified in the Harness stage **Infrastructure**.

You can use a `values.yaml` file to specify the namespace and reference it in the manifest. In an Apply step, you can override this `values.yaml` and specify a different namespace for that particular Apply step.

</details>

<details>

<summary>Can the Apply step render empty manifest files?</summary>

No. The Kubernetes Apply step cannot render empty files. Empty manifests result in a step failure. The manifest must have complete and defined resources to apply.

</details>

***

## Next steps

* [Deploy manifests separately using the Apply step](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-executions/deploy-manifests-using-apply-step.md): Walk through configuring and running the Apply step in a CD pipeline.
* [Add a Kubernetes sidecar container](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-kubernetes-category/add-a-kubernetes-sidecar-container.md): Deploy sidecar containers alongside your primary workload.
* [What can I deploy in Kubernetes?](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-k8s-ref/what-can-i-deploy-in-kubernetes.md): Review supported Kubernetes workload types and deployment options.

{% @harness-feedback/feedback %}
