@@ -81,12 +81,16 @@ echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc
81
81
82
82
<!--
83
83
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
+ ```
84
88
-->
85
89
86
90
需要 kubectl 版本 1.23 或更高版本。
87
91
88
92
``` 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 中
90
94
```
91
95
92
96
<!--
@@ -123,12 +127,19 @@ KUBECONFIG=~/.kube/config:~/.kube/kubconfig2
123
127
124
128
kubectl config view
125
129
130
+ # Show merged kubeconfig settings and raw certificate data and exposed secrets
131
+ kubectl config view --raw
132
+
126
133
# get the password for the e2e user
127
134
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'
128
135
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
+
129
139
kubectl config view -o jsonpath='{.users[].name}' # display the first user
130
140
kubectl config view -o jsonpath='{.users[*].name}' # get a list of users
131
141
kubectl config get-contexts # display list of contexts
142
+ kubectl config get-contexts -o name # get all context names
132
143
kubectl config current-context # display the current-context
133
144
kubectl config use-context my-cluster-name # set the default context to my-cluster-name
134
145
@@ -162,12 +173,19 @@ KUBECONFIG=~/.kube/config:~/.kube/kubconfig2
162
173
163
174
kubectl config view
164
175
176
+ # 显示合并的 kubeconfig 配置和原始证书数据以及公开的 Secret
177
+ kubectl config view --raw
178
+
165
179
# 获取 e2e 用户的密码
166
180
kubectl config view -o jsonpath=' {.users[?(@.name == "e2e")].user.password}'
167
181
182
+ # 获取 e2e 用户的证书
183
+ kubectl config view --raw -o jsonpath=' {.users[?(.name == "e2e")].user.client-certificate-data}' | base64 -d
184
+
168
185
kubectl config view -o jsonpath=' {.users[].name}' # 显示第一个用户
169
186
kubectl config view -o jsonpath=' {.users[*].name}' # 获取用户列表
170
187
kubectl config get-contexts # 显示上下文列表
188
+ kubectl config get-contexts -o name # 获取所有上下文的名称
171
189
kubectl config current-context # 展示当前所处的上下文
172
190
kubectl config use-context my-cluster-name # 设置默认的上下文为 my-cluster-name
173
191
@@ -714,6 +732,7 @@ kubectl port-forward my-pod 5000:6000 # Listen on port 5000 on the
714
732
kubectl exec my-pod -- ls / # Run command in existing pod (1 container case)
715
733
kubectl exec --stdin --tty my-pod -- /bin/sh # Interactive shell access to a running pod (1 container case)
716
734
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
717
736
kubectl top pod POD_NAME --containers # Show metrics for a given pod and its containers
718
737
kubectl top pod POD_NAME --sort-by=cpu # Show metrics for a given pod and sort it by 'cpu' or 'memory'
719
738
```
@@ -738,7 +757,8 @@ kubectl port-forward my-pod 5000:6000 # 在本地计算机上侦
738
757
kubectl exec my-pod -- ls / # 在已有的 Pod 中运行命令(单容器场景)
739
758
kubectl exec --stdin --tty my-pod -- /bin/sh # 使用交互 shell 访问正在运行的 Pod (一个容器场景)
740
759
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 和其中容器的度量值
742
762
kubectl top pod POD_NAME --sort-by=cpu # 显示给定 Pod 的指标并且按照 'cpu' 或者 'memory' 排序
743
763
```
744
764
@@ -820,6 +840,7 @@ kubectl exec deploy/my-deployment -- ls # 在 Deployment 里
820
840
kubectl cordon my-node # Mark my-node as unschedulable
821
841
kubectl drain my-node # Drain my-node in preparation for maintenance
822
842
kubectl uncordon my-node # Mark my-node as schedulable
843
+ kubectl top node # Show metrics for all nodes
823
844
kubectl top node my-node # Show metrics for a given node
824
845
kubectl cluster-info # Display addresses of the master and services
825
846
kubectl cluster-info dump # Dump current cluster state to stdout
@@ -836,6 +857,7 @@ kubectl taint nodes foo dedicated=special-user:NoSchedule
836
857
kubectl cordon my-node # 标记 my-node 节点为不可调度
837
858
kubectl drain my-node # 对 my-node 节点进行清空操作,为节点维护做准备
838
859
kubectl uncordon my-node # 标记 my-node 节点为可以调度
860
+ kubectl top node # 显示所有节点的度量值
839
861
kubectl top node my-node # 显示给定节点的度量值
840
862
kubectl cluster-info # 显示主控节点和服务的地址
841
863
kubectl cluster-info dump # 将当前集群状态转储到标准输出
0 commit comments