Kubectl apply: Difference between revisions
Jump to navigation
Jump to search
Line 10: | Line 10: | ||
Apply a configuration to a resource by filename or stdin: | Apply a configuration to a resource by filename or stdin: | ||
<syntaxhighlight lang='bash'> | |||
kubectl apply -f <manifest.yaml> | |||
</syntaxhighlight> | |||
<syntaxhighlight lang='bash'> | |||
cat <manifest.yaml> | kubectl apply -f - | |||
</syntaxhighlight> | |||
In-line: | |||
<syntaxhighlight lang='bash'> | |||
cat <<EOF | kubectl -n ${namespace} apply -f - | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
name: something | |||
namespace: ${namespace} | |||
spec: | |||
... | |||
EOF | |||
</syntaxhighlight> | |||
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 [[Kubernetes Strategic Merge Patch|strategic merge patch]]. | 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 [[Kubernetes Strategic Merge Patch|strategic merge patch]]. |
Revision as of 04:34, 14 October 2020
Internal
Overview
Apply a configuration to a resource by filename or stdin:
kubectl apply -f <manifest.yaml>
cat <manifest.yaml> | kubectl apply -f -
In-line:
cat <<EOF | kubectl -n ${namespace} apply -f -
apiVersion: v1
kind: Service
metadata:
name: something
namespace: ${namespace}
spec:
...
EOF
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:
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.
Options
-f|--filename
The filename that contains the configuration to apply.
-k|--kustomize
Process a kustomization directory.