Merge pull request #41623 from my-git9/ip-masq-agent3

[zh-cn] sync and improve resource-usage-monitoring ip-masq-agent audit
pull/41639/head
Kubernetes Prow Robot 2023-06-14 07:16:19 -07:00 committed by GitHub
commit e59c484653
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 51 deletions

View File

@ -36,16 +36,16 @@ cluster's pod [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routin
范围之外的目的地时使用。
<!--
### **Key Terms**
### Key Terms
-->
### **关键术语** {#key-terms}
### 关键术语 {#key-terms}
<!--
* **NAT (Network Address Translation)**
* **NAT (Network Address Translation)**:
Is a method of remapping one IP address to another by modifying either the source and/or
destination address information in the IP header. Typically performed by a device doing IP routing.
-->
* **NAT (网络地址转换)**
* **NAT网络地址转换**
是一种通过修改 IP 地址头中的源和/或目标地址信息将一个 IP 地址重新映射
到另一个 IP 地址的方法。通常由执行 IP 路由的设备执行。
@ -55,7 +55,7 @@ cluster's pod [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routin
multiple source IP addresses are masked behind a single address, which is typically the
device doing the IP routing. In Kubernetes this is the Node's IP address.
-->
* **伪装**
* **伪装**
NAT 的一种形式,通常用于执行多对一地址转换,其中多个源 IP 地址被隐藏在
单个地址后面,该地址通常是执行 IP 路由的设备。在 Kubernetes 中,
这是节点的 IP 地址。
@ -67,18 +67,18 @@ cluster's pod [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routin
**CIDR notation**, in which an address or routing prefix is written with a suffix indicating
the number of bits of the prefix, such as 192.168.2.0/24.
-->
* **CIDR (无类别域间路由)**
* **CIDR无类别域间路由**
基于可变长度子网掩码,允许指定任意长度的前缀。
CIDR 引入了一种新的 IP 地址表示方法,现在通常称为**CIDR表示法**
CIDR 引入了一种新的 IP 地址表示方法,现在通常称为 **CIDR 表示法**
其中地址或路由前缀后添加一个后缀,用来表示前缀的位数,例如 192.168.2.0/24。
<!--
* **Link Local**
* Link Local
A link-local address is a network address that is valid only for communications within the
network segment or the broadcast domain that the host is connected to. Link-local addresses
for IPv4 are defined in the address block 169.254.0.0/16 in CIDR notation.
-->
* **本地链路**
* **本地链路**
本地链路是仅对网段或主机所连接的广播域内的通信有效的网络地址。
IPv4 的本地链路地址在 CIDR 表示法的地址块 169.254.0.0/16 中定义。
@ -98,19 +98,19 @@ The agent will also treat link-local (169.254.0.0/16) as a non-masquerade CIDR b
The agent is configured to reload its configuration from the location
*/etc/config/ip-masq-agent* every 60 seconds, which is also configurable.
-->
ip-masq-agent 配置 iptables 规则,以便在将流量发送到集群节点的 IP 和集群 IP 范围之外的目标时
处理伪装节点或 Pod 的 IP 地址。这本质上隐藏了集群节点 IP 地址后面的 Pod IP 地址。
在某些环境中,去往“外部”地址的流量必须从已知的机器地址发出。
ip-masq-agent 配置 iptables 规则,以便在将流量发送到集群节点的 IP 和集群 IP
范围之外的目标时处理伪装节点或 Pod 的 IP 地址。这本质上隐藏了集群节点 IP 地址后面的
Pod IP 地址。在某些环境中,去往"外部"地址的流量必须从已知的机器地址发出。
例如,在 Google Cloud 中,任何到互联网的流量都必须来自 VM 的 IP。
使用容器时,如 Google Kubernetes Engine从 Pod IP 发出的流量将被拒绝出站。
为了避免这种情况,我们必须将 Pod IP 隐藏在 VM 自己的 IP 地址后面 - 通常称为“伪装”
为了避免这种情况,我们必须将 Pod IP 隐藏在 VM 自己的 IP 地址后面 - 通常称为"伪装"
默认情况下,代理配置为将
[RFC 1918](https://tools.ietf.org/html/rfc1918)
指定的三个私有 IP 范围视为非伪装
[CIDR](https://zh.wikipedia.org/wiki/%E6%97%A0%E7%B1%BB%E5%88%AB%E5%9F%9F%E9%97%B4%E8%B7%AF%E7%94%B1)。
这些范围是 10.0.0.0/8,172.16.0.0/12 和 192.168.0.0/16。
这些范围是 10.0.0.0/8172.16.0.0/12 和 192.168.0.0/16。
默认情况下代理还将链路本地地址169.254.0.0/16视为非伪装 CIDR。
代理程序配置为每隔 60 秒从 */etc/config/ip-masq-agent* 重新加载其配置,
代理程序配置为每隔 60 秒从 **/etc/config/ip-masq-agent** 重新加载其配置,
这也是可修改的。
![masq/non-masq example](/images/docs/ip-masq.png)
@ -134,8 +134,8 @@ optional keys:
* `masqLinkLocal`: A Boolean (true/false) which indicates whether to masquerade traffic to the
link local prefix `169.254.0.0/16`. False by default.
-->
* `masqLinkLocal`:布尔值 (true/false),表示是否为本地链路前缀 169.254.0.0/16 的流量提供伪装。
默认为 false。
* `masqLinkLocal`:布尔值true/false表示是否为本地链路前缀 `169.254.0.0/16`
的流量提供伪装。默认为 false。
<!--
* `resyncInterval`: A time interval at which the agent attempts to reload config from disk.
@ -146,7 +146,7 @@ optional keys:
<!--
Traffic to 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 ranges will NOT be masqueraded. Any
other traffic (assumed to be internet) will be masqueraded. An example of a local destination
other traffic (assumed to be internet) will be masqueraded. An example of a local destination
from a pod could be its Node's IP address as well as another node's address or one of the IP
addresses in Cluster's IP range. Any other traffic will be masqueraded by default. The
below entries show the default set of rules that are applied by the ip-masq-agent:
@ -180,17 +180,19 @@ to your cluster.
或者你使用的集群 CIDR 不在 10.0.0.0/8 范围内,
`ip-masq-agent` 将在你的集群中运行。
如果你在其他环境中运行,可以将 `ip-masq-agent`
[DaemonSet](/zh-cn/docs/concepts/workloads/controllers/daemonset/) 添加到你的集群中。
[DaemonSet](/zh-cn/docs/concepts/workloads/controllers/daemonset/)
添加到你的集群中。
<!-- steps -->
<!--
## Create an ip-masq-agent
To create an ip-masq-agent, run the following kubectl command:
-->
## 创建 ip-masq-agent {#create-ip-masq-agent}
通过运行以下 kubectl 指令创建 ip-masq-agent:
通过运行以下 kubectl 指令创建 ip-masq-agent
```shell
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/ip-masq-agent/master/ip-masq-agent.yaml
@ -207,7 +209,7 @@ kubectl label nodes my-node node.kubernetes.io/masq-agent-ds-ready=true
```
<!--
More information can be found in the ip-masq-agent documentation [here](https://github.com/kubernetes-sigs/ip-masq-agent)
More information can be found in the ip-masq-agent documentation [here](https://github.com/kubernetes-sigs/ip-masq-agent).
-->
更多信息可以通过 ip-masq-agent 文档[这里](https://github.com/kubernetes-sigs/ip-masq-agent)找到。
@ -215,7 +217,7 @@ More information can be found in the ip-masq-agent documentation [here](https://
In most cases, the default set of rules should be sufficient; however, if this is not the case
for your cluster, you can create and apply a
[ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap/) to customize the IP
ranges that are affected. For example, to allow
ranges that are affected. For example, to allow
only 10.0.0.0/8 to be considered by the ip-masq-agent, you can create the following
[ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap/) in a file called
"config".
@ -223,15 +225,15 @@ only 10.0.0.0/8 to be considered by the ip-masq-agent, you can create the follow
在大多数情况下,默认的规则集应该足够;但是,如果你的集群不是这种情况,则可以创建并应用
[ConfigMap](/zh-cn/docs/tasks/configure-pod-container/configure-pod-configmap/)
来自定义受影响的 IP 范围。
例如,要允许 ip-masq-agent 仅作用于 10.0.0.0/8你可以在一个名为 “config” 的文件中创建以下
[ConfigMap](/zh-cn/docs/tasks/configure-pod-container/configure-pod-configmap/)
例如,要允许 ip-masq-agent 仅作用于 10.0.0.0/8你可以在一个名为 "config" 的文件中创建以下
[ConfigMap](/zh-cn/docs/tasks/configure-pod-container/configure-pod-configmap/)。
{{< note >}}
<!--
It is important that the file is called config since, by default, that will be used as the key
for lookup by the `ip-masq-agent`:
-->
重要的是,该文件之所以被称为 config因为默认情况下该文件将被用作
重要的是,该文件之所以被称为 config因为默认情况下,该文件将被用作
`ip-masq-agent` 查找的主键:
```yaml
@ -242,7 +244,7 @@ resyncInterval: 60s
{{< /note >}}
<!--
Run the following command to add the config map to your cluster:
Run the following command to add the configmap to your cluster:
-->
运行以下命令将 ConfigMap 添加到你的集群:
@ -276,8 +278,8 @@ By default, the link local range (169.254.0.0/16) is also handled by the ip-masq
sets up the appropriate iptables rules. To have the ip-masq-agent ignore link local, you can
set `masqLinkLocal` to true in the ConfigMap.
-->
默认情况下,本地链路范围 (169.254.0.0/16) 也由 ip-masq agent 处理,
该代理设置适当的 iptables 规则。 要使 ip-masq-agent 忽略本地链路,
默认情况下,本地链路范围169.254.0.0/16也由 ip-masq agent 处理,
该代理设置适当的 iptables 规则。要使 ip-masq-agent 忽略本地链路,
可以在 ConfigMap 中将 `masqLinkLocal` 设置为 true。
```yaml

View File

@ -19,7 +19,7 @@ by applications that use the Kubernetes API, and by the control plane itself.
Auditing allows cluster administrators to answer the following questions:
-->
Kubernetes **审计Auditing** 功能提供了与安全相关的、按时间顺序排列的记录集,
Kubernetes**审计Auditing**功能提供了与安全相关的、按时间顺序排列的记录集,
记录每个用户、使用 Kubernetes API 的应用以及控制面自身引发的活动。
审计功能使得集群管理员能够回答以下问题:
@ -54,9 +54,8 @@ include logs files and webhooks.
-->
审计记录最初产生于
[kube-apiserver](/zh-cn/docs/reference/command-line-tools-reference/kube-apiserver/)
内部。每个请求在不同执行阶段都会生成审计事件;这些审计事件会根据特定策略
被预处理并写入后端。策略确定要记录的内容和用来存储记录的后端。
当前的后端支持日志文件和 webhook。
内部。每个请求在不同执行阶段都会生成审计事件;这些审计事件会根据特定策略被预处理并写入后端。
策略确定要记录的内容和用来存储记录的后端,当前的后端支持日志文件和 webhook。
<!--
Each request can be recorded with an associated _stage_. The defined stages are:
@ -73,8 +72,8 @@ Each request can be recorded with an associated _stage_. The defined stages are:
-->
每个请求都可被记录其相关的**阶段stage**。已定义的阶段有:
- `RequestReceived` - 此阶段对应审计处理器接收到请求后,并且在委托给
其余处理器之前生成的事件。
- `RequestReceived` - 此阶段对应审计处理器接收到请求后,
并且在委托给其余处理器之前生成的事件。
- `ResponseStarted` - 在响应消息的头部发送后,响应消息体发送前生成的事件。
只有长时间运行的请求(例如 watch才会生成这个阶段。
- `ResponseComplete` - 当响应消息体完成并且没有更多数据需要传输的时候。
@ -115,9 +114,9 @@ _audit level_ of the event. The defined audit levels are:
审计策略定义了关于应记录哪些事件以及应包含哪些数据的规则。
审计策略对象结构定义在
[`audit.k8s.io` API 组](/zh-cn/docs/reference/config-api/apiserver-audit.v1/#audit-k8s-io-v1-Policy)
处理事件时,将按顺序与规则列表进行比较。第一个匹配规则设置事件的
**审计级别Audit Level**。已定义的审计级别有:
[`audit.k8s.io` API 组](/zh-cn/docs/reference/config-api/apiserver-audit.v1/#audit-k8s-io-v1-Policy)
处理事件时,将按顺序与规则列表进行比较。第一个匹配规则设置事件的**审计级别Audit Level**。
已定义的审计级别有:
<!--
- `None` - don't log events that match this rule.
@ -194,7 +193,7 @@ In all cases, audit events follow a structure defined by the Kubernetes API in t
-->
## 审计后端 {#audit-backends}
审计后端实现将审计事件导出到外部存储。`Kube-apiserver` 默认提供两个后端:
审计后端实现将审计事件导出到外部存储。`kube-apiserver` 默认提供两个后端:
- Log 后端,将事件写入到文件系统
- Webhook 后端,将事件发送到外部 HTTP API
@ -210,7 +209,7 @@ with an appropriate Kubernetes API object. For example, the following request bo
request to `/apis/batch/v1/namespaces/some-namespace/jobs/some-job-name`:
-->
对于 patch 请求,请求的消息体需要是设定 patch 操作的 JSON 所构成的一个串,
而不是一个完整的 Kubernetes API 对象 JSON 串。
而不是一个完整的 Kubernetes API 对象 JSON 串。
例如,以下的示例是一个合法的 patch 请求消息体,该请求对应
`/apis/batch/v1/namespaces/some-namespace/jobs/some-job-name`
@ -237,7 +236,7 @@ You can configure the log audit backend using the following `kube-apiserver` fla
-->
### Log 后端 {#log-backend}
Log 后端将审计事件写入 [JSONlines](https://jsonlines.org/) 格式的文件。
Log 后端将审计事件写入 [JSONlines](https://jsonlines.org/) 格式的文件。
你可以使用以下 `kube-apiserver` 标志配置 Log 审计后端:
<!--
@ -259,9 +258,9 @@ to the location of the policy file and log file, so that audit records are persi
如果你的集群控制面以 Pod 的形式运行 kube-apiserver记得要通过 `hostPath`
卷来访问策略文件和日志文件所在的目录,这样审计记录才会持久保存下来。例如:
```shell
--audit-policy-file=/etc/kubernetes/audit-policy.yaml \
--audit-log-path=/var/log/kubernetes/audit/audit.log
```yaml
- --audit-policy-file=/etc/kubernetes/audit-policy.yaml
- --audit-log-path=/var/log/kubernetes/audit/audit.log
```
<!--

View File

@ -25,9 +25,9 @@ This information allows you to evaluate your application's performance and
where bottlenecks can be removed to improve overall performance.
-->
要扩展应用程序并提供可靠的服务,你需要了解应用程序在部署时的行为。
你可以通过检测容器检查 Kubernetes 集群中的应用程序性能,
[Pod](/zh-cn/docs/concepts/workloads/pods)、
[服务](/zh-cn/docs/concepts/services-networking/service/)和整个集群的特征
你可以通过检测容器、[Pod](/zh-cn/docs/concepts/workloads/pods)、
[Service](/zh-cn/docs/concepts/services-networking/service/)
和整个集群的特征来检查 Kubernetes 集群中应用程序的性能
Kubernetes 在每个级别上提供有关应用程序资源使用情况的详细信息。
此信息使你可以评估应用程序的性能,以及在何处可以消除瓶颈以提高整体性能。
@ -50,7 +50,7 @@ cluster components such as the
controller, as well as the `kubectl top` utility.
These metrics are collected by the lightweight, short-term, in-memory
[metrics-server](https://github.com/kubernetes-sigs/metrics-server) and
are exposed via the `metrics.k8s.io` API.
are exposed via the `metrics.k8s.io` API.
-->
## 资源度量管道 {#resource-metrics-pipeline}
@ -58,8 +58,8 @@ These metrics are collected by the lightweight, short-term, in-memory
[Horizontal Pod Autoscaler](/zh-cn/docs/tasks/run-application/horizontal-pod-autoscale/)
控制器以及 `kubectl top` 实用程序相关的有限度量。
这些指标是由轻量级的、短期、内存存储的
[metrics-server](https://github.com/kubernetes-sigs/metrics-server) 收集
通过 `metrics.k8s.io` 公开。
[metrics-server](https://github.com/kubernetes-sigs/metrics-server) 收集,
通过 `metrics.k8s.io` 公开。
<!--
metrics-server discovers all nodes on the cluster and
@ -78,10 +78,10 @@ resource usage statistics through the metrics-server Resource Metrics API.
This API is served at `/metrics/resource/v1beta1` on the kubelet's authenticated and
read-only ports.
-->
度量服务器发现集群中的所有节点,并且查询每个节点的
metrics-server 发现集群中的所有节点,并且查询每个节点的
[kubelet](/zh-cn/docs/reference/command-line-tools-reference/kubelet/)
以获取 CPU 和内存使用情况。
Kubelet 充当 Kubernetes 主节点与节点之间的桥梁,管理机器上运行的 Pod 和容器。
kubelet 充当 Kubernetes 主节点与节点之间的桥梁,管理机器上运行的 Pod 和容器。
kubelet 将每个 Pod 转换为其组成的容器,并通过容器运行时接口从容器运行时获取各个容器使用情况统计信息。
如果某个容器运行时使用 Linux cgroups 和名字空间来实现容器。
并且这一容器运行时不发布资源用量统计信息,