Skip to content

Commit 49a2655

Browse files
authored
Merge pull request #32604 from nikhita/kubectl-subresource-support-docs
Document kubectl subresource support
2 parents 3fca29a + 73563a3 commit 49a2655

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

content/en/docs/reference/kubectl/cheatsheet.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ kubectl get pods -o json | jq -c 'paths|join(".")'
230230
# Produce ENV for all pods, assuming you have a default container for the pods, default namespace and the `env` command is supported.
231231
# Helpful when running any supported command across all pods, not just `env`
232232
for pod in $(kubectl get po --output=jsonpath={.items..metadata.name}); do echo $pod && kubectl exec -it $pod -- env; done
233+
234+
# Get a deployment's status subresource
235+
kubectl get deployment nginx-deployment --subresource=status
233236
```
234237

235238
## Updating resources
@@ -276,6 +279,9 @@ kubectl patch deployment valid-deployment --type json -p='[{"op": "remove", "
276279

277280
# Add a new element to a positional array
278281
kubectl patch sa default --type='json' -p='[{"op": "add", "path": "/secrets/1", "value": {"name": "whatever" } }]'
282+
283+
# Update a deployment's replicas count by patching it's scale subresource
284+
kubectl patch deployment nginx-deployment --subresource='scale' --type='merge' -p '{"spec":{"replicas":2}}'
279285
```
280286

281287
## Editing resources

content/en/docs/reference/kubectl/conventions.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ For a stable output in a script:
1919
* Fully-qualify the version. For example, `jobs.v1.batch/myjob`. This will ensure that kubectl does not use its default version that can change over time.
2020
* Don't rely on context, preferences, or other implicit states.
2121

22+
## Subresources
23+
24+
* You can use the `--subresource` alpha flag for kubectl commands like `get`, `patch`,
25+
`edit` and `replace` to fetch and update subresources for all resources that
26+
support them. Currently, only the `status` and `scale` subresources are supported.
27+
* The API contract against a subresource is identical to a full resource. While updating the
28+
`status` subresource to a new value, keep in mind that the subresource could be potentially
29+
reconciled by a controller to a different value.
30+
31+
2232
## Best Practices
2333

2434
### `kubectl run`

0 commit comments

Comments
 (0)