Skip to content

Commit 20aaa90

Browse files
committed
[zh-cn]sync quick-reference node/_index
Signed-off-by: xin.li <[email protected]>
1 parent 6f25a21 commit 20aaa90

2 files changed

Lines changed: 48 additions & 52 deletions

File tree

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

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ This page contains a list of commonly used `kubectl` commands and flags.
3030
<!--
3131
These instructions are for Kubernetes v{{< skew currentVersion >}}. To check the version, use the `kubectl version` command.
3232
-->
33-
这些指令适用于 Kubernetes v{{< skew currentVersion >}}。要检查版本,请使用 `kubectl version` 命令。
33+
这些指令适用于 Kubernetes v{{< skew currentVersion >}}。
34+
要检查版本,请使用 `kubectl version` 命令。
3435
{{< /note >}}
3536

3637
<!-- body -->
3738

3839
<!--
3940
## Kubectl autocomplete
40-
41-
### BASH
4241
-->
4342
## kubectl 自动补全 {#kubectl-autocomplete}
4443

@@ -53,8 +52,8 @@ echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permane
5352
You can also use a shorthand alias for `kubectl` that also works with completion:
5453
-->
5554
```bash
56-
source <(kubectl completion bash) # bash 中设置当前 shell 的自动补全,要先安装 bash-completion
57-
echo "source <(kubectl completion bash)" >> ~/.bashrc # 在你的 bash shell 中永久地添加自动补全
55+
source <(kubectl completion bash) # 要在 bash 中设置 shell 的自动补全,需要先安装 bash-completion 软件包
56+
echo "source <(kubectl completion bash)" >> ~/.bashrc # 为你的 bash shell 永久添加自动补全功能
5857
```
5958

6059
你还可以在补全时为 `kubectl` 使用一个速记别名:
@@ -73,7 +72,7 @@ echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc
7372
```
7473
-->
7574
```bash
76-
source <(kubectl completion zsh) # 在 zsh 中设置当前 shell 的自动补全
75+
source <(kubectl completion zsh) # 在 zsh 中设置自动补全到当前 shell
7776
echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc # 在你的 zsh shell 中永久地添加自动补全
7877
```
7978

@@ -100,7 +99,9 @@ Appending `--all-namespaces` happens frequently enough that you should be aware
10099
-->
101100
我们经常用到 `--all-namespaces` 参数,你应该要知道它的简写:
102101

103-
```kubectl -A```
102+
```
103+
kubectl -A
104+
```
104105

105106
<!--
106107
## Kubectl context and configuration
@@ -295,11 +296,11 @@ kubectl apply -f ./dir # 基于目录下的所有
295296
kubectl apply -f https://example.com/manifest.yaml # 从 URL 中创建资源(注意:这是一个示例域名,不包含有效的清单)
296297
kubectl create deployment nginx --image=nginx # 启动单实例 nginx
297298

298-
# 创建一个打印 Hello World 的 Job
299+
# 创建一个打印 "Hello World" 的 Job
299300
kubectl create job hello --image=busybox:1.28 -- echo "Hello World"
300301

301-
# 创建一个打印 Hello World 间隔 1 分钟的 CronJob
302-
kubectl create cronjob hello --image=busybox:1.28 --schedule="*/1 * * * *" -- echo "Hello World"
302+
# 创建一个打印 "Hello World" 间隔 1 分钟的 CronJob
303+
kubectl create cronjob hello --image=busybox:1.28 --schedule="*/1 * * * *" -- echo "Hello World"
303304

304305
kubectl explain pods # 获取 Pod 清单的文档说明
305306

@@ -463,11 +464,11 @@ kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
463464
# 列举所有 PV 持久卷,按容量排序
464465
kubectl get pv --sort-by=.spec.capacity.storage
465466

466-
# 获取包含 app=cassandra 标签的所有 Pod 的 version 标签
467+
# 获取包含 "app=cassandra" 标签的所有 Pod 的 version 标签
467468
kubectl get pods --selector=app=cassandra -o \
468469
jsonpath='{.items[*].metadata.labels.version}'
469470

470-
# 检索带有 “.” 键值,例如 'ca.crt'
471+
# 检索带有 "." 键值,例如 'ca.crt'
471472
kubectl get configmap myconfig \
472473
-o jsonpath='{.data.ca\.crt}'
473474

@@ -518,7 +519,7 @@ kubectl events --types=Warning
518519
kubectl diff -f ./my-manifest.yaml
519520

520521
# 生成一个句点分隔的树,其中包含为节点返回的所有键
521-
# 在复杂的嵌套JSON结构中定位键时非常有用
522+
# 在复杂的嵌套 JSON 结构中定位键时非常有用
522523
kubectl get nodes -o json | jq -c 'paths|join(".")'
523524

524525
# 生成一个句点分隔的树,其中包含为 Pod 等返回的所有键
@@ -578,7 +579,7 @@ cat pod.json | kubectl replace -f - # 通过传入
578579
# 强制替换,删除后重建资源。会导致服务不可用。
579580
kubectl replace --force -f ./pod.json
580581

581-
# 为多副本的 nginx 创建服务,使用 80 端口提供服务,连接到容器的 8000 端口
582+
# 为多副本的 nginx 创建 Service,使用 80 端口提供服务,连接到容器的 8000 端口
582583
kubectl expose rc nginx --port=80 --target-port=8000
583584

584585
# 将某单容器 Pod 的镜像版本(标签)更新到 v4
@@ -609,7 +610,7 @@ kubectl patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve
609610
kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'
610611
611612
# Disable a deployment livenessProbe using a json patch with positional arrays
612-
kubectl patch deployment valid-deployment --type json -p='[{"op": "remove", "path": "/spec/template/spec/containers/0/livenessProbe"}]'
613+
kubectl patch deployment valid-deployment --type json -p='[{"op": "remove", "path": "/spec/template/spec/containers/0/livenessProbe"}]'
613614
614615
# Add a new element to a positional array
615616
kubectl patch sa default --type='json' -p='[{"op": "add", "path": "/secrets/1", "value": {"name": "whatever" } }]'
@@ -622,14 +623,14 @@ kubectl patch deployment nginx-deployment --subresource='scale' --type='merge' -
622623
# 部分更新某节点
623624
kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'
624625

625-
# 更新容器的镜像;spec.containers[*].name 是必需的。因为它是一个合并性质的主键。
626+
# 更新容器的镜像;"spec.containers[*].name" 是必需的。因为它是一个合并性质的主键。
626627
kubectl patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}'
627628

628629
# 使用带位置数组的 JSON patch 更新容器的镜像
629630
kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'
630631

631632
# 使用带位置数组的 JSON patch 禁用某 Deployment 的 livenessProbe
632-
kubectl patch deployment valid-deployment --type json -p='[{"op": "remove", "path": "/spec/template/spec/containers/0/livenessProbe"}]'
633+
kubectl patch deployment valid-deployment --type json -p='[{"op": "remove", "path": "/spec/template/spec/containers/0/livenessProbe"}]'
633634

634635
# 在带位置数组中添加元素
635636
kubectl patch sa default --type='json' -p='[{"op": "add", "path": "/secrets/1", "value": {"name": "whatever" } }]'
@@ -654,7 +655,7 @@ KUBE_EDITOR="nano" kubectl edit svc/docker-registry # Use an alternative edito
654655
```
655656
-->
656657
```bash
657-
kubectl edit svc/docker-registry # 编辑名为 docker-registry 的服务
658+
kubectl edit svc/docker-registry # 编辑名为 docker-registry 的 Service
658659
KUBE_EDITOR="nano" kubectl edit svc/docker-registry # 使用其他编辑器
659660
```
660661

@@ -691,17 +692,17 @@ kubectl delete pod,service baz foo # Delete pods
691692
kubectl delete pods,services -l name=myLabel # Delete pods and services with label name=myLabel
692693
kubectl -n my-ns delete pod,svc --all # Delete all pods and services in namespace my-ns,
693694
# Delete all pods matching the awk pattern1 or pattern2
694-
kubectl get pods -n mynamespace --no-headers=true | awk '/pattern1|pattern2/{print $1}' | xargs kubectl delete -n mynamespace pod
695+
kubectl get pods -n mynamespace --no-headers=true | awk '/pattern1|pattern2/{print $1}' | xargs kubectl delete -n mynamespace pod
695696
```
696697
-->
697698
```bash
698-
kubectl delete -f ./pod.json # 删除在 pod.json 中指定的类型和名称的 Pod
699+
kubectl delete -f ./pod.json # 删除在 "pod.json" 中指定的类型和名称的 Pod
699700
kubectl delete pod unwanted --now # 删除 Pod 且无宽限期限(无优雅时段)
700-
kubectl delete pod,service baz foo # 删除名称为 "baz" 和 "foo" 的 Pod 和服务
701-
kubectl delete pods,services -l name=myLabel # 删除包含 name=myLabel 标签的 Pod 和服务
702-
kubectl -n my-ns delete pod,svc --all # 删除在 my-ns 名字空间中全部的 Pod 和服务
701+
kubectl delete pod,service baz foo # 删除名称为 "baz" 和 "foo" 的 Pod 和 Service
702+
kubectl delete pods,services -l name=myLabel # 删除包含 "name=myLabel" 标签的 Pod 和 Service
703+
kubectl -n my-ns delete pod,svc --all # 删除在 my-ns 名字空间中全部的 Pod 和 Service
703704
# 删除所有与 pattern1 或 pattern2 awk 模式匹配的 Pod
704-
kubectl get pods -n mynamespace --no-headers=true | awk '/pattern1|pattern2/{print $1}' | xargs kubectl delete -n mynamespace pod
705+
kubectl get pods -n mynamespace --no-headers=true | awk '/pattern1|pattern2/{print $1}' | xargs kubectl delete -n mynamespace pod
705706
```
706707

707708
<!--
@@ -738,19 +739,18 @@ kubectl top pod POD_NAME --sort-by=cpu # Show metrics for a given p
738739
-->
739740
```bash
740741
kubectl logs my-pod # 获取 Pod 日志(标准输出)
741-
kubectl logs -l name=myLabel # 获取含 name=myLabel 标签的 Pod 的日志(标准输出)
742+
kubectl logs -l name=myLabel # 获取含 "name=myLabel" 标签的 Pod 的日志(标准输出)
742743
kubectl logs my-pod --previous # 获取上个容器实例的 Pod 日志(标准输出)
743-
kubectl logs my-pod -c my-container # 获取 Pod 容器的日志(标准输出, 多容器场景)
744-
kubectl logs -l name=myLabel -c my-container # 获取含 name=myLabel 标签的 Pod 容器日志(标准输出, 多容器场景)
745-
kubectl logs my-pod -c my-container --previous # 获取 Pod 中某容器的上个实例的日志(标准输出, 多容器场景)
744+
kubectl logs my-pod -c my-container # 获取 Pod 容器的日志(标准输出多容器场景)
745+
kubectl logs -l name=myLabel -c my-container # 获取含 "name=myLabel" 标签的 Pod 容器日志(标准输出多容器场景)
746+
kubectl logs my-pod -c my-container --previous # 获取 Pod 中某容器的上个实例的日志(标准输出多容器场景)
746747
kubectl logs -f my-pod # 流式输出 Pod 的日志(标准输出)
747-
kubectl logs -f my-pod -c my-container # 流式输出 Pod 容器的日志(标准输出, 多容器场景)
748-
kubectl logs -f -l name=myLabel --all-containers # 流式输出含 name=myLabel 标签的 Pod 的所有日志(标准输出)
748+
kubectl logs -f my-pod -c my-container # 流式输出 Pod 容器的日志(标准输出多容器场景)
749+
kubectl logs -f -l name=myLabel --all-containers # 流式输出含 "name=myLabel" 标签的 Pod 的所有日志(标准输出)
749750
kubectl run -i --tty busybox --image=busybox:1.28 -- sh # 以交互式 Shell 运行 Pod
750-
kubectl run nginx --image=nginx -n mynamespace #mynamespace 命名空间中运行单个 nginx Pod
751+
kubectl run nginx --image=nginx -n mynamespace #"mynamespace" 命名空间中运行单个 nginx Pod
751752
kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml
752-
# 为运行 nginx Pod 生成规约并将其写入到名为 pod.yaml 的文件
753-
753+
# 为运行 nginx Pod 生成规约并将其写入到名为 "pod.yaml" 的文件
754754
kubectl attach my-pod -i # 挂接到一个运行的容器中
755755
kubectl port-forward my-pod 5000:6000 # 在本地计算机上侦听端口 5000 并转发到 my-pod 上的端口 6000
756756
kubectl exec my-pod -- ls / # 在已有的 Pod 中运行命令(单容器场景)
@@ -777,10 +777,10 @@ kubectl cp my-namespace/my-pod:/tmp/foo /tmp/bar # Copy /tmp/foo from a re
777777
```
778778
-->
779779
```bash
780-
kubectl cp /tmp/foo_dir my-pod:/tmp/bar_dir # 将 /tmp/foo_dir 本地目录复制到远程当前命名空间中 Pod 中的 /tmp/bar_dir
781-
kubectl cp /tmp/foo my-pod:/tmp/bar -c my-container # 将 /tmp/foo 本地文件复制到远程 Pod 中特定容器的 /tmp/bar 下
782-
kubectl cp /tmp/foo my-namespace/my-pod:/tmp/bar # 将 /tmp/foo 本地文件复制到远程 my-namespace 命名空间内指定 Pod 中的 /tmp/bar
783-
kubectl cp my-namespace/my-pod:/tmp/foo /tmp/bar # 将 /tmp/foo 从远程 Pod 复制到本地 /tmp/bar
780+
kubectl cp /tmp/foo_dir my-pod:/tmp/bar_dir #"/tmp/foo_dir" 本地目录复制到远程当前命名空间中 Pod 中的 "/tmp/bar_dir"
781+
kubectl cp /tmp/foo my-pod:/tmp/bar -c my-container #"/tmp/foo" 本地文件复制到远程 Pod 中特定容器的 "/tmp/bar"
782+
kubectl cp /tmp/foo my-namespace/my-pod:/tmp/bar #"/tmp/foo" 本地文件复制到远程 "my-namespace" 命名空间内指定 Pod 中的 "/tmp/bar"
783+
kubectl cp my-namespace/my-pod:/tmp/foo /tmp/bar #"/tmp/foo" 从远程 Pod 复制到本地 "/tmp/bar"
784784
```
785785

786786
{{< note >}}
@@ -799,8 +799,8 @@ kubectl exec -n my-namespace my-pod -- tar cf - /tmp/foo | tar xf - -C /tmp/bar
799799
```
800800
-->
801801
```bash
802-
tar cf - /tmp/foo | kubectl exec -i -n my-namespace my-pod -- tar xf - -C /tmp/bar # 将 /tmp/foo 本地文件复制到远程 my-namespace 命名空间中 Pod 中的 /tmp/bar
803-
kubectl exec -n my-namespace my-pod -- tar cf - /tmp/foo | tar xf - -C /tmp/bar # 将 /tmp/foo 从远程 Pod 复制到本地 /tmp/bar
802+
tar cf - /tmp/foo | kubectl exec -i -n my-namespace my-pod -- tar xf - -C /tmp/bar #"/tmp/foo" 本地文件复制到远程 "my-namespace" 命名空间中 Pod 中的 "/tmp/bar"
803+
kubectl exec -n my-namespace my-pod -- tar cf - /tmp/foo | tar xf - -C /tmp/bar #"/tmp/foo" 从远程 Pod 复制到本地 "/tmp/bar"
804804
```
805805

806806
<!--
@@ -825,9 +825,9 @@ kubectl logs deploy/my-deployment # 获取一个 Deploym
825825
kubectl logs deploy/my-deployment -c my-container # 获取一个 Deployment 的 Pod 的日志(多容器例子)
826826

827827
kubectl port-forward svc/my-service 5000 # 侦听本地端口 5000 并转发到 Service 后端端口 5000
828-
kubectl port-forward svc/my-service 5000:my-service-port # 侦听本地端口 5000 并转发到名字为 <my-service-port> 的 Service 目标端口
828+
kubectl port-forward svc/my-service 5000:my-service-port # 侦听本地端口 5000 并转发到名字为 "<my-service-port>" 的 Service 目标端口
829829

830-
kubectl port-forward deploy/my-deployment 5000:6000 # 侦听本地端口 5000 并转发到 <my-deployment> 创建的 Pod 里的端口 6000
830+
kubectl port-forward deploy/my-deployment 5000:6000 # 侦听本地端口 5000 并转发到 "<my-deployment>" 创建的 Pod 里的端口 6000
831831
kubectl exec deploy/my-deployment -- ls # 在 Deployment 里的第一个 Pod 的第一个容器里运行命令(单容器和多容器例子)
832832
```
833833

@@ -862,7 +862,7 @@ kubectl top node # 显示
862862
kubectl top node my-node # 显示给定节点的度量值
863863
kubectl cluster-info # 显示主控节点和服务的地址
864864
kubectl cluster-info dump # 将当前集群状态转储到标准输出
865-
kubectl cluster-info dump --output-directory=/path/to/cluster-state # 将当前集群状态输出到 /path/to/cluster-state
865+
kubectl cluster-info dump --output-directory=/path/to/cluster-state # 将当前集群状态输出到 "/path/to/cluster-state"
866866

867867
# 查看当前节点上存在的现有污点
868868
kubectl get nodes -o='custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect'
@@ -991,13 +991,13 @@ More examples in the kubectl [reference documentation](/docs/reference/kubectl/#
991991
<!--
992992
### Kubectl output verbosity and debugging
993993
994-
Kubectl verbosity is controlled with the `-v` or `--v` flags followed by an integer representing the log level. General Kubernetes logging conventions and the associated log levels are described [here](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md).
994+
Kubectl verbosity is controlled with the `-v` or `--v` flags followed by an integer representing the log level. General Kubernetes logging conventions and the associated log levels are described [here](https://github.com/kubernetes/community/blob/main/contributors/devel/sig-instrumentation/logging.md).
995995
-->
996996
### kubectl 日志输出详细程度和调试 {#kubectl-output-verbosity-and-debugging}
997997

998998
kubectl 日志输出详细程度是通过 `-v` 或者 `--v` 来控制的,参数后跟一个数字表示日志的级别。
999999
Kubernetes 通用的日志习惯和相关的日志级别在
1000-
[这里](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md)有相应的描述。
1000+
[这里](https://github.com/kubernetes/community/blob/main/contributors/devel/sig-instrumentation/logging.md)有相应的描述。
10011001

10021002
<!--
10031003
Verbosity | Description
@@ -1015,7 +1015,7 @@ Verbosity | Description
10151015
-->
10161016
详细程度 | 描述
10171017
--------| -----------
1018-
`--v=0` | 用于那些应该 **始终** 对运维人员可见的信息,因为这些信息一般很有用。
1018+
`--v=0` | 用于那些应该**始终**对运维人员可见的信息,因为这些信息一般很有用。
10191019
`--v=1` | 如果你不想要看到冗余信息,此值是一个合理的默认日志级别。
10201020
`--v=2` | 输出有关服务的稳定状态的信息以及重要的日志消息,这些信息可能与系统中的重大变化有关。这是建议大多数系统设置的默认日志级别。
10211021
`--v=3` | 包含有关系统状态变化的扩展信息。

content/zh-cn/docs/reference/node/_index.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ no_list: true
1313
<!--
1414
This section contains the following reference topics about nodes:
1515
16+
* the kubelet's [sync loop](/docs/reference/node/kubelet-sync-loop/)
17+
1618
* the kubelet's [checkpoint API](/docs/reference/node/kubelet-checkpoint-api/)
1719
* a list of [Articles on dockershim Removal and on Using CRI-compatible Runtimes](/docs/reference/node/topics-on-dockershim-and-cri-compatible-runtimes/)
1820
@@ -30,20 +32,14 @@ This section contains the following reference topics about nodes:
3032
-->
3133
本部分包含以下有关节点的参考主题:
3234

35+
* kubelet 的[同步循环](/zh-cn/docs/reference/node/kubelet-sync-loop/)
3336
* kubelet 的 [Checkpoint API](/zh-cn/docs/reference/node/kubelet-checkpoint-api/)
34-
3537
* 一系列[关于 dockershim 移除和使用兼容 CRI 运行时的文章](/zh-cn/docs/reference/node/topics-on-dockershim-and-cri-compatible-runtimes/)
36-
3738
* [kubelet 设备管理器 API 版本](/zh-cn/docs/reference/node/device-plugin-api-versions)
38-
3939
* [由 kubelet 填充的节点标签](/zh-cn/docs/reference/node/node-labels)
40-
4140
* [由 kubelet 使用的本地文件和路径](/zh-cn/docs/reference/node/kubelet-files)
42-
4341
* [节点 `.status` 信息](/zh-cn/docs/reference/node/node-status/)
44-
4542
* [Linux 节点的交换(Swap)行为](/zh-cn/docs/reference/node/swap-behavior/)
46-
4743
* [Seccomp 信息](/zh-cn/docs/reference/node/seccomp/)
4844

4945
<!--

0 commit comments

Comments
 (0)