本頁面說明 Google Distributed Cloud 隨附的專用網路功能 Kubernetes 運算子。這個運算子會實作一組 CustomResourceDefinitions (CRD),讓 Distributed Cloud 執行高效能工作負載。
Distributed Cloud Server 不支援網路功能運算子和 SR-IOV 功能。
網路函式運算子可讓您執行下列操作:
- 輪詢節點上的現有網路裝置。
- 查詢節點上每個網路裝置的 IP 位址和實體連結狀態。
- 在節點上佈建額外網路介面。
- 在節點的實體機器上設定低階系統功能,以支援高效能工作負載。
- 在 PCI Express 網路介面上使用單一根目錄輸入/輸出虛擬化 (SR-IOV),將其虛擬化為多個虛擬介面。然後,您可以設定 Distributed Cloud 工作負載,使用這些虛擬網路介面。
Distributed Cloud 對 SR-IOV 的支援是以下列開放原始碼專案為基礎:
必要條件
網路功能運算子會從 Distributed Cloud Edge Network API 擷取網路設定。如要允許這項操作,請使用下列指令,將 Edge Network 檢視者角色 (roles/edgenetwork.viewer) 授予網路功能運算子服務帳戶:
gcloud projects add-iam-policy-binding PROJECT_ID \ --role roles/edgenetwork.viewer \ --member "serviceAccount:PROJECT_ID.svc.id.goog[nf-operator/nf-angautomator-sa]"
將 PROJECT_ID 替換為目標 Google Cloud 專案的 ID。
網路功能運算子資源
Distributed Cloud Network Function 運算子會實作下列 Kubernetes CRD:
Network:定義 Pod 可用來與內部和外部資源通訊的虛擬網路。您必須先使用 Distributed Cloud Edge Network API 建立對應的 VLAN,才能在這個資源中指定該 VLAN。如需操作說明,請參閱「建立網路」。NetworkInterfaceState。可讓您探索網路介面狀態,並查詢網路介面的連結狀態和 IP 位址。NodeSystemConfigUpdate。可設定核心選項和Kubelet標記等低階系統功能。SriovNetworkNodePolicy. 選取一組 SR-IOV 虛擬化網路介面,並將該組介面例項化為 Kubernetes 資源。您可以在NetworkAttachmentDefinition資源中使用這項資源。SriovNetworkNodeState:可查詢 Distributed Cloud 節點上SriovNetworkNodePolicy資源的佈建狀態。NetworkAttachmentDefinition:可將 Distributed Cloud Pod 連結至 Distributed Cloud 節點上的一或多個邏輯或實體網路。您必須先使用 Distributed Cloud Edge Network API 建立對應的 VLAN,才能在這個資源中指定該 VLAN。如需操作說明,請參閱「建立網路」。
網路功能運算子也允許您定義不使用 SR-IOV 虛擬函式的次要網路介面。
Network 項資源
Network 資源會在 Distributed Cloud 機架內定義虛擬網路,Distributed Cloud 叢集內的 Pod 可使用該網路與內部和外部資源通訊。
Network 資源提供下列可設定的參數,適用於公開為可寫入欄位的網路介面:
spec.type:指定這個網路的網路傳輸層。唯一有效的值為L2。您也必須指定nodeInterfaceMatcher.interfaceName值。spec.nodeInterfaceMatcher.interfaceName:目標 Distributed Cloud 節點上實體網路介面的名稱,用於這個網路。spec.gateway4:這個網路的網路閘道 IP 位址。spec.l2NetworkConfig.prefixLength4:指定這個網路的 CIDR 範圍。
下列範例說明資源的結構:
apiVersion: networking.gke.io/v1
kind: Network
metadata:
name: vlan200-network
annotations:
networking.gke.io/gdce-vlan-id: 200
networking.gke.io/gdce-vlan-mtu: 1500
spec:
type: L2
nodeInterfaceMatcher:
interfaceName: gdcenet0.200
gateway4: 10.53.0.1
NetworkInterfaceState 項資源
NetworkInterfaceState 資源是唯讀資源,可讓您探索節點上的實體網路介面,並收集流經這些介面的網路流量執行階段統計資料。Distributed Cloud 會為叢集中的每個節點建立 NetworkInterfaceState 資源。
Distributed Cloud 機器的預設設定包含 Rack Select Network Daughter Card (rNDC) 上的繫結網路介面,名稱為 gdcenet0。這個介面會連結 eno1np0 和 eno2np1 網路介面。每個伺服器分別連接至一個 Distributed Cloud ToR 交換器。
NetworkInterfaceState 資源提供下列類別的網路介面資訊,這些資訊會顯示為唯讀狀態欄位。
一般資訊:
status.interfaces.ifname:目標網路介面的名稱。status.lastReportTime:目標介面的最後一份狀態報告時間和日期。
IP 位址設定資訊:
status.interfaces.interfaceinfo.address:指派給目標介面的 IP 位址。status.interfaces.interfaceinfo.dns:指派給目標介面的 DNS 伺服器 IP 位址。status.interfaces.interfaceinfo.gateway:為目標介面提供服務的網路閘道 IP 位址。status.interfaces.interfaceinfo.prefixlen:IP 前置字元的長度。
硬體資訊:
status.interfaces.linkinfo.broadcast:目標介面的廣播 MAC 位址。status.interfaces.linkinfo.businfo:PCIe 裝置路徑,格式為bus:slot.function。status.interfaces.linkinfo.flags:介面旗標,例如BROADCAST。status.interfaces.linkinfo.macAddress:目標介面的單點傳播 MAC 位址。status.interfaces.linkinfo.mtu:目標介面的 MTU 值。
接收統計資料:
status.interfaces.statistics.rx.bytes:目標介面接收的總位元組數。status.interfaces.statistics.rx.dropped:目標介面捨棄的封包總數。status.interfaces.statistics.rx.errors:目標介面的封包接收錯誤總數。status.interfaces.statistics.rx.multicast:目標介面收到的多點傳送封包總數。status.interfaces.statistics.rx.overErrors:目標介面接收的封包總數 (包括錯誤)。status.interfaces.statistics.rx.packets:目標介面收到的封包總數。
傳輸統計資料:
status.interfaces.statistics.tx.bytes:目標介面傳輸的總位元組數。status.interfaces.statistics.tx.carrierErrors:目標介面遇到的載波錯誤總數。status.interfaces.statistics.tx.collisions:目標介面遇到的封包衝突總數。status.interfaces.statistics.tx.dropped:目標介面捨棄的封包總數。status.interfaces.statistics.tx.errors:目標介面的傳輸錯誤總數。status.interfaces.statistics.tx.packets:目標介面傳輸的封包總數。
下列範例說明資源的結構:
apiVersion: networking.gke.io/v1
kind: NetworkInterfaceState
metadata:
name: MyNode1
nodeName: MyNode1
status:
interfaces:
- ifname: eno1np0
linkinfo:
businfo: 0000:1a:00.0
flags: up|broadcast|multicast
macAddress: ba:16:03:9e:9c:87
mtu: 9000
statistics:
rx:
bytes: 1098522811
errors: 2
multicast: 190926
packets: 4988200
tx:
bytes: 62157709961
packets: 169847139
- ifname: eno2np1
linkinfo:
businfo: 0000:1a:00.1
flags: up|broadcast|multicast
macAddress: ba:16:03:9e:9c:87
mtu: 9000
statistics:
rx:
bytes: 33061895405
multicast: 110203
packets: 110447356
tx:
bytes: 2370516278
packets: 11324730
- ifname: enp95s0f0np0
interfaceinfo:
- address: fe80::63f:72ff:fec4:2bf4
prefixlen: 64
linkinfo:
businfo: 0000:5f:00.0
flags: up|broadcast|multicast
macAddress: 04:3f:72:c4:2b:f4
mtu: 9000
statistics:
rx:
bytes: 37858381
multicast: 205645
packets: 205645
tx:
bytes: 1207334
packets: 6542
- ifname: enp95s0f1np1
interfaceinfo:
- address: fe80::63f:72ff:fec4:2bf5
prefixlen: 64
linkinfo:
businfo: 0000:5f:00.1
flags: up|broadcast|multicast
macAddress: 04:3f:72:c4:2b:f5
mtu: 9000
statistics:
rx:
bytes: 37852406
multicast: 205607
packets: 205607
tx:
bytes: 1207872
packets: 6545
- ifname: enp134s0f0np0
interfaceinfo:
- address: fe80::63f:72ff:fec4:2b6c
prefixlen: 64
linkinfo:
businfo: 0000:86:00.0
flags: up|broadcast|multicast
macAddress: 04:3f:72:c4:2b:6c
mtu: 9000
statistics:
rx:
bytes: 37988773
multicast: 205584
packets: 205584
tx:
bytes: 1212385
packets: 6546
- ifname: enp134s0f1np1
interfaceinfo:
- address: fe80::63f:72ff:fec4:2b6d
prefixlen: 64
linkinfo:
businfo: 0000:86:00.1
flags: up|broadcast|multicast
macAddress: 04:3f:72:c4:2b:6d
mtu: 9000
statistics:
rx:
bytes: 37980702
multicast: 205548
packets: 205548
tx:
bytes: 1212297
packets: 6548
- ifname: gdcenet0
interfaceinfo:
- address: 208.117.254.36
prefixlen: 28
- address: fe80::b816:3ff:fe9e:9c87
prefixlen: 64
linkinfo:
flags: up|broadcast|multicast
macAddress: ba:16:03:9e:9c:87
mtu: 9000
statistics:
rx:
bytes: 34160422968
errors: 2
multicast: 301129
packets: 115435591
tx:
bytes: 64528301111
packets: 181171964
.. <remaining interfaces omitted>
lastReportTime: "2022-03-30T07:35:44Z"
NodeSystemConfigUpdate 項資源
您可以使用 NodeSystemConfigUpdate 資源變更節點的作業系統設定,以及修改 Kubelet 標記。除了 sysctl 變更之外,其他變更都需要重新啟動節點。
例項化這項資源時,您必須在 nodeSelector 欄位中指定目標節點。您必須在 nodeSelector 欄位中,為每個目標節點加入所有鍵/值組合。如果在這個欄位中指定多個目標節點,系統會一次更新一個目標節點。
注意:nodeName 欄位已淘汰,立即使用會重新啟動目標節點,包括本機控制層節點,這可能會停止重要工作負載。
NodeSystemConfigUpdate 資源提供下列 Distributed Cloud 專屬的設定欄位:
spec.containerRuntimeDNSConfig.ip:指定私人映像檔登錄檔的 IP 位址清單。spec.containerRuntimeDNSConfig:指定 Container Runtime Environment 在每個 Distributed Cloud 節點上使用的自訂 DNS 項目清單。每個項目都包含下列欄位:ip:指定目標 IPv4 位址,domain:指定對應網域,interface:指定網路輸出介面,透過該介面可連線至ip欄位中指定的 IP 位址。您可以指定透過下列資源定義的介面:CustomNetworkInterfaceConfig、Network(透過註解)、NetworkAttachmentDefinition(透過註解)。這項功能為預先發布版。
spec.kubeletConfig.cpuManagerPolicy:指定 Kubernetes CPUManager 政策。有效值為None和Static。spec.kubeletConfig.topologyManagerPolicy:指定 Kubernetes TopologyManager 政策。有效值為None、BestEffort、Restricted和SingleNumaMode。spec.osConfig.hugePagesConfig:指定每個 NUMA 節點的巨頁設定。有效值為2MB和1GB。系統會將要求的大頁面數量平均分配到兩個 NUMA 節點。舉例來說,如果您配置 16 個巨頁,每個巨頁為 1 GB,則每個節點會預先配置 8 GB。spec.osConfig.isolatedCpusPerSocket:指定每個插槽的隔離 CPU 數量。如果cpuManagerPolicy設為Static,則為必要屬性。隔離 CPU 數量上限必須少於節點中 CPU 總數的 80%。spec.osConfig.cpuIsolationPolicy:指定 CPU 隔離政策。Default政策只會將systemd工作與為工作負載保留的 CPU 隔離。Kernel政策會將 CPU 標示為isolcpus,並在每個 CPU 上設定rcu_nocb、nohz_full和rcu_nocb_poll標記。spec.sysctls.NodeLevel:指定您可以使用 Network Function 運算子,在節點上全域設定的sysctls參數。可設定的參數如下:fs.inotify.max_user_instancesfs.inotify.max_user_watcheskernel.sched_rt_runtime_uskernel.core_patternnet.ipv4.tcp_wmemnet.ipv4.tcp_rmemnet.ipv4.tcp_slow_start_after_idlenet.ipv4.udp_rmem_minnet.ipv4.udp_wmem_minnet.ipv4.tcp_rmemnet.ipv4.tcp_wmemnet.core.rmem_maxnet.core.wmem_maxnet.core.rmem_defaultnet.core.wmem_defaultnet.netfilter.nf_conntrack_tcp_timeout_unacknowledgednet.netfilter.nf_conntrack_tcp_timeout_max_retransnet.sctp.auth_enablenet.sctp.sctp_memnet.ipv4.udp_memnet.ipv4.tcp_memnet.ipv4.tcp_slow_start_after_idlenet.sctp.auth_enablevm.max_map_count
您也可以使用
tuning容器網路介面 (CNI) 外掛程式,將安全和不安全的sysctls參數範圍限定在特定 Pod 或命名空間。
NodeSystemConfigUpdate 資源提供下列唯讀一般狀態欄位:
status.lastReportTime:目標介面最近一次回報狀態的時間。status.conditions.lastTransitionTime:介面狀態最近一次變更的時間。status.conditions.observedGeneration:表示初始條件所依據的.metadata.generation值。status.conditions.message:說明介面狀態變更的資訊訊息。status.conditions.reason:程式化 ID,表示介面狀態上次變更的原因。status.conditions.status:條件的狀態描述符。有效值為True、False和Unknown。status.conditions.type:以 camelCase 格式表示的條件類型。
下列範例說明資源的結構:
apiVersion: networking.gke.io/v1
kind: NodeSystemConfigUpdate
metadata:
name: node-pool-1-config
namespace: default
spec:
nodeSelector:
baremetal.cluster.gke.io/node-pool: node-pool-1
networking.gke.io/worker-network-sriov.capable: true
sysctls:
nodeLevel:
"net.ipv4.udp_mem" : "12348035 16464042 24696060"
kubeletConfig:
topologyManagerPolicy: BestEffort
cpuManagerPolicy: Static
osConfig:
hugePagesConfig:
"TWO_MB": 0
"ONE_GB": 16
isolatedCpusPerSocket:
"0": 10
"1": 10
SriovNetworkNodePolicy 項資源
SriovNetworkNodePolicy 資源可讓您在 Distributed Cloud 實體機器上分配一組 SR-IOV 虛擬函式 (VF),並將該組函式例項化為 Kubernetes 資源。接著,您可以在 NetworkAttachmentDefinition 資源中使用這項資源。
您可以依據每個目標 VF 的 PCIe 供應商和裝置 ID、PCIe 裝置位址,或 Linux 列舉的裝置名稱選取目標 VF。SR-IOV 網路運算子會設定每個實體網路介面,以佈建目標 VF。包括更新網路介面韌體、設定 Linux 核心驅動程式,以及視需要重新啟動 Distributed Cloud 機器。
如要探索節點上可用的網路介面,請在 nf-operator 命名空間中,查詢該節點上的 NetworkInterfaceState 資源。
下列範例說明資源的結構:
apiVersion: sriovnetwork.k8s.cni.cncf.io/v1
kind: SriovNetworkNodePolicy
metadata:
name: mlnx6-p2-sriov-en2
namespace: sriov-network-operator
spec:
deviceType: netdevice
isRdma: true
mtu: 9000
nicSelector:
pfNames:
- enp134s0f1np1
nodeSelector:
edgecontainer.googleapis.com/network-sriov.capable: "true"
numVfs: 31
priority: 99
resourceName: mlnx6_p2_sriov_en2
上述範例會從名為 enp134s0f1np1 的網路介面上的第二個連接埠,建立最多 31 個 VF,MTU 值為 9000 (允許的最大值)。使用節點選取器標籤 edgecontainer.googleapis.com/network-sriov.capable,這個標籤會出現在所有支援 SR-IOV 的 Distributed Cloud 節點上。
如要瞭解如何使用這項資源,請參閱 SriovNetworkNodeState。
SriovNetworkNodeState 項資源
您可以使用 SriovNetworkNodeState 唯讀資源,查詢 Distributed Cloud 節點上 SriovNetworkNodePolicy 資源的佈建狀態。這個方法會傳回節點上 SriovNetworkNodePolicy 資源的完整設定,以及節點上作用中的 VF 清單。status.syncStatus 欄位會指出為節點定義的所有 SriovNetworkNodePolicy 資源是否已正確套用。
下列範例說明資源的結構:
apiVersion: sriovnetwork.k8s.cni.cncf.io/v1
kind: SriovNetworkNodeState
metadata:
name: MyNode1
namespace: sriov-network-operator
spec:
dpConfigVersion: "1969684"
interfaces:
- mtu: 9000
name: enp134s0f1np1
numVfs: 31
pciAddress: 0000:86:00.1
vfGroups:
- deviceType: netdevice
mtu: 9000
policyName: mlnx6-p2-sriov-en2
resourceName: mlnx6_p2_sriov_en2
vfRange: 0-30
status:
Status:
Interfaces:
Device ID: 1015
Driver: mlx5_core
Link Speed: 25000 Mb/s
Link Type: ETH
Mac: ba:16:03:9e:9c:87
Mtu: 9000
Name: eno1np0
Pci Address: 0000:1a:00.0
Vendor: 15b3
Device ID: 1015
Driver: mlx5_core
Link Speed: 25000 Mb/s
Link Type: ETH
Mac: ba:16:03:9e:9c:87
Mtu: 9000
Name: eno2np1
Pci Address: 0000:1a:00.1
Vendor: 15b3
Vfs:
- Vfs:
- deviceID: 101e
driver: mlx5_core
mac: c2:80:29:b5:63:55
mtu: 9000
name: enp134s0f1v0
pciAddress: 0000:86:04.1
vendor: 15b3
vfID: 0
- deviceID: 101e
driver: mlx5_core
mac: 7e:36:0c:82:d4:20
mtu: 9000
name: enp134s0f1v1
pciAddress: 0000:86:04.2
vendor: 15b3
vfID: 1
.. <omitted 29 other VFs here>
syncStatus: Succeeded
如要瞭解如何使用這項資源,請參閱 SriovNetworkNodeState。
NetworkAttachmentDefinition 項資源
NetworkAttachmentDefinition 資源可讓您將 Distributed Cloud Pod 連接至 Distributed Cloud 節點上的一或多個邏輯或實體網路。這項功能採用 Multus-CNI 架構和 SRIOV-CNI 外掛程式。
使用註解參照適當 SriovNetworkNodePolicy 資源的名稱。建立註解時,請執行下列操作:
- 使用
k8s.v1.cni.cncf.io/resourceName鍵。 - 在其值中使用
gke.io/前置字元,後面接著目標SriovNetworkNodePolicy資源的名稱。
下列範例說明資源的結構:
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: sriov-net1
namespace: mynamespace
annotations:
k8s.v1.cni.cncf.io/resourceName: gke.io/mlnx6_p2_sriov_en2
spec:
config: '{
"type": "sriov",
"cniVersion": "0.3.1",
"name": "sriov-network",
"ipam": {
"type": "host-local",
"subnet": "10.56.217.0/24",
"routes": [{
"dst": "0.0.0.0/0"
}],
"gateway": "10.56.217.1"
}
}'
將 NetworkAttachmentDefinition 資源升級至 Distributed Cloud 1.4.0
Distributed Cloud 1.4.0 版會以名為 gdcenet0 的新介面,取代 bond0 介面。透過 gdcenet0 介面,您可以在機架中每部 Distributed Cloud 機器使用主機管理網路介面卡 (NIC),處理工作負載,同時完全區隔 Distributed Cloud 管理和控制層網路流量。如要使用這項功能,請完成本節的步驟,重新設定 NetworkAttachmentDefinition 資源,然後按照「設定 Distributed Cloud 網路」中的操作說明,佈建適當的網路和子網路。
針對您已部署一或多個 NetworkAttachmentDefinition 資源的每個 Distributed Cloud 叢集,適用下列遷移規則:
- 對於每個新的
NetworkAttachmentDefinition資源,請使用gdcenet0,而非bond0做為master欄位的值。如果您套用資源,並為這個欄位使用bond0或空白值,Distributed Cloud 會將值替換為gdcenet0,然後儲存資源並套用至叢集。 - 針對每個現有的
NetworkAttachmentDefinition資源,將bond0取代為gdcenet0做為master欄位的值,然後將資源重新套用至叢集,以還原受影響 Pod 的完整網路連線。
如要瞭解如何使用這項資源,請參閱 NetworkAttachmentDefinition。
使用 SR-IOV VF 在 Pod 上設定次要介面
設定 SriovNetworkNodePolicy 資源和對應的 NetworkAttachmentDefinition 資源後,您可以使用 SR-IOV 虛擬函式,在 Distributed Cloud Pod 上設定次要網路介面。
如要這麼做,請在 Distributed Cloud Pod 定義中新增註解,如下所示:
- 鍵:
k8s.v1.cni.cncf.io/networks - 值:
nameSpace/<NetworkAttachmentDefinition1,nameSpace/NetworkAttachmentDefinition2...
以下範例說明這項註解:
apiVersion: v1
kind: Pod
metadata:
name: sriovpod
annotations:
k8s.v1.cni.cncf.io/networks: mynamespace/sriov-net1
spec:
containers:
- name: sleeppodsriov
command: ["sh", "-c", "trap : TERM INT; sleep infinity & wait"]
image: alpine
securityContext:
capabilities:
add:
- NET_ADMIN
使用 MacVLAN 驅動程式在 Pod 上設定次要介面
Distributed Cloud 也支援使用 MacVLAN 驅動程式,在 Pod 上建立次要網路介面。只有 gdcenet0 介面支援這項設定,且僅適用於執行容器化工作負載的 Pod。
如要設定介面以使用 MacVLAN 驅動程式,請按照下列步驟操作:
設定
NetworkAttachmentDefinition資源,如以下範例所示:apiVersion: "k8s.cni.cncf.io/v1" kind: NetworkAttachmentDefinition metadata: name: macvlan-b400-1 annotations: networking.gke.io/gdce-vlan-id: 400 spec: config: '{ "type": "macvlan", "master": "gdcenet0.400", "ipam": { "type": "static", "addresses": [ { "address": "192.168.100.20/27", "gateway": "192.168.100.1" } ] ... } }'在 Distributed Cloud Pod 定義中新增註解,如下所示:
apiVersion: v1 kind: Pod metadata: name: macvlan-testpod1 annotations: k8s.v1.cni.cncf.io/networks: macvlan-b400-1
使用 Distributed Cloud 多重網路功能,在 Pod 上設定次要介面
Distributed Cloud 支援使用多網路功能,在 Pod 上建立次要網路介面。如要這樣做,請完成下列步驟:
設定
Network資源。例如:apiVersion: networking.gke.io/v1 kind: Network metadata: name: vlan200-network spec: type: L2 nodeInterfaceMatcher: interfaceName: vlan200-interface gateway4: 10.53.0.1在 Distributed Cloud Pod 定義中新增註解,如下所示:
apiVersion: v1 kind: Pod metadata: name: myPod annotations: networking.gke.io/interfaces: [{"interfaceName":"eth1","network":"vlan200-network"}] networking.gke.io/default-interface: eth1 ...後續步驟