Skip to content

Commit 73c1cbb

Browse files
committed
[zh] sysc reference\kubectl\quick-reference.md
Signed-off-by: ydFu <[email protected]>
1 parent 5a91c11 commit 73c1cbb

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc
8181

8282
<!--
8383
Require kubectl version 1.23 or above.
84+
85+
```bash
86+
echo 'kubectl completion fish | source' >> ~/.config/fish/config.fish # add kubectl autocompletion permanently to your fish shell
87+
```
8488
-->
8589

8690
需要 kubectl 版本 1.23 或更高版本。
8791

8892
```bash
89-
+echo 'kubectl completion fish | source' >> ~/.config/fish/config.fish # 将 kubectl 自动补全永久添加到你的 Fish shell 中
93+
echo 'kubectl completion fish | source' >> ~/.config/fish/config.fish # 将 kubectl 自动补全永久添加到你的 Fish shell 中
9094
```
9195

9296
<!--
@@ -123,12 +127,19 @@ KUBECONFIG=~/.kube/config:~/.kube/kubconfig2
123127
124128
kubectl config view
125129
130+
# Show merged kubeconfig settings and raw certificate data and exposed secrets
131+
kubectl config view --raw
132+
126133
# get the password for the e2e user
127134
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'
128135
136+
# get the certificate for the e2e user
137+
kubectl config view --raw -o jsonpath='{.users[?(.name == "e2e")].user.client-certificate-data}' | base64 -d
138+
129139
kubectl config view -o jsonpath='{.users[].name}' # display the first user
130140
kubectl config view -o jsonpath='{.users[*].name}' # get a list of users
131141
kubectl config get-contexts # display list of contexts
142+
kubectl config get-contexts -o name # get all context names
132143
kubectl config current-context # display the current-context
133144
kubectl config use-context my-cluster-name # set the default context to my-cluster-name
134145
@@ -162,12 +173,19 @@ KUBECONFIG=~/.kube/config:~/.kube/kubconfig2
162173

163174
kubectl config view
164175

176+
# 显示合并的 kubeconfig 配置和原始证书数据以及公开的 Secret
177+
kubectl config view --raw
178+
165179
# 获取 e2e 用户的密码
166180
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'
167181

182+
# 获取 e2e 用户的证书
183+
kubectl config view --raw -o jsonpath='{.users[?(.name == "e2e")].user.client-certificate-data}' | base64 -d
184+
168185
kubectl config view -o jsonpath='{.users[].name}' # 显示第一个用户
169186
kubectl config view -o jsonpath='{.users[*].name}' # 获取用户列表
170187
kubectl config get-contexts # 显示上下文列表
188+
kubectl config get-contexts -o name # 获取所有上下文的名称
171189
kubectl config current-context # 展示当前所处的上下文
172190
kubectl config use-context my-cluster-name # 设置默认的上下文为 my-cluster-name
173191

@@ -714,6 +732,7 @@ kubectl port-forward my-pod 5000:6000 # Listen on port 5000 on the
714732
kubectl exec my-pod -- ls / # Run command in existing pod (1 container case)
715733
kubectl exec --stdin --tty my-pod -- /bin/sh # Interactive shell access to a running pod (1 container case)
716734
kubectl exec my-pod -c my-container -- ls / # Run command in existing pod (multi-container case)
735+
kubectl top pod # Show metrics for all pods in the default namespace
717736
kubectl top pod POD_NAME --containers # Show metrics for a given pod and its containers
718737
kubectl top pod POD_NAME --sort-by=cpu # Show metrics for a given pod and sort it by 'cpu' or 'memory'
719738
```
@@ -738,7 +757,8 @@ kubectl port-forward my-pod 5000:6000 # 在本地计算机上侦
738757
kubectl exec my-pod -- ls / # 在已有的 Pod 中运行命令(单容器场景)
739758
kubectl exec --stdin --tty my-pod -- /bin/sh # 使用交互 shell 访问正在运行的 Pod (一个容器场景)
740759
kubectl exec my-pod -c my-container -- ls / # 在已有的 Pod 中运行命令(多容器场景)
741-
kubectl top pod POD_NAME --containers # 显示给定 Pod 和其中容器的监控数据
760+
kubectl top pod # 显示默认命名空间中所有 Pod 的度量值
761+
kubectl top pod POD_NAME --containers # 显示给定 Pod 和其中容器的度量值
742762
kubectl top pod POD_NAME --sort-by=cpu # 显示给定 Pod 的指标并且按照 'cpu' 或者 'memory' 排序
743763
```
744764

@@ -820,6 +840,7 @@ kubectl exec deploy/my-deployment -- ls # 在 Deployment 里
820840
kubectl cordon my-node # Mark my-node as unschedulable
821841
kubectl drain my-node # Drain my-node in preparation for maintenance
822842
kubectl uncordon my-node # Mark my-node as schedulable
843+
kubectl top node # Show metrics for all nodes
823844
kubectl top node my-node # Show metrics for a given node
824845
kubectl cluster-info # Display addresses of the master and services
825846
kubectl cluster-info dump # Dump current cluster state to stdout
@@ -836,6 +857,7 @@ kubectl taint nodes foo dedicated=special-user:NoSchedule
836857
kubectl cordon my-node # 标记 my-node 节点为不可调度
837858
kubectl drain my-node # 对 my-node 节点进行清空操作,为节点维护做准备
838859
kubectl uncordon my-node # 标记 my-node 节点为可以调度
860+
kubectl top node # 显示所有节点的度量值
839861
kubectl top node my-node # 显示给定节点的度量值
840862
kubectl cluster-info # 显示主控节点和服务的地址
841863
kubectl cluster-info dump # 将当前集群状态转储到标准输出

0 commit comments

Comments
 (0)