Kubectl apply

From NovaOrdis Knowledge Base
Revision as of 02:20, 26 February 2022 by Ovidiu (talk | contribs) (→‎Internal)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search



Apply a configuration to a resource by filename or stdin:

kubectl apply -f <manifest.yaml>
cat <manifest.yaml> | kubectl apply -f -

To apply all manifests from a directory:

kubectl apply -f ./dir


cat <<EOF | kubectl -n ${namespace} apply -f - 
apiVersion: v1
kind: Service
  name: something
  namespace: ${namespace}

The command can be used to both create a new resource or update the state of an existing resource. When updating the state, the command supports strategic merge patch.

Also see:

kubectl create

Namespace Handling

The resources specified by the manifest can be deployed in an arbitrary namespace with the -n <namespace> option, unless the manifest already specifies a different namespace in the metadata section. In that case, an error will ensue:

error: the namespace from the provided object "default" does not match the namespace "prometheus". You must pass '--namespace=default' to perform this operation.



The filename that contains the configuration to apply. "-" means it will take stdin and apply it.


Process a kustomization directory.