@@ -81,12 +81,16 @@ echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc
8181
8282<!--
8383Require 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
124128kubectl 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
127134kubectl 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+
129139kubectl config view -o jsonpath='{.users[].name}' # display the first user
130140kubectl config view -o jsonpath='{.users[*].name}' # get a list of users
131141kubectl config get-contexts # display list of contexts
142+ kubectl config get-contexts -o name # get all context names
132143kubectl config current-context # display the current-context
133144kubectl 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
163174kubectl config view
164175
176+ # 显示合并的 kubeconfig 配置和原始证书数据以及公开的 Secret
177+ kubectl config view --raw
178+
165179# 获取 e2e 用户的密码
166180kubectl 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+
168185kubectl config view -o jsonpath=' {.users[].name}' # 显示第一个用户
169186kubectl config view -o jsonpath=' {.users[*].name}' # 获取用户列表
170187kubectl config get-contexts # 显示上下文列表
188+ kubectl config get-contexts -o name # 获取所有上下文的名称
171189kubectl config current-context # 展示当前所处的上下文
172190kubectl 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
714732kubectl exec my-pod -- ls / # Run command in existing pod (1 container case)
715733kubectl exec --stdin --tty my-pod -- /bin/sh # Interactive shell access to a running pod (1 container case)
716734kubectl 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
717736kubectl top pod POD_NAME --containers # Show metrics for a given pod and its containers
718737kubectl 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 # 在本地计算机上侦
738757kubectl exec my-pod -- ls / # 在已有的 Pod 中运行命令(单容器场景)
739758kubectl exec --stdin --tty my-pod -- /bin/sh # 使用交互 shell 访问正在运行的 Pod (一个容器场景)
740759kubectl 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 和其中容器的度量值
742762kubectl top pod POD_NAME --sort-by=cpu # 显示给定 Pod 的指标并且按照 'cpu' 或者 'memory' 排序
743763```
744764
@@ -820,6 +840,7 @@ kubectl exec deploy/my-deployment -- ls # 在 Deployment 里
820840kubectl cordon my-node # Mark my-node as unschedulable
821841kubectl drain my-node # Drain my-node in preparation for maintenance
822842kubectl uncordon my-node # Mark my-node as schedulable
843+ kubectl top node # Show metrics for all nodes
823844kubectl top node my-node # Show metrics for a given node
824845kubectl cluster-info # Display addresses of the master and services
825846kubectl cluster-info dump # Dump current cluster state to stdout
@@ -836,6 +857,7 @@ kubectl taint nodes foo dedicated=special-user:NoSchedule
836857kubectl cordon my-node # 标记 my-node 节点为不可调度
837858kubectl drain my-node # 对 my-node 节点进行清空操作,为节点维护做准备
838859kubectl uncordon my-node # 标记 my-node 节点为可以调度
860+ kubectl top node # 显示所有节点的度量值
839861kubectl top node my-node # 显示给定节点的度量值
840862kubectl cluster-info # 显示主控节点和服务的地址
841863kubectl cluster-info dump # 将当前集群状态转储到标准输出
0 commit comments