⎈ k8s knowledge compiler

kubectl patch [page]deterministic

Update fields of a resource

reference

##

Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch.

JSON and YAML formats are accepted.

Note: Strategic merge patch is not supported for custom resources.

``` kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE] ```

##

``` # Partially update a node using a strategic merge patch, specifying the patch as JSON kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}' # Partially update a node using a strategic merge patch, specifying the patch as YAML kubectl patch node k8s-node-1 -p $'spec:\n unschedulable: true' # Partially update a node identified by the type and name specified in "node.json" using strategic merge patch kubectl patch -f node.json -p '{"spec":{"unschedulable":true}}' # Update a container's image; spec.containers[*].name is required because it's a merge key kubectl patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}' # Update a container's image using a JSON patch with positional arrays kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' # Update a deployment's replicas through the 'scale' subresource using a merge patch kubectl patch deployment nginx-deployment --subresource='scale' --type='merge' -p '{"spec":{"replicas":2}}' ```

##

<table style="width: 100%; table-layout: fixed;"> <colgroup> <col span="1" style="width: 10px;" /> <col span="1" /> </colgroup> <tbody>

<tr> <td colspan="2">--allow-missing-template-keys&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default: true</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.</p></td> </tr>

<tr> <td colspan="2">--dry-run string[="unchanged"]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default: "none"</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Must be &quot;none&quot;, &quot;server&quot;, or &quot;client&quot;. If client strategy, only print the object that would be sent, without sending it. If server strategy, submit server-side request without persisting the resource.</p></td> </tr>

<tr> <td colspan="2">--field-manager string&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default: "kubectl-patch"</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Name of the manager used to track field ownership.</p></td> </tr>

<tr> <td colspan="2">-f, --filename strings</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Filename, directory, or URL to files identifying the resource to update</p></td> </tr>

<tr> <td colspan="2">-h, --help</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>help for patch</p></td> </tr>

<tr> <td colspan="2">-k, --kustomize string</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Process the kustomization directory. This flag can't be used together with -f or -R.</p></td> </tr>

<tr> <td colspan="2">--local</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>If true, patch will operate on the content of the file, not the server-side resource.</p></td> </tr>

<tr> <td colspan="2">-o, --output string</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Output format. One of: (json, yaml, kyaml, name, go-template, go-template-file, template, templatefile, jsonpath, jsonpath-as-json, jsonpath-file).</p></td> </tr>

<tr> <td colspan="2">-p, --patch string</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>The patch to be applied to the resource JSON file.</p></td> </tr>

<tr> <td colspan="2">--patch-file string</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>A file containing a patch to be a …(trimmed)

Sources

reference/kubectl/generated/kubectl_patch/_index.md · dockubectl patch

Related (6)

part_of {{% heading "synopsis" %}}describes conf=1
part_of {{% heading "examples" %}}describes conf=1
part_of {{% heading "options" %}}describes conf=1
part_of {{% heading "parentoptions" %}}describes conf=1
part_of {{% heading "seealso" %}}describes conf=1
api_for Patchdocuments API object conf=1

← all Docs