{
"ipam": {
"type": "static",
"addresses": [
{
"address": "191.168.1.7/24"
}
]
}
}
以下部分提供有关如何配置二级网络的 IP 地址分配的说明和信息。
IP 地址管理 (IPAM) 容器网络接口 (CNI) 插件为其他 CNI 插件提供 IP 地址。
您可以使用以下 IP 地址分配类型
静态分配。
通过 DHCP 服务器进行动态分配。您指定的 DHCP 服务器必须可以从附加网络访问。
通过 Whereabouts IPAM CNI 插件进行动态分配。
下表描述了静态 IP 地址分配的配置
字段 | 类型 | 描述 |
---|---|---|
|
|
IPAM 地址类型。需要值为 |
|
|
指定要分配给虚拟接口的 IP 地址的对象数组。支持 IPv4 和 IPv6 IP 地址。 |
|
|
指定要在 Pod 内配置的路由的对象数组。 |
|
|
可选:指定 DNS 配置的对象数组。 |
addresses
数组需要具有以下字段的对象
字段 | 类型 | 描述 |
---|---|---|
|
|
您指定的 IP 地址和网络前缀。例如,如果您指定 |
|
|
将出站网络流量路由到的默认网关。 |
字段 | 类型 | 描述 |
---|---|---|
|
|
CIDR 格式的 IP 地址范围,例如 |
|
|
网络流量路由到的网关。 |
字段 | 类型 | 描述 |
---|---|---|
|
|
一个或多个用于发送 DNS 查询的 IP 地址数组。 |
|
|
要附加到主机名的默认域名。例如,如果域名设置为 |
|
|
在 DNS 查询期间要附加到非限定主机名(例如 |
{
"ipam": {
"type": "static",
"addresses": [
{
"address": "191.168.1.7/24"
}
]
}
}
以下 JSON 描述了使用 DHCP 进行动态 IP 地址分配的配置。
DHCP 租约续期
Pod 在创建时获取其原始 DHCP 租约。该租约必须由在集群上运行的最小 DHCP 服务器部署定期续期。 要触发 DHCP 服务器的部署,您必须通过编辑集群网络操作员配置来创建一个 shim 网络附件,如下例所示 shim 网络附件定义示例
|
字段 | 类型 | 描述 |
---|---|---|
|
|
IPAM 地址类型。需要值为 |
{
"ipam": {
"type": "dhcp"
}
}
Whereabouts CNI 插件允许将 IP 地址动态分配给附加网络,而无需使用 DHCP 服务器。
Whereabouts CNI 插件还支持重叠的 IP 地址范围以及在单独的 NetworkAttachmentDefinition
CRD 中多次配置相同的 CIDR 范围。这在多租户环境中提供了更大的灵活性和管理能力。
下表描述了使用 Whereabouts 进行动态 IP 地址分配的配置对象
字段 | 类型 | 描述 |
---|---|---|
|
|
IPAM 地址类型。需要值为 |
|
|
CIDR 表示法中的 IP 地址和范围。IP 地址将从此地址范围内分配。 |
|
|
可选:零个或多个 CIDR 表示法中的 IP 地址和范围列表。不会分配排除的地址范围内的 IP 地址。 |
|
|
可选:帮助确保每个 Pod 组或域都获得其自己的一组 IP 地址,即使它们共享相同的 IP 地址范围。设置此字段对于保持网络的独立性和组织性非常重要,尤其是在多租户环境中。 |
以下示例显示了使用 Whereabouts 的动态地址分配配置
{
"ipam": {
"type": "whereabouts",
"range": "192.0.2.192/27",
"exclude": [
"192.0.2.192/30",
"192.0.2.196/32"
]
}
}
以下示例显示了使用重叠 IP 地址范围为多租户网络进行动态 IP 地址分配。
{
"ipam": {
"type": "whereabouts",
"range": "192.0.2.192/29",
"network_name": "example_net_common", (1)
}
}
1 | 可选。如果设置,则必须与NetworkAttachmentDefinition 2 的network_name 匹配。 |
{
"ipam": {
"type": "whereabouts",
"range": "192.0.2.192/24",
"network_name": "example_net_common", (1)
}
}
1 | 可选。如果设置,则必须与NetworkAttachmentDefinition 1 的network_name 匹配。 |
Whereabouts 调解器负责使用 Whereabouts IP 地址管理 (IPAM) 解决方案管理集群内 Pod 的动态 IP 地址分配。它确保每个 Pod 从指定的 IP 地址范围获得唯一的 IP 地址。它还在 Pod 被删除或缩减规模时处理 IP 地址释放。
您还可以使用 |
当您通过集群网络运营商配置附加网络时,whereabouts-reconciler
守护程序集会自动创建。当您从 YAML 清单配置附加网络时,它不会自动创建。
要触发whereabouts-reconciler
守护程序集的部署,您必须通过编辑集群网络运营商自定义资源 (CR) 文件手动创建一个whereabouts-shim
网络附件。
请使用以下步骤部署whereabouts-reconciler
守护程序集。
通过运行以下命令编辑Network.operator.openshift.io
自定义资源 (CR)
$ oc edit network.operator.openshift.io cluster
在自定义资源 (CR) 的spec
定义中包含此示例 YAML 片段中所示的additionalNetworks
部分
apiVersion: operator.openshift.io/v1
kind: Network
metadata:
name: cluster
# ...
spec:
additionalNetworks:
- name: whereabouts-shim
namespace: default
rawCNIConfig: |-
{
"name": "whereabouts-shim",
"cniVersion": "0.3.1",
"type": "bridge",
"ipam": {
"type": "whereabouts"
}
}
type: Raw
# ...
保存文件并退出文本编辑器。
通过运行以下命令验证whereabouts-reconciler
守护程序集是否已成功部署
$ oc get all -n openshift-multus | grep whereabouts-reconciler
pod/whereabouts-reconciler-jnp6g 1/1 Running 0 6s
pod/whereabouts-reconciler-k76gg 1/1 Running 0 6s
pod/whereabouts-reconciler-k86t9 1/1 Running 0 6s
pod/whereabouts-reconciler-p4sxw 1/1 Running 0 6s
pod/whereabouts-reconciler-rvfdv 1/1 Running 0 6s
pod/whereabouts-reconciler-svzw9 1/1 Running 0 6s
daemonset.apps/whereabouts-reconciler 6 6 6 6 6 kubernetes.io/os=linux 6s
Whereabouts IPAM CNI 插件每天运行 IP 调解器。此过程会清理任何可能导致 IP 资源耗尽并因此阻止为新 Pod 分配 IP 的闲置 IP 分配。
使用此步骤更改 IP 调解器的运行频率。
您已安装 OpenShift CLI (oc
)。
您可以作为具有cluster-admin
角色的用户访问集群。
您已部署whereabouts-reconciler
守护程序集,并且whereabouts-reconciler
Pod 正在运行。
运行以下命令以在openshift-multus
命名空间中创建名为whereabouts-config
的ConfigMap
对象,其中包含 IP 调解器的特定 cron 表达式
$ oc create configmap whereabouts-config -n openshift-multus --from-literal=reconciler_cron_expression="*/15 * * * *"
此 cron 表达式表示 IP 调解器每 15 分钟运行一次。根据您的具体要求调整表达式。
|
通过运行以下命令检索与openshift-multus
命名空间中的whereabouts-reconciler
守护程序集和 Pod 相关的资源信息
$ oc get all -n openshift-multus | grep whereabouts-reconciler
pod/whereabouts-reconciler-2p7hw 1/1 Running 0 4m14s
pod/whereabouts-reconciler-76jk7 1/1 Running 0 4m14s
pod/whereabouts-reconciler-94zw6 1/1 Running 0 4m14s
pod/whereabouts-reconciler-mfh68 1/1 Running 0 4m14s
pod/whereabouts-reconciler-pgshz 1/1 Running 0 4m14s
pod/whereabouts-reconciler-xn5xz 1/1 Running 0 4m14s
daemonset.apps/whereabouts-reconciler 6 6 6 6 6 kubernetes.io/os=linux 4m16s
运行以下命令以验证whereabouts-reconciler
Pod 是否以配置的间隔运行 IP 调解器
$ oc -n openshift-multus logs whereabouts-reconciler-2p7hw
2024-02-02T16:33:54Z [debug] event not relevant: "/cron-schedule/..2024_02_02_16_33_54.1375928161": CREATE
2024-02-02T16:33:54Z [debug] event not relevant: "/cron-schedule/..2024_02_02_16_33_54.1375928161": CHMOD
2024-02-02T16:33:54Z [debug] event not relevant: "/cron-schedule/..data_tmp": RENAME
2024-02-02T16:33:54Z [verbose] using expression: */15 * * * *
2024-02-02T16:33:54Z [verbose] configuration updated to file "/cron-schedule/..data". New cron expression: */15 * * * *
2024-02-02T16:33:54Z [verbose] successfully updated CRON configuration id "00c2d1c9-631d-403f-bb86-73ad104a6817" - new cron expression: */15 * * * *
2024-02-02T16:33:54Z [debug] event not relevant: "/cron-schedule/config": CREATE
2024-02-02T16:33:54Z [debug] event not relevant: "/cron-schedule/..2024_02_02_16_26_17.3874177937": REMOVE
2024-02-02T16:45:00Z [verbose] starting reconciler run
2024-02-02T16:45:00Z [debug] NewReconcileLooper - inferred connection data
2024-02-02T16:45:00Z [debug] listing IP pools
2024-02-02T16:45:00Z [debug] no IP addresses to cleanup
2024-02-02T16:45:00Z [verbose] reconciler success
可以使用ipRanges
参数为以下情况配置双栈 IP 地址分配:
IPv4 地址
IPv6 地址
多个 IP 地址分配
将type
设置为whereabouts
。
使用ipRanges
分配 IP 地址,如下例所示
cniVersion: operator.openshift.io/v1
kind: Network
=metadata:
name: cluster
spec:
additionalNetworks:
- name: whereabouts-shim
namespace: default
type: Raw
rawCNIConfig: |-
{
"name": "whereabouts-dual-stack",
"cniVersion": "0.3.1,
"type": "bridge",
"ipam": {
"type": "whereabouts",
"ipRanges": [
{"range": "192.168.10.0/24"},
{"range": "2001:db8::/64"}
]
}
}
将网络附加到 Pod。有关更多信息,请参见“将 Pod 添加到附加网络”。
验证所有 IP 地址是否已分配。
运行以下命令以确保 IP 地址已作为元数据分配。
$ oc exec -it mypod -- ip a