kubectl-diff
Show differences between local and live resources
TLDR
View differences between the live resource and file definition
SYNOPSIS
kubectl diff [-f FILENAME|DIR|URL [...]] [-k KUSTOMIZE_DIR] [OPTIONS]
PARAMETERS
-f, --filename []string
Files, directories, or URLs containing Kubernetes manifests to diff
-k, --kustomize string
Path to Kustomize directory for building manifests
-R, --recursive
Recursively process directories specified in -f
--prune
Prune (delete) cluster resources not in input manifests
--server-side
Use server-side apply for more accurate diffs (Kubernetes 1.16+)
--dry-run=client|server
Dry-run mode; default client
-o, --output=go-template|json|yaml|name
Output format (default name)
--validate
Validate input with schema (default true)
-l, --selector string
Selector for resources to diff
-n, --namespace string
Target namespace (inherits from kubectl)
DESCRIPTION
kubectl-diff is a popular kubectl plugin that previews changes by comparing local Kubernetes manifests (YAML/JSON files) against the current cluster state. It simulates a server-side apply to show semantic differences, such as added, removed, or modified fields in resources like Deployments, Services, or ConfigMaps.
This prevents unintended changes during deployments. Output resembles git diff, highlighting patches with + for additions and - for removals. Supports directories, Kustomize overlays, recursive scanning, pruning unused resources, and output formats like YAML or JSON.
Ideal for CI/CD validation, PR reviews, or debugging drifts between desired and actual states without risking the cluster.
CAVEATS
Not a built-in kubectl command; requires plugin installation (e.g., via krew). Behavior varies by implementation. Server-side diffs need cluster support (v1.16+). May not handle all CRDs perfectly.
INSTALLATION
Via krew: kubectl krew install diff
Or download binary from GitHub releases and mv kubectl-diff /usr/local/bin/; chmod +x.
EXAMPLE
kubectl diff -f myapp/
Diffs all YAML in myapp/ directory.
kubectl diff -k overlays/prod -n production --server-side
Builds and diffs Kustomize overlay.
HISTORY
Emerged ~2018 as community plugins (e.g., replicatedhq/kubectl-diff, maorfr/kube-diff) to fill gap before native server-side dry-runs. Popularity surged with Kubernetes 1.16 server-side apply. Now installable via krew plugin diff; actively maintained in ecosystem.


