kubectl-plugins

clone

Create a copy of a resource with the same values.

Install kubectl-clone
curl -fsSL https://kubectl-plugins.dev/install.sh | sh -s -- clone
Download a binary insteadmacOS (Apple silicon) · macOS (Intel) · Linux (amd64) · Linux (arm64) · Windows (amd64)
Put the binary on your PATH as kubectl-clone, or build from source.
kubectl clone RESOURCE NAME [NEW_NAME] [-n NAMESPACE] [--to-namespace NAMESPACE] [--dry-run]

Copies any resource type (plural, singular, short name or resource.group) under a new name, a new namespace, or both. kubectl cp is built in to kubectl (it copies files to and from pods), so this plugin is named clone.

Server-populated fields (uid, resourceVersion, managedFields, ownerReferences, status, the last-applied annotation) are dropped, along with values that must be unique: a Service’s clusterIP(s), a Pod’s nodeName and a PVC’s volumeName. The copy never overwrites the source: give a new name or --to-namespace.

Flags

FlagDescription
-n, --namespaceNamespace of the source (default: current context namespace)
--to-namespaceNamespace for the copy (default: the source namespace)
--dry-runValidate server-side without creating the copy

Examples

kubectl clone deployment web web-copy
kubectl clone configmap app-config --to-namespace staging
kubectl clone secret db-creds db-creds-v2 -n prod --to-namespace staging