LinuxCommandLibrary

kubectl-apply

creates or updates Kubernetes resources

TLDR

Apply manifest

$ kubectl apply -f [manifest.yaml]
copy
Apply directory
$ kubectl apply -f [manifests/]
copy
Apply from URL
$ kubectl apply -f [https://example.com/manifest.yaml]
copy
Apply with kustomization
$ kubectl apply -k [directory/]
copy
Dry run
$ kubectl apply -f [manifest.yaml] --dry-run=client
copy
Server-side apply
$ kubectl apply -f [manifest.yaml] --server-side
copy

SYNOPSIS

kubectl apply [options] -f filename

DESCRIPTION

kubectl apply creates or updates Kubernetes resources using declarative configuration files. It compares the desired state defined in YAML or JSON manifests against the current state of the cluster and makes only the necessary changes to reconcile any differences, using a three-way merge strategy that considers the last-applied configuration, the live state, and the new manifest.
The command accepts manifests from local files, directories, URLs, or Kustomize overlays, making it well-suited for GitOps workflows where cluster state is version-controlled. It supports both client-side and server-side apply modes, with server-side apply providing better conflict detection when multiple actors manage the same resource through field ownership tracking.
This is the recommended approach for managing Kubernetes resources in production, as it preserves changes made by other controllers and allows incremental updates without replacing entire resource definitions.

PARAMETERS

-f FILE

File, directory, or URL.
-k DIR
Kustomization directory.
--dry-run MODE
client, server, or none.
--server-side
Server-side apply.
--force-conflicts
Force apply on conflicts.
-n NAMESPACE
Target namespace.
--help
Display help information.

CAVEATS

Subcommand of kubectl. Last-applied annotation used. Prefer over create for management.

HISTORY

kubectl apply implements declarative resource management for Kubernetes, enabling GitOps workflows.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community