[zh-cn] resync /docs/reference/kubectl/cheatsheet.md

pull/35021/head
Michael 2022-07-14 20:52:27 +08:00
parent e396a65051
commit 27ef353ee4
1 changed files with 28 additions and 9 deletions

View File

@ -26,7 +26,7 @@ card:
This page contains a list of commonly used `kubectl` commands and flags.
-->
本页列举了常用的 “kubectl” 命令和标志
本页列举了常用的 `kubectl` 命令和标志。
<!-- body -->
@ -50,10 +50,10 @@ You can also use a shorthand alias for `kubectl` that also works with completion
-->
```bash
source <(kubectl completion bash) # 在 bash 中设置当前 shell 的自动补全,要先安装 bash-completion 包。
echo "source <(kubectl completion bash)" >> ~/.bashrc # 在您的 bash shell 中永久的添加自动补全
echo "source <(kubectl completion bash)" >> ~/.bashrc # 在你的 bash shell 中永久地添加自动补全
```
您还可以为 `kubectl` 使用一个速记别名,该别名也可以与 completion 一起使用
你还可以在补全时为 `kubectl` 使用一个速记别名
```bash
alias k=kubectl
@ -70,7 +70,7 @@ echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc
-->
```bash
source <(kubectl completion zsh) # 在 zsh 中设置当前 shell 的自动补全
echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc # 在您的 zsh shell 中永久的添加自动补全
echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc # 在你的 zsh shell 中永久地添加自动补全
```
<!--
@ -92,7 +92,7 @@ Set which Kubernetes cluster `kubectl` communicates with and modifies configurat
information. See [Authenticating Across Clusters with kubeconfig](/docs/tasks/access-application-cluster/configure-access-multiple-clusters/) documentation for
detailed config file information.
-->
## Kubectl 上下文和配置
## Kubectl 上下文和配置
设置 `kubectl` 与哪个 Kubernetes 集群进行通信并修改配置信息。
查看[使用 kubeconfig 跨集群授权访问](/zh-cn/docs/tasks/access-application-cluster/configure-access-multiple-clusters/)
@ -116,6 +116,11 @@ kubectl config get-contexts # display list of contexts
kubectl config current-context # display the current-context
kubectl config use-context my-cluster-name # set the default context to my-cluster-name
kubectl config set-cluster my-cluster-name # set a cluster entry in the kubeconfig
# configure the URL to a proxy server to use for requests made by this client in the kubeconfig
kubectl config set-cluster my-cluster-name --proxy-url=my-proxy-url
# add a new user to your kubeconf that supports basic auth
kubectl config set-credentials kubeuser/foo.kubernetes.com --username=kubeuser --password=kubepassword
@ -137,7 +142,9 @@ alias kn='f() { [ "$1" ] && kubectl config set-context --current --namespace $1
kubectl config view # 显示合并的 kubeconfig 配置。
# 同时使用多个 kubeconfig 文件并查看合并的配置
KUBECONFIG=~/.kube/config:~/.kube/kubconfig2 kubectl config view
KUBECONFIG=~/.kube/config:~/.kube/kubconfig2
kubectl config view
# 获取 e2e 用户的密码
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'
@ -148,6 +155,11 @@ kubectl config get-contexts # 显示上下文列表
kubectl config current-context # 展示当前所处的上下文
kubectl config use-context my-cluster-name # 设置默认的上下文为 my-cluster-name
kubectl config set-cluster my-cluster-name # 在 kubeconfig 中设置集群条目
# 在 kubeconfig 中配置代理服务器的 URL以用于该客户端的请求
kubectl config set-cluster my-cluster-name --proxy-url=my-proxy-url
# 添加新的用户配置到 kubeconf 中,使用 basic auth 进行身份认证
kubectl config set-credentials kubeuser/foo.kubernetes.com --username=kubeuser --password=kubepassword
@ -171,10 +183,11 @@ alias kn='f() { [ "$1" ] && kubectl config set-context --current --namespace $1
`apply` manages applications through files defining Kubernetes resources. It creates and updates resources in a cluster through running `kubectl apply`. This is the recommended way of managing Kubernetes applications on production. See [Kubectl Book](https://kubectl.docs.kubernetes.io).
-->
## Kubectl apply
`apply` 通过定义 Kubernetes 资源的文件来管理应用。
它通过运行 `kubectl apply` 在集群中创建和更新资源。
这是在生产中管理 Kubernetes 应用的推荐方法。
参见 [Kubectl 文档](https://kubectl.docs.kubernetes.io)。
参见 [Kubectl 文档](https://kubectl.docs.kubernetes.io/zh/)。
<!--
## Creating objects
@ -638,7 +651,7 @@ kubectl get pods -n mynamespace --no-headers=true | awk '/pattern1|pattern2/{pr
<!--
## Interacting with running Pods
-->
## 与运行中的 Pods 进行交互
## 与运行中的 Pod 进行交互
<!--
```bash
@ -772,6 +785,9 @@ kubectl cluster-info # Display
kubectl cluster-info dump # Dump current cluster state to stdout
kubectl cluster-info dump --output-directory=/path/to/cluster-state # Dump current cluster state to /path/to/cluster-state
# View existing taints on which exist on current nodes.
kubectl get nodes -o=custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect
# If a taint with that key and effect already exists, its value is replaced as specified.
kubectl taint nodes foo dedicated=special-user:NoSchedule
```
@ -785,6 +801,9 @@ kubectl cluster-info # 显示
kubectl cluster-info dump # 将当前集群状态转储到标准输出
kubectl cluster-info dump --output-directory=/path/to/cluster-state # 将当前集群状态输出到 /path/to/cluster-state
# 查看当前节点上存在的现有污点。
kubectl get nodes -o=custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect
# 如果已存在具有指定键和效果的污点,则替换其值为指定值。
kubectl taint nodes foo dedicated=special-user:NoSchedule
```
@ -927,7 +946,7 @@ Verbosity | Description
详细程度 | 描述
--------------| -----------
`--v=0` | 用于那些应该 *始终* 对运维人员可见的信息,因为这些信息一般很有用。
`--v=1` | 如果不想要看到冗余信息,此值是一个合理的默认日志级别。
`--v=1` | 如果不想要看到冗余信息,此值是一个合理的默认日志级别。
`--v=2` | 输出有关服务的稳定状态的信息以及重要的日志消息,这些信息可能与系统中的重大变化有关。这是建议大多数系统设置的默认日志级别。
`--v=3` | 包含有关系统状态变化的扩展信息。
`--v=4` | 包含调试级别的冗余信息。