Skip to content

Commit c531c05

Browse files
authored
Merge pull request #38399 from windsonsea/cheaty
[zh] sync /kubectl/cheatsheet.md
2 parents 9306717 + 65e28e3 commit c531c05

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

content/zh-cn/docs/reference/kubectl/cheatsheet.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ card:
66
name: reference
77
weight: 30
88
---
9-
<!-- ---
9+
<!--
1010
title: kubectl Cheat Sheet
1111
reviewers:
1212
- erictune
@@ -17,7 +17,6 @@ weight: 10 # highlight it
1717
card:
1818
name: reference
1919
weight: 30
20-
---
2120
-->
2221

2322
<!-- overview -->
@@ -35,7 +34,6 @@ This page contains a list of commonly used `kubectl` commands and flags.
3534
3635
### BASH
3736
-->
38-
3937
## Kubectl 自动补全 {#kubectl-autocomplete}
4038

4139
### BASH
@@ -79,7 +77,7 @@ echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc
7977
### 关于 `--all-namespaces` 的一点说明 {#a-note-on-all-namespaces}
8078

8179
<!--
82-
Appending `--all-namespaces` happens frequently enough where you should be aware of the shorthand for `--all-namespaces`:
80+
Appending `--all-namespaces` happens frequently enough where you should be aware of the shorthand for `--all-namespaces`:
8381
-->
8482
我们经常用到 `--all-namespaces` 参数,你应该要知道它的简写:
8583

@@ -385,6 +383,9 @@ kubectl get pods --all-namespaces -o jsonpath='{range .items[*].status.initConta
385383
# List Events sorted by timestamp
386384
kubectl get events --sort-by=.metadata.creationTimestamp
387385
386+
# List all warning events
387+
kubectl events --types=Warning
388+
388389
# Compares the current state of the cluster against the state that the cluster would be in if the manifest was applied.
389390
kubectl diff -f ./my-manifest.yaml
390391
@@ -470,6 +471,9 @@ kubectl get pods --all-namespaces -o jsonpath='{range .items[*].status.initConta
470471
# 列出事件(Events),按时间戳排序
471472
kubectl get events --sort-by=.metadata.creationTimestamp
472473

474+
# 列出所有警告事件
475+
kubectl events --types=Warning
476+
473477
# 比较当前的集群状态和假定某清单被应用之后的集群状态
474478
kubectl diff -f ./my-manifest.yaml
475479

@@ -566,7 +570,7 @@ kubectl patch deployment valid-deployment --type json -p='[{"op": "remove", "
566570
# Add a new element to a positional array
567571
kubectl patch sa default --type='json' -p='[{"op": "add", "path": "/secrets/1", "value": {"name": "whatever" } }]'
568572
569-
# Update a deployment's replica count by patching it's scale subresource
573+
# Update a deployment's replica count by patching its scale subresource
570574
kubectl patch deployment nginx-deployment --subresource='scale' --type='merge' -p '{"spec":{"replicas":2}}'
571575
```
572576
-->
@@ -638,6 +642,7 @@ kubectl scale --replicas=5 rc/foo rc/bar rc/baz # 伸缩多个
638642
<!--
639643
```bash
640644
kubectl delete -f ./pod.json # Delete a pod using the type and name specified in pod.json
645+
kubectl delete pod unwanted --now # Delete a pod with no grace period
641646
kubectl delete pod,service baz foo # Delete pods and services with same names "baz" and "foo"
642647
kubectl delete pods,services -l name=myLabel # Delete pods and services with label name=myLabel
643648
kubectl -n my-ns delete pod,svc --all # Delete all pods and services in namespace my-ns,
@@ -647,6 +652,7 @@ kubectl get pods -n mynamespace --no-headers=true | awk '/pattern1|pattern2/{pr
647652
-->
648653
```bash
649654
kubectl delete -f ./pod.json # 删除在 pod.json 中指定的类型和名称的 Pod
655+
kubectl delete pod unwanted --now # 删除 Pod 且无宽限期限(无优雅时段)
650656
kubectl delete pod,service baz foo # 删除名称为 "baz" 和 "foo" 的 Pod 和服务
651657
kubectl delete pods,services -l name=myLabel # 删除包含 name=myLabel 标签的 pods 和服务
652658
kubectl -n my-ns delete pod,svc --all # 删除在 my-ns 名字空间中全部的 Pods 和服务
@@ -860,7 +866,7 @@ To output details to your terminal window in a specific format, add the `-o` (or
860866

861867
要以特定格式将详细信息输出到终端窗口,将 `-o`(或者 `--output`)参数添加到支持的 `kubectl` 命令中。
862868

863-
<!--O
869+
<!--
864870
Output format | Description
865871
--------------| -----------
866872
`-o=custom-columns=<spec>` | Print a table using a comma separated list of custom columns
@@ -898,8 +904,6 @@ kubectl get pods -A -o=custom-columns='DATA:spec.containers[?(@.image!="registry
898904
899905
# All fields under metadata regardless of name
900906
kubectl get pods -A -o=custom-columns='DATA:metadata.*'
901-
902-
More examples in the kubectl [reference documentation](/docs/reference/kubectl/#custom-columns).
903907
```
904908
-->
905909
使用 `-o=custom-columns` 的示例:

0 commit comments

Comments
 (0)