From 27ef353ee4d19dd055f5abd81641d40eb693dc65 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Jul 2022 20:52:27 +0800 Subject: [PATCH] [zh-cn] resync /docs/reference/kubectl/cheatsheet.md --- .../docs/reference/kubectl/cheatsheet.md | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/content/zh-cn/docs/reference/kubectl/cheatsheet.md b/content/zh-cn/docs/reference/kubectl/cheatsheet.md index f85846aa32..6ca3acfba8 100644 --- a/content/zh-cn/docs/reference/kubectl/cheatsheet.md +++ b/content/zh-cn/docs/reference/kubectl/cheatsheet.md @@ -26,7 +26,7 @@ card: This page contains a list of commonly used `kubectl` commands and flags. --> -本页列举了常用的 “kubectl” 命令和标志 +本页列举了常用的 `kubectl` 命令和标志。 @@ -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 中永久地添加自动补全 ``` -## 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/)。 -## 与运行中的 Pods 进行交互 +## 与运行中的 Pod 进行交互