[zh] sync organize-cluster-access-kubeconfig.md

pull/39833/head
windsonsea 2023-03-07 18:06:23 +08:00
parent ef2f73828c
commit bccd515e3e
1 changed files with 54 additions and 54 deletions

View File

@ -20,27 +20,23 @@ of a cluster.
使用 kubeconfig 文件来组织有关集群、用户、命名空间和身份认证机制的信息。
`kubectl` 命令行工具使用 kubeconfig 文件来查找选择集群所需的信息,并与集群的 API 服务器进行通信。
<!--
{{< note >}}
<!--
A file that is used to configure access to clusters is called
a *kubeconfig file*. This is a generic way of referring to configuration files.
It does not mean that there is a file named `kubeconfig`.
{{< /note >}}
-->
{{< note >}}
用于配置集群访问的文件称为“kubeconfig 文件”。
这是引用配置文件的通用方法,并不意味着有一个名为 `kubeconfig` 的文件
用于配置集群访问的文件称为 **kubeconfig 文件**
这是引用到配置文件的通用方法,并不意味着有一个名为 `kubeconfig` 的文件。
{{< /note >}}
<!--
{{< warning >}}
<!--
Only use kubeconfig files from trusted sources. Using a specially-crafted kubeconfig file could result in malicious code execution or file exposure.
If you must use an untrusted kubeconfig file, inspect it carefully first, much as you would a shell script.
{{< /warning>}}
-->
{{< warning >}}
只使用来源可靠的 kubeconfig 文件。使用特制的 kubeconfig 文件可能会导致恶意代码执行或文件暴露。
如果必须使用不受信任的 kubeconfig 文件,请首先像检查 shell 脚本一样仔细检查它。
请务必仅使用来源可靠的 kubeconfig 文件。使用特制的 kubeconfig 文件可能会导致恶意代码执行或文件暴露。
如果必须使用不受信任的 kubeconfig 文件,请首先像检查 Shell 脚本一样仔细检查此文件。
{{< /warning>}}
<!--
@ -57,15 +53,15 @@ variable or by setting the
For step-by-step instructions on creating and specifying kubeconfig files, see
[Configure Access to Multiple Clusters](/docs/tasks/access-application-cluster/configure-access-multiple-clusters).
-->
有关创建和指定 kubeconfig 文件的分步说明,请参阅
[配置对多集群的访问](/zh-cn/docs/tasks/access-application-cluster/configure-access-multiple-clusters)。
有关创建和指定 kubeconfig 文件的分步说明,
请参阅[配置对多集群的访问](/zh-cn/docs/tasks/access-application-cluster/configure-access-multiple-clusters)。
<!-- body -->
<!--
## Supporting multiple clusters, users, and authentication mechanisms
-->
## 支持多集群、用户和身份认证机制
## 支持多集群、用户和身份认证机制 {#support-clusters-users-and-authn}
<!--
Suppose you have several clusters, and your users and components authenticate
@ -92,7 +88,7 @@ clusters and namespaces.
<!--
## Context
-->
## 上下文Context
## 上下文Context {#context}
<!--
A *context* element in a kubeconfig file is used to group access parameters
@ -107,7 +103,7 @@ the *current context* to communicate with the cluster.
<!--
To choose the current context:
-->
选择当前上下文
选择当前上下文
```shell
kubectl config use-context
@ -116,7 +112,7 @@ kubectl config use-context
<!--
## The KUBECONFIG environment variable
-->
## KUBECONFIG 环境变量
## KUBECONFIG 环境变量 {#kubeconfig-env-var}
<!--
The `KUBECONFIG` environment variable holds a list of kubeconfig files.
@ -126,21 +122,21 @@ required. If the `KUBECONFIG` environment variable doesn't exist,
`kubectl` uses the default kubeconfig file, `$HOME/.kube/config`.
-->
`KUBECONFIG` 环境变量包含一个 kubeconfig 文件列表。
对于 Linux 和 Mac列表以冒号分隔。对于 Windows列表以分号分隔。
`KUBECONFIG` 环境变量不是必的。
如果 `KUBECONFIG` 环境变量不存在,`kubectl` 使用默认的 kubeconfig 文件,`$HOME/.kube/config`。
对于 Linux 和 Mac列表以英文冒号分隔。对于 Windows列表以英文分号分隔。
`KUBECONFIG` 环境变量不是必的。
如果 `KUBECONFIG` 环境变量不存在,`kubectl` 将使用默认的 kubeconfig 文件:`$HOME/.kube/config`。
<!--
If the `KUBECONFIG` environment variable does exist, `kubectl` uses
an effective configuration that is the result of merging the files
listed in the `KUBECONFIG` environment variable.
-->
如果 `KUBECONFIG` 环境变量存在,`kubectl` 使用 `KUBECONFIG` 环境变量中列举的文件合并后的有效配置。
如果 `KUBECONFIG` 环境变量存在,`kubectl` 使用 `KUBECONFIG` 环境变量中列举的文件合并后的有效配置。
<!--
## Merging kubeconfig files
-->
## 合并 kubeconfig 文件
## 合并 kubeconfig 文件 {#merge-kubeconfig-files}
<!--
To see your configuration, enter this command:
@ -155,7 +151,7 @@ kubectl config view
As described previously, the output might be from a single kubeconfig file,
or it might be the result of merging several kubeconfig files.
-->
如前所述,输出可能来自 kubeconfig 文件,也可能是合并多个 kubeconfig 文件的结果。
如前所述,输出可能来自单个 kubeconfig 文件,也可能是合并多个 kubeconfig 文件的结果。
<!--
Here are the rules that `kubectl` uses when it merges kubeconfig files:
@ -186,34 +182,36 @@ Here are the rules that `kubectl` uses when it merges kubeconfig files:
* 忽略空文件名。
* 对于内容无法反序列化的文件,产生错误信息。
* 第一个设置特定值或者映射键的文件将生效。
* 永远不会更改值或者映射键。示例:保留第一个文件的上下文以设置 `current-context`。示例:如果两个文件都指定了 `red-user`,则仅使用第一个文件的 `red-user` 中的值。即使第二个文件在 `red-user` 下有非冲突条目,也要丢弃它们。
* 永远不会更改值或者映射键。示例:保留第一个文件的上下文以设置 `current-context`
示例:如果两个文件都指定了 `red-user`,则仅使用第一个文件的 `red-user` 中的值。
即使第二个文件在 `red-user` 下有非冲突条目,也要丢弃它们。
<!--
<!--
For an example of setting the `KUBECONFIG` environment variable, see
[Setting the KUBECONFIG environment variable](/docs/tasks/access-application-cluster/configure-access-multiple-clusters/#set-the-kubeconfig-environment-variable).
-->
有关设置 `KUBECONFIG` 环境变量的示例,请参阅
[设置 KUBECONFIG 环境变量](/zh-cn/docs/tasks/access-application-cluster/configure-access-multiple-clusters/#set-the-kubeconfig-environment-variable)。
-->
有关设置 `KUBECONFIG` 环境变量的示例,
请参阅[设置 KUBECONFIG 环境变量](/zh-cn/docs/tasks/access-application-cluster/configure-access-multiple-clusters/#set-the-kubeconfig-environment-variable)。
<!--
<!--
Otherwise, use the default kubeconfig file, `$HOME/.kube/config`, with no merging.
-->
否则,使用默认的 kubeconfig 文件 `$HOME/.kube/config`,不进行合并。
-->
否则,使用默认的 kubeconfig 文件`$HOME/.kube/config`,不进行合并。
<!--
1. Determine the context to use based on the first hit in this chain:
1. Use the `--context` command-line flag if it exists.
2. Use the `current-context` from the merged kubeconfig files.
1. Use the `current-context` from the merged kubeconfig files.
-->
2. 根据此链中的第一个匹配确定要使用的上下文。
1. 如果存在,使用 `--context` 命令行参数。
1. 如果存在上下文使用 `--context` 命令行参数。
2. 使用合并的 kubeconfig 文件中的 `current-context`
<!--
<!--
An empty context is allowed at this point.
-->
-->
这种场景下允许空上下文。
<!--
@ -222,16 +220,17 @@ Here are the rules that `kubectl` uses when it merges kubeconfig files:
which is run twice: once for user and once for cluster:
1. Use a command-line flag if it exists: `--user` or `--cluster`.
2. If the context is non-empty, take the user or cluster from the context.
1. If the context is non-empty, take the user or cluster from the context.
-->
3. 确定集群和用户。此时,可能有也可能没有上下文。根据此链中的第一个匹配确定集群和用户,这将运行两次:一次用于用户,一次用于集群。
3. 确定集群和用户。此时,可能有也可能没有上下文。根据此链中的第一个匹配确定集群和用户,
这将运行两次:一次用于用户,一次用于集群。
1. 如果存在,使用命令行参数:`--user` 或者 `--cluster`
2. 如果上下文非空,从上下文中获取用户或集群。
1. 如果存在用户或集群使用命令行参数:`--user` 或者 `--cluster`
2. 如果上下文非空,从上下文中获取用户或集群。
<!--
<!--
The user and cluster can be empty at this point.
-->
-->
这种场景下用户和集群可以为空。
<!--
@ -240,32 +239,33 @@ Here are the rules that `kubectl` uses when it merges kubeconfig files:
Build each piece of the cluster information based on this chain; the first hit wins:
1. Use command line flags if they exist: `--server`, `--certificate-authority`, `--insecure-skip-tls-verify`.
2. If any cluster information attributes exist from the merged kubeconfig files, use them.
3. If there is no server location, fail.
1. If any cluster information attributes exist from the merged kubeconfig files, use them.
1. If there is no server location, fail.
-->
4. 确定要使用的实际集群信息。此时,可能有也可能没有集群信息。基于此链构建每个集群信息;第一个匹配项会被采用:
4. 确定要使用的实际集群信息。此时,可能有也可能没有集群信息。
基于此链构建每个集群信息;第一个匹配项会被采用:
1. 如果存在:`--server`、`--certificate-authority` 和 `--insecure-skip-tls-verify`,使用命令行参数
2. 如果合并的 kubeconfig 文件中存在集群信息属性,则使用它们
1. 如果存在集群信息,则使用命令行参数`--server`、`--certificate-authority` 和 `--insecure-skip-tls-verify`
2. 如果合并的 kubeconfig 文件中存在集群信息属性,则使用这些属性
3. 如果没有 server 配置,则配置无效。
<!--
2. Determine the actual user information to use. Build user information using the same
1. Determine the actual user information to use. Build user information using the same
rules as cluster information, except allow only one authentication
technique per user:
1. Use command line flags if they exist: `--client-certificate`, `--client-key`, `--username`, `--password`, `--token`.
2. Use the `user` fields from the merged kubeconfig files.
3. If there are two conflicting techniques, fail.
1. Use the `user` fields from the merged kubeconfig files.
1. If there are two conflicting techniques, fail.
-->
5. 确定要使用的实际用户信息。使用与集群信息相同的规则构建用户信息,但每个用户只允许一种身份认证技术:
5. 确定要使用的实际用户信息。使用与集群信息相同的规则构建用户信息,但对于每个用户只允许使用一种身份认证技术:
1. 如果存在:`--client-certificate`、`--client-key`、`--username`、`--password` 和 `--token`,使用命令行参数
1. 如果存在用户信息,则使用命令行参数`--client-certificate`、`--client-key`、`--username`、`--password` 和 `--token`
2. 使用合并的 kubeconfig 文件中的 `user` 字段。
3. 如果存在两种冲突技术,则配置无效。
<!--
3. For any information still missing, use default values and potentially
1. For any information still missing, use default values and potentially
prompt for authentication information.
-->
6. 对于仍然缺失的任何信息,使用其对应的默认值,并可能提示输入身份认证信息。
@ -273,7 +273,7 @@ Here are the rules that `kubectl` uses when it merges kubeconfig files:
<!--
## File references
-->
## 文件引用
## 文件引用 {#file-reference}
<!--
File and path references in a kubeconfig file are relative to the location of the kubeconfig file.
@ -283,14 +283,14 @@ are stored absolutely.
-->
kubeconfig 文件中的文件和路径引用是相对于 kubeconfig 文件的位置。
命令行上的文件引用是相对于当前工作目录的。
`$HOME/.kube/config` 中,相对路径按相对路径存储,绝对路径按绝对路径存储。
`$HOME/.kube/config` 中,相对路径按相对路径存储,绝对路径按绝对路径存储。
<!--
## Proxy
You can configure `kubectl` to use a proxy per cluster using `proxy-url` in your kubeconfig file, like this:
-->
## 代理
## 代理 {#proxy}
你可以在 `kubeconfig` 文件中,为每个集群配置 `proxy-url` 来让 `kubectl` 使用代理,例如: