Skip to content

Commit

Permalink
Merge pull request #45906 from ydFu/quick-reference
Browse files Browse the repository at this point in the history
[zh] sysc reference\kubectl\quick-reference.md
  • Loading branch information
k8s-ci-robot committed Apr 18, 2024
2 parents 39694ce + 73c1cbb commit ecdbe80
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions content/zh-cn/docs/reference/kubectl/quick-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc

<!--
Require kubectl version 1.23 or above.
```bash
echo 'kubectl completion fish | source' >> ~/.config/fish/config.fish # add kubectl autocompletion permanently to your fish shell
```
-->

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

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

<!--
Expand Down Expand Up @@ -123,12 +127,19 @@ KUBECONFIG=~/.kube/config:~/.kube/kubconfig2
kubectl config view
# Show merged kubeconfig settings and raw certificate data and exposed secrets
kubectl config view --raw
# get the password for the e2e user
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'
# get the certificate for the e2e user
kubectl config view --raw -o jsonpath='{.users[?(.name == "e2e")].user.client-certificate-data}' | base64 -d
kubectl config view -o jsonpath='{.users[].name}' # display the first user
kubectl config view -o jsonpath='{.users[*].name}' # get a list of users
kubectl config get-contexts # display list of contexts
kubectl config get-contexts -o name # get all context names
kubectl config current-context # display the current-context
kubectl config use-context my-cluster-name # set the default context to my-cluster-name
Expand Down Expand Up @@ -162,12 +173,19 @@ KUBECONFIG=~/.kube/config:~/.kube/kubconfig2

kubectl config view

# 显示合并的 kubeconfig 配置和原始证书数据以及公开的 Secret
kubectl config view --raw

# 获取 e2e 用户的密码
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'

# 获取 e2e 用户的证书
kubectl config view --raw -o jsonpath='{.users[?(.name == "e2e")].user.client-certificate-data}' | base64 -d

kubectl config view -o jsonpath='{.users[].name}' # 显示第一个用户
kubectl config view -o jsonpath='{.users[*].name}' # 获取用户列表
kubectl config get-contexts # 显示上下文列表
kubectl config get-contexts -o name # 获取所有上下文的名称
kubectl config current-context # 展示当前所处的上下文
kubectl config use-context my-cluster-name # 设置默认的上下文为 my-cluster-name

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

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

0 comments on commit ecdbe80

Please sign in to comment.