Skip to content

Commit bb2d809

Browse files
authored
Merge pull request #37569 from windsonsea/cheats
[zh] sync cheatsheet.md
2 parents 535d52e + 2fc98fb commit bb2d809

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

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

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This page contains a list of commonly used `kubectl` commands and flags.
3636
### BASH
3737
-->
3838

39-
## Kubectl 自动补全
39+
## Kubectl 自动补全 {#kubectl-autocomplete}
4040

4141
### BASH
4242

@@ -76,7 +76,7 @@ echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc
7676
<!--
7777
### A Note on --all-namespaces
7878
-->
79-
### 关于 --all-namespaces 的一点说明
79+
### 关于 --all-namespaces 的一点说明 {#a-note-on-all-namespaces}
8080

8181
<!--
8282
Appending `--all-namespaces` happens frequently enough where you should be aware of the shorthand for `--all-namespaces`:
@@ -92,7 +92,7 @@ Set which Kubernetes cluster `kubectl` communicates with and modifies configurat
9292
information. See [Authenticating Across Clusters with kubeconfig](/docs/tasks/access-application-cluster/configure-access-multiple-clusters/) documentation for
9393
detailed config file information.
9494
-->
95-
## Kubectl 上下文和配置
95+
## Kubectl 上下文和配置 {#kubectl-context-and-configuration}
9696

9797
设置 `kubectl` 与哪个 Kubernetes 集群进行通信并修改配置信息。
9898
查看[使用 kubeconfig 跨集群授权访问](/zh-cn/docs/tasks/access-application-cluster/configure-access-multiple-clusters/)
@@ -314,7 +314,7 @@ EOF
314314
<!--
315315
## Viewing, finding resources
316316
-->
317-
## 查看和查找资源
317+
## 查看和查找资源 {#viewing-finding-resources}
318318

319319
<!--
320320
```bash
@@ -491,7 +491,7 @@ kubectl get deployment nginx-deployment --subresource=status
491491
<!--
492492
## Updating resources
493493
-->
494-
## 更新资源
494+
## 更新资源 {#updating-resources}
495495

496496
<!--
497497
```bash
@@ -542,8 +542,10 @@ kubectl annotate pods my-pod icon-url=http://goo.gl/XXBTWq # 添加注解
542542
kubectl autoscale deployment foo --min=2 --max=10 # 对 "foo" Deployment 自动伸缩容
543543
```
544544

545-
<!-- ## Patching resources -->
546-
## 部分更新资源
545+
<!--
546+
## Patching resources
547+
-->
548+
## 部分更新资源 {#patching-resources}
547549

548550
<!--
549551
```bash
@@ -591,7 +593,7 @@ kubectl patch deployment nginx-deployment --subresource='scale' --type='merge' -
591593
592594
Edit any API resource in your preferred editor.
593595
-->
594-
## 编辑资源
596+
## 编辑资源 {#editing-resources}
595597

596598
使用你偏爱的编辑器编辑 API 资源。
597599

@@ -609,9 +611,10 @@ KUBE_EDITOR="nano" kubectl edit svc/docker-registry # 使用其他编辑器
609611
<!--
610612
## Scaling resources
611613
-->
612-
## 对资源进行伸缩
614+
## 对资源进行伸缩 {#scaling-resources}
613615

614-
<!-- ```bash
616+
<!--
617+
```bash
615618
kubectl scale --replicas=3 rs/foo # Scale a replicaset named 'foo' to 3
616619
kubectl scale --replicas=3 -f foo.yaml # Scale a resource specified in "foo.yaml" to 3
617620
kubectl scale --current-replicas=2 --replicas=3 deployment/mysql # If the deployment named mysql's current size is 2, scale mysql to 3
@@ -628,9 +631,10 @@ kubectl scale --replicas=5 rc/foo rc/bar rc/baz # 伸缩多个
628631
<!--
629632
## Deleting resources
630633
-->
631-
## 删除资源
634+
## 删除资源 {#deleting-resources}
632635

633-
<!-- ```bash
636+
<!--
637+
```bash
634638
kubectl delete -f ./pod.json # Delete a pod using the type and name specified in pod.json
635639
kubectl delete pod,service baz foo # Delete pods and services with same names "baz" and "foo"
636640
kubectl delete pods,services -l name=myLabel # Delete pods and services with label name=myLabel
@@ -651,7 +655,7 @@ kubectl get pods -n mynamespace --no-headers=true | awk '/pattern1|pattern2/{pr
651655
<!--
652656
## Interacting with running Pods
653657
-->
654-
## 与运行中的 Pod 进行交互
658+
## 与运行中的 Pod 进行交互 {#interacting-with-running-pods}
655659

656660
<!--
657661
```bash
@@ -705,7 +709,7 @@ kubectl top pod POD_NAME --sort-by=cpu # 显示给定 Pod 的指标
705709
<!--
706710
## Copy files and directories to and from containers
707711
-->
708-
## 从容器中复制文件和目录
712+
## 从容器中复制文件和目录 {#copy-files-and-directories-to-and-from-containers}
709713

710714
<!--
711715
```bash
@@ -722,11 +726,11 @@ kubectl cp /tmp/foo my-namespace/my-pod:/tmp/bar # 将 /tmp/foo 本地文
722726
kubectl cp my-namespace/my-pod:/tmp/foo /tmp/bar # 将 /tmp/foo 从远程 Pod 复制到本地 /tmp/bar
723727
```
724728

729+
{{< note >}}
725730
<!--
726731
`kubectl cp` requires that the 'tar' binary is present in your container image. If 'tar' is not present,`kubectl cp` will fail.
727732
For advanced use cases, such as symlinks, wildcard expansion or file mode preservation consider using `kubectl exec`.
728733
-->
729-
{{< note >}}
730734
`kubectl cp` 要求容器镜像中存在 “tar” 二进制文件。如果 “tar” 不存在,`kubectl cp` 将失败。
731735
对于进阶用例,例如符号链接、通配符扩展或保留文件权限,请考虑使用 `kubectl exec`
732736
{{< /note >}}
@@ -745,7 +749,7 @@ kubectl exec -n my-namespace my-pod -- tar cf - /tmp/foo | tar xf - -C /tmp/bar
745749
<!--
746750
## Interacting with Deployments and Services
747751
-->
748-
## 与 Deployments 和 Services 进行交互
752+
## 与 Deployments 和 Services 进行交互 {#interacting-with-deployments-and-services}
749753

750754
<!--
751755
```bash
@@ -773,7 +777,7 @@ kubectl exec deploy/my-deployment -- ls # 在 Deployment 里
773777
<!--
774778
## Interacting with Nodes and cluster
775779
-->
776-
## 与节点和集群进行交互
780+
## 与节点和集群进行交互 {#interacting-with-nodes-and-cluster}
777781

778782
<!--
779783
```bash
@@ -786,7 +790,7 @@ kubectl cluster-info dump # Dump cur
786790
kubectl cluster-info dump --output-directory=/path/to/cluster-state # Dump current cluster state to /path/to/cluster-state
787791
788792
# View existing taints on which exist on current nodes.
789-
kubectl get nodes -o=custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect
793+
kubectl get nodes -o='custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect'
790794
791795
# If a taint with that key and effect already exists, its value is replaced as specified.
792796
kubectl taint nodes foo dedicated=special-user:NoSchedule
@@ -802,7 +806,7 @@ kubectl cluster-info dump # 将当
802806
kubectl cluster-info dump --output-directory=/path/to/cluster-state # 将当前集群状态输出到 /path/to/cluster-state
803807

804808
# 查看当前节点上存在的现有污点。
805-
kubectl get nodes -o=custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect
809+
kubectl get nodes -o='custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect'
806810

807811
# 如果已存在具有指定键和效果的污点,则替换其值为指定值。
808812
kubectl taint nodes foo dedicated=special-user:NoSchedule
@@ -811,7 +815,7 @@ kubectl taint nodes foo dedicated=special-user:NoSchedule
811815
<!--
812816
### Resource types
813817
-->
814-
### 资源类型
818+
### 资源类型 {#resource-types}
815819

816820
<!--
817821
List all supported resource types along with their shortnames, [API group](/docs/concepts/overview/kubernetes-api/#api-groups-and-versioning), whether they are [namespaced](/docs/concepts/overview/working-with-objects/namespaces), and [Kind](/docs/concepts/overview/working-with-objects/kubernetes-objects):
@@ -851,7 +855,7 @@ kubectl api-resources --api-group=extensions # "extensions" API 组中的所有
851855
852856
To output details to your terminal window in a specific format, add the `-o` (or `--output`) flag to a supported `kubectl` command.
853857
-->
854-
### 格式化输出
858+
### 格式化输出 {#formatting-output}
855859

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

@@ -891,7 +895,6 @@ kubectl get pods --namespace default --output=custom-columns="NAME:.metadata.nam
891895
# All images excluding "registry.k8s.io/coredns:1.6.2"
892896
kubectl get pods -A -o=custom-columns='DATA:spec.containers[?(@.image!="registry.k8s.io/coredns:1.6.2")].image'
893897
894-
895898
# All fields under metadata regardless of name
896899
kubectl get pods -A -o=custom-columns='DATA:metadata.*'
897900
@@ -924,11 +927,11 @@ More examples in the kubectl [reference documentation](/docs/reference/kubectl/#
924927
925928
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).
926929
-->
927-
### Kubectl 日志输出详细程度和调试
930+
### Kubectl 日志输出详细程度和调试 {#kubectl-output-verbosity-and-debugging}
928931

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

933936
<!--
934937
Verbosity | Description

0 commit comments

Comments
 (0)