部署并验证 GKE NFO 多网络和;高性能接口

关于此 Codelab
schedule91 分钟
subject上次更新时间:2023年8月15日
account_circleDeepak Michael 编写

GCP 长期以来在虚拟机实例级别支持多个接口。通过多接口,一个虚拟机最多可以将 7 个新接口(默认为 7 个接口)连接到不同的 VPC。GKE 网络现在将此行为扩展到在节点上运行的 Pod。在此功能推出之前,GKE 集群允许所有节点池只有一个接口,因此可映射到单个 VPC。借助 Pod 上的多网络功能,用户现在可以在节点上以及 GKE 集群中的 Pod 上启用多个接口。

在本教程中,您将构建一个全面的 GKE Multinic 环境,用于说明图 1 中所示的用例。

  1. 利用 Mission 创建 netdevice-l3-pod,以便:
  2. 执行 PING 和通过 eth2 将 wget -S 发送到 netdevice-vpc 中的 netdevice-apache 实例
  3. 执行 PING 和通过 eth1 将 wget -S 复制到 l3-vpc 中的 l3-apache 实例
  4. 创建一个 l3-pod,利用 GCP 执行 PING 和通过 eth1 将 wget -S 复制到 l3-apache 实例

在这两个用例中,Pod 的 eth0 接口都连接到默认网络。

图 1

9d93019ee608587f

学习内容

  • 如何创建 l3 类型子网
  • 如何创建 netdevice type 子网
  • 如何建立多 NIC GKE 节点池
  • 如何创建具有 netdevice 和 l3 功能的 Pod
  • 如何创建具有 L3 功能的 Pod
  • 如何创建和验证 GKE 对象网络
  • 如何使用 PING、wget 和防火墙日志验证与远程 Apache 服务器的连接

所需条件

  • Google Cloud 项目

2. 术语和概念

主要 VPC:主要 VPC 是预配置的 VPC,包含一组默认设置和资源。GKE 集群就是在此 VPC 中创建的。

子网:在 Google Cloud 中,子网是在 VPC 中创建具有网络掩码的无类别域间路由 (CIDR) 的方式。子网有一个分配给节点的主要 IP 地址范围,并且可以有多个属于 Pod 和 Service 的次要范围。

节点网络:节点网络是指 VPC 和子网对的专用组合。在此节点网络中,系统会为属于节点池的节点分配主要 IP 地址范围中的 IP 地址。

次要范围:Google Cloud 次要范围是属于 VPC 中区域的 CIDR 和网络掩码。GKE 会将它用作第 3 层 Pod 网络。一个 VPC 可以有多个次要范围,并且一个 Pod 可以连接到多个 Pod 网络。

网络(L3 或设备):充当 Pod 连接点的 Network 对象。在本教程中,网络为 l3-network 和 netdevice-network,其中设备可以是 netdevice 或 dpdk。默认网络是必需的,基于默认节点池子网在集群创建时创建。

第 3 层网络对应于子网上的次要范围,表示为:

VPC ->子网名称 ->次要范围名称

设备网络对应于 VPC 上的子网,表示为:

VPC ->子网名称

默认 Pod 网络:Google Cloud 会在集群创建期间创建一个默认的 Pod 网络。默认 Pod 网络使用主 VPC 作为节点网络。默认情况下,默认 Pod 网络适用于所有集群节点和 Pod。

具有多个接口的 Pod:在 GKE 中具有多个接口的 Pod 无法连接到同一个 Pod 网络,因为 Pod 的每个接口都必须连接到唯一的网络。

更新项目以支持此 Codelab

此 Codelab 利用 $variables 辅助在 Cloud Shell 中实现 gcloud 配置。

在 Cloud Shell 中,执行以下操作:

gcloud config list project
gcloud config
set project [YOUR-PROJECT-NAME]
projectid
=YOUR-PROJECT-NAME
echo $projectid

3. 主要 VPC 设置

创建主 VPC

在 Cloud Shell 中,执行以下操作:

gcloud compute networks create primary-vpc --project=$projectid --subnet-mode=custom

创建节点和次要子网

在 Cloud Shell 中,执行以下操作:

gcloud compute networks subnets create primary-node-subnet --project=$projectid --range=192.168.0.0/24 --network=primary-vpc --region=us-central1 --enable-private-ip-google-access --secondary-range=sec-range-primay-vpc=10.0.0.0/21

4. 创建 GKE 集群

创建指定主 VPC 子网的专用 GKE 集群,以创建带有必需标志“enable-multi-networking”和“-enable-dataplane-v2”的默认节点池,以支持多 NIC 节点池。

在 Cloud Shell 中,创建 GKE 集群:

gcloud container clusters create multinic-gke \
   
--zone "us-central1-a" \
   
--enable-dataplane-v2 \
   
--enable-ip-alias \
   
--enable-multi-networking \
   
--network "primary-vpc" --subnetwork "primary-node-subnet" \
   
--num-nodes=2 \
   
--max-pods-per-node=32 \
   
--cluster-secondary-range-name=sec-range-primay-vpc \
   
--no-enable-master-authorized-networks \
   
--release-channel "regular" \
   
--enable-private-nodes --master-ipv4-cidr "100.100.10.0/28" \
   
--enable-ip-alias

验证 multinic-gke 集群

在 Cloud Shell 中,向集群进行身份验证:

gcloud container clusters get-credentials multinic-gke --zone us-central1-a --project $projectid

在 Cloud Shell 中,验证默认池生成了两个节点:

kubectl get nodes

示例:

user@$ kubectl get nodes
NAME                                          STATUS   ROLES    AGE    VERSION
gke
-multinic-gke-default-pool-3d419e48-1k2p   Ready    <none>   2m4s   v1.27.3-gke.100
gke
-multinic-gke-default-pool-3d419e48-xckb   Ready    <none>   2m4s   v1.27.3-gke.100

5. netdevice-vpc 设置

创建 netdevice-vpc 网络

在 Cloud Shell 中,执行以下操作:

gcloud compute networks create netdevice-vpc --project=$projectid --subnet-mode=custom

创建 netdevice-vpc 子网

在 Cloud Shell 中,创建用于多 netdevice-network 的子网:

gcloud compute networks subnets create netdevice-subnet --project=$projectid --range=192.168.10.0/24 --network=netdevice-vpc --region=us-central1 --enable-private-ip-google-access

在 Cloud Shell 中,为 netdevice-apache 实例创建一个子网:

gcloud compute networks subnets create netdevice-apache --project=$projectid --range=172.16.10.0/28 --network=netdevice-vpc --region=us-central1 --enable-private-ip-google-access

Cloud Router 和 NAT 配置

由于虚拟机实例没有外部 IP 地址,因此本教程使用 Cloud NAT 安装软件包。

在 Cloud Shell 中,创建 Cloud Router 路由器。

gcloud compute routers create netdevice-cr --network netdevice-vpc --region us-central1

在 Cloud Shell 中,创建 NAT 网关。

gcloud compute routers nats create cloud-nat-netdevice --router=netdevice-cr --auto-allocate-nat-external-ips --nat-all-subnet-ip-ranges --region us-central1

创建 netdevice-apache 实例

在下一部分,您将创建 netdevice-apache 实例。

在 Cloud Shell 中,创建实例:

gcloud compute instances create netdevice-apache \
   
--project=$projectid \
   
--machine-type=e2-micro \
   
--image-family debian-11 \
   
--no-address \
   
--image-project debian-cloud \
   
--zone us-central1-a \
   
--subnet=netdevice-apache \
   
--metadata startup-script="#! /bin/bash
      sudo apt-get update
      sudo apt-get install apache2 -y
      sudo service apache2 restart
      echo 'Welcome to the netdevice-apache instance !!' | tee /var/www/html/index.html
      EOF"

6. l3-VPC 设置

创建 l3-vpc 网络

在 Cloud Shell 中,执行以下操作:

gcloud compute networks create l3-vpc --project=$projectid --subnet-mode=custom

创建 l3-vpc 子网

在 Cloud Shell 中,创建主要范围和次要范围子网。次级范围(sec-range-l3-subnet) 用于多 NIC l3 网络:

gcloud compute networks subnets create l3-subnet --project=$projectid --range=192.168.20.0/24 --network=l3-vpc --region=us-central1 --enable-private-ip-google-access --secondary-range=sec-range-l3-subnet=10.0.8.0/21

在 Cloud Shell 中,为 l3-apache 实例创建一个子网:

gcloud compute networks subnets create l3-apache --project=$projectid --range=172.16.20.0/28 --network=l3-vpc --region=us-central1 --enable-private-ip-google-access

Cloud Router 和 NAT 配置

由于虚拟机实例没有外部 IP 地址,因此本教程使用 Cloud NAT 安装软件包。

在 Cloud Shell 中,创建 Cloud Router 路由器。

gcloud compute routers create l3-cr --network l3-vpc --region us-central1

在 Cloud Shell 中,创建 NAT 网关。

gcloud compute routers nats create cloud-nat-l3 --router=l3-cr --auto-allocate-nat-external-ips --nat-all-subnet-ip-ranges --region us-central1

创建 l3-apache 实例

在下一部分,您将创建 l3-apache 实例。

在 Cloud Shell 中,创建实例:

gcloud compute instances create l3-apache \
   
--project=$projectid \
   
--machine-type=e2-micro \
   
--image-family debian-11 \
   
--no-address \
   
--image-project debian-cloud \
   
--zone us-central1-a \
   
--subnet=l3-apache \
   
--metadata startup-script="#! /bin/bash
      sudo apt-get update
      sudo apt-get install apache2 -y
      sudo service apache2 restart
      echo 'Welcome to the l3-apache instance !!' | tee /var/www/html/index.html
      EOF"

7. 创建多 NIC 节点池

在下一部分中,您将创建包含以下标志的多网络节点池:

-additional-node-network(对于设备类型接口是必需的)

示例:

--additional-node-network network=netdevice-vpc,subnetwork=netdevice-subnet

-additional-node-network 和–additional-pod-network(L3 类型接口的必需项)

示例:

--additional-node-network network=l3-vpc,subnetwork=l3-subnet --additional-pod-network subnetwork=l3-subnet,pod-ipv4-range=sec-range-l3-subnet,max-pods-per-node=8

机器类型:部署节点池时,请考虑机器类型依赖项。例如,类似于“e2-standard-4”的机器类型具有 4 个 vCPU 的 VPC 最多可支持 4 个 VPC。例如,netdevice-l3-pod 总共有 3 个接口(默认接口、netdevice 和 l3),因此本教程中使用的机器类型是 e2-standard-4。

在 Cloud Shell 中,创建由设备类型和 L3 组成的节点池:

gcloud container --project "$projectid" node-pools create "multinic-node-pool" --cluster "multinic-gke" --zone "us-central1-a" --additional-node-network network=netdevice-vpc,subnetwork=netdevice-subnet --additional-node-network network=l3-vpc,subnetwork=l3-subnet --additional-pod-network subnetwork=l3-subnet,pod-ipv4-range=sec-range-l3-subnet,max-pods-per-node=8 --machine-type "e2-standard-4"

8. 验证 multnic-node-pool

在 Cloud Shell 中,验证 multinic-node-pool 生成了三个节点:

kubectl get nodes

示例:

user@$ kubectl get nodes
NAME                                                STATUS   ROLES    AGE     VERSION
gke
-multinic-gke-default-pool-3d419e48-1k2p         Ready    <none>   15m     v1.27.3-gke.100
gke
-multinic-gke-default-pool-3d419e48-xckb         Ready    <none>   15m     v1.27.3-gke.100
gke
-multinic-gke-multinic-node-pool-135699a1-0tfx   Ready    <none>   3m51s   v1.27.3-gke.100
gke
-multinic-gke-multinic-node-pool-135699a1-86gz   Ready    <none>   3m51s   v1.27.3-gke.100
gke
-multinic-gke-multinic-node-pool-135699a1-t66p   Ready    <none>   3m51s   v1.27.3-gke.100

9. 创建 netdevice-network

在以下步骤中,您将生成 Network 和 GKENetworkParamSet kubernetes 对象,以创建用于在后续步骤中关联 Pod 的 netdevice-network。

创建 netdevice-network 对象

在 Cloud Shell 中,使用 VI 编辑器或 nano 创建网络对象 YAML netdevice-network.yaml。请注意“路由至”是 netdevice-vpc 中的子网 172.16.10.0/28 (netdevice-apache)。

apiVersion: networking.gke.io/v1
kind
: Network
metadata
:
    name
: netdevice-network
spec
:
    type
: "Device"
    parametersRef
:
     
group: networking.gke.io
      kind
: GKENetworkParamSet
      name
: "netdevice"
    routes
:
   
- to: "172.16.10.0/28"

在 Cloud Shell 中,应用 netdevice-network.yaml:

kubectl apply -f netdevice-network.yaml 

在 Cloud Shell 中,验证 netdevice-network 状态类型为“就绪”。

kubectl describe networks netdevice-network

示例:

user@$ kubectl describe networks netdevice-network
Name:         netdevice-network
Namespace:    
Labels:       <none>
Annotations:  networking.gke.io/in-use: false
API
Version:  networking.gke.io/v1
Kind:         Network
Metadata:
 
Creation Timestamp:  2023-07-30T22:37:38Z
 
Generation:          1
 
Resource Version:    1578594
  UID
:                 46d75374-9fcc-42be-baeb-48e074747052
Spec:
 
Parameters Ref:
   
Group:  networking.gke.io
   
Kind:   GKENetworkParamSet
   
Name:   netdevice
 
Routes:
   
To:  172.16.10.0/28
 
Type:  Device
Status:
 
Conditions:
   
Last Transition Time:  2023-07-30T22:37:38Z
   
Message:               GKENetworkParamSet resource was deleted: netdevice
   
Reason:                GNPDeleted
   
Status:                False
   
Type:                  ParamsReady
   
Last Transition Time:  2023-07-30T22:37:38Z
   
Message:               Resource referenced by params is not ready
   
Reason:                ParamsNotReady
   
Status:                False
   
Type:                  Ready
Events:                    <none>

创建 GKENetworkParamSet

在 Cloud Shell 中,使用 VI 编辑器或 nano 创建网络对象 YAML netdevice-network-parm.yaml。该规范会映射到 netdevice-vpc 子网部署。

apiVersion: networking.gke.io/v1
kind
: GKENetworkParamSet
metadata
:
    name
: "netdevice"
spec
:
    vpc
: "netdevice-vpc"
    vpcSubnet
: "netdevice-subnet"
    deviceMode
: "NetDevice"

在 Cloud Shell 中,应用 netdevice-network-parm.yaml

kubectl apply -f netdevice-network-parm.yaml 

在 Cloud Shell 中,验证 netdevice-network 状态原因 GNPParmsReady 和 NetworkReady:

kubectl describe networks netdevice-network

示例:

user@$ kubectl describe networks netdevice-network
Name:         netdevice-network
Namespace:    
Labels:       <none>
Annotations:  networking.gke.io/in-use: false
API
Version:  networking.gke.io/v1
Kind:         Network
Metadata:
 
Creation Timestamp:  2023-07-30T22:37:38Z
 
Generation:          1
 
Resource Version:    1579791
  UID
:                 46d75374-9fcc-42be-baeb-48e074747052
Spec:
 
Parameters Ref:
   
Group:  networking.gke.io
   
Kind:   GKENetworkParamSet
   
Name:   netdevice
 
Routes:
   
To:  172.16.10.0/28
 
Type:  Device
Status:
 
Conditions:
   
Last Transition Time:  2023-07-30T22:39:44Z
   
Message:              
   
Reason:                GNPParamsReady
   
Status:                True
   
Type:                  ParamsReady
   
Last Transition Time:  2023-07-30T22:39:44Z
   
Message:              
   
Reason:                NetworkReady
   
Status:                True
   
Type:                  Ready
Events:                    <none>

在 Cloud Shell 中,在后续步骤中验证用于 Pod 接口的 gkenetworkparamset CIDR 地址块 192.168.10.0/24。

kubectl describe gkenetworkparamsets.networking.gke.io netdevice

示例:

user@$ kubectl describe gkenetworkparamsets.networking.gke.io netdevice
Name:         netdevice
Namespace:    
Labels:       <none>
Annotations:  <none>
API
Version:  networking.gke.io/v1
Kind:         GKENetworkParamSet
Metadata:
 
Creation Timestamp:  2023-07-30T22:39:43Z
 
Finalizers:
    networking
.gke.io/gnp-controller
    networking
.gke.io/high-perf-finalizer
 
Generation:        1
 
Resource Version:  1579919
  UID
:               6fe36b0c-0091-4b6a-9d28-67596cbce845
Spec:
 
Device Mode:  NetDevice
 
Vpc:          netdevice-vpc
 
Vpc Subnet:   netdevice-subnet
Status:
 
Conditions:
   
Last Transition Time:  2023-07-30T22:39:43Z
   
Message:              
   
Reason:                GNPReady
   
Status:                True
   
Type:                  Ready
 
Network Name:            netdevice-network
 
Pod CID Rs:
   
Cidr Blocks:
     
192.168.10.0/24
Events:  <none>

10. 创建 l3 网络

在以下步骤中,您将生成 Network 和 GKENetworkParamSet kubernetes 对象,以创建用于在后续步骤中关联 Pod 的 l3 网络。

创建 l3 网络对象

在 Cloud Shell 中,使用 VI 编辑器或 nano 创建网络对象 YAML l3-network.yaml。请注意“路由至”是 l3-vpc 中的子网 172.16.20.0/28 (l3-apache)。

apiVersion: networking.gke.io/v1
kind
: Network
metadata
:
  name
: l3-network
spec
:
  type
: "L3"
  parametersRef
:
   
group: networking.gke.io
    kind
: GKENetworkParamSet
    name
: "l3-network"
  routes
:
 
- to: "172.16.20.0/28"

在 Cloud Shell 中,应用 l3-network.yaml:

kubectl apply -f l3-network.yaml 

在 Cloud Shell 中,验证 l3 网络的状态类型为“准备就绪”。

kubectl describe networks l3-network

示例:

user@$ kubectl describe networks l3-network
Name:         l3-network
Namespace:    
Labels:       <none>
Annotations:  networking.gke.io/in-use: false
API
Version:  networking.gke.io/v1
Kind:         Network
Metadata:
 
Creation Timestamp:  2023-07-30T22:43:54Z
 
Generation:          1
 
Resource Version:    1582307
  UID
:                 426804be-35c9-4cc5-bd26-00b94be2ef9a
Spec:
 
Parameters Ref:
   
Group:  networking.gke.io
   
Kind:   GKENetworkParamSet
   
Name:   l3-network
 
Routes:
  to
:  172.16.20.0/28
 
Type:  L3
Status:
 
Conditions:
   
Last Transition Time:  2023-07-30T22:43:54Z
   
Message:               GKENetworkParamSet resource was deleted: l3-network
   
Reason:                GNPDeleted
   
Status:                False
   
Type:                  ParamsReady
   
Last Transition Time:  2023-07-30T22:43:54Z
   
Message:               Resource referenced by params is not ready
   
Reason:                ParamsNotReady
   
Status:                False
   
Type:                  Ready
Events:                    <none>

创建 GKENetworkParamSet

在 Cloud Shell 中,使用 VI 编辑器或 nano 创建网络对象 YAML l3-network-parm.yaml。请注意,该规范映射到 l3-vpc 子网部署。

apiVersion: networking.gke.io/v1
kind
: GKENetworkParamSet
metadata
:
  name
: "l3-network"
spec
:
  vpc
: "l3-vpc"
  vpcSubnet
: "l3-subnet"
  podIPv4Ranges
:
    rangeNames
:
   
- "sec-range-l3-subnet"

在 Cloud Shell 中,应用 l3-network-parm.yaml

kubectl apply -f l3-network-parm.yaml 

在 Cloud Shell 中,验证 l3-network 状态为“原因”是否为 GNPParmsReady 和 NetworkReady:

kubectl describe networks l3-network

示例:

user@$ kubectl describe networks l3-network
Name:         l3-network
Namespace:    
Labels:       <none>
Annotations:  networking.gke.io/in-use: false
API
Version:  networking.gke.io/v1
Kind:         Network
Metadata:
 
Creation Timestamp:  2023-07-30T22:43:54Z
 
Generation:          1
 
Resource Version:    1583647
  UID
:                 426804be-35c9-4cc5-bd26-00b94be2ef9a
Spec:
 
Parameters Ref:
   
Group:  networking.gke.io
   
Kind:   GKENetworkParamSet
   
Name:   l3-network
 
Routes:
   
To:  172.16.20.0/28
 
Type:  L3
Status:
 
Conditions:
   
Last Transition Time:  2023-07-30T22:46:14Z
   
Message:              
   
Reason:                GNPParamsReady
   
Status:                True
   
Type:                  ParamsReady
   
Last Transition Time:  2023-07-30T22:46:14Z
   
Message:              
   
Reason:                NetworkReady
   
Status:                True
   
Type:                  Ready
Events:                    <none>

在 Cloud Shell 中,验证用于创建 Pod 接口的 gkenetworkparamset l3-network CIDR 10.0.8.0/21。

kubectl describe gkenetworkparamsets.networking.gke.io l3-network

示例:

user@$ kubectl describe gkenetworkparamsets.networking.gke.io l3-network
Name:         l3-network
Namespace:    
Labels:       <none>
Annotations:  <none>
API
Version:  networking.gke.io/v1
Kind:         GKENetworkParamSet
Metadata:
 
Creation Timestamp:  2023-07-30T22:46:14Z
 
Finalizers:
    networking
.gke.io/gnp-controller
 
Generation:        1
 
Resource Version:  1583656
  UID
:               4c1f521b-0088-4005-b000-626ca5205326
Spec:
  podIPv4Ranges
:
   
Range Names:
      sec
-range-l3-subnet
 
Vpc:         l3-vpc
 
Vpc Subnet:  l3-subnet
Status:
 
Conditions:
   
Last Transition Time:  2023-07-30T22:46:14Z
   
Message:              
   
Reason:                GNPReady
   
Status:                True
   
Type:                  Ready
 
Network Name:            l3-network
 
Pod CID Rs:
   
Cidr Blocks:
     
10.0.8.0/21
Events:  <none>

11. 创建 netdevice-l3-pod

在下一部分中,您将创建运行 buzzbox(称为“瑞士军刀”)的 netdevice-l3-pod支持 300 多条常用命令。该 Pod 配置为使用 eth1 与 l3-vpc 通信,使用 eth2 与 netdevice-vpc 通信。

在 Cloud Shell 中,使用 VI 编辑器或 nano 创建名为 netdevice-l3-pod.yaml 的繁忙框容器。

apiVersion: v1
kind
: Pod
metadata
:
  name
: netdevice-l3-pod
  annotations
:
    networking
.gke.io/default-interface: 'eth0'
    networking
.gke.io/interfaces: |
     
[
     
{"interfaceName":"eth0","network":"default"},
     
{"interfaceName":"eth1","network":"l3-network"},
     
{"interfaceName":"eth2","network":"netdevice-network"}
     
]
spec
:
  containers
:
 
- name: netdevice-l3-pod
    image
: busybox
    command
: ["sleep", "10m"]
    ports
:
   
- containerPort: 80
  restartPolicy
: Always

在 Cloud Shell 中,应用 netdevice-l3-pod.yaml

kubectl apply -f netdevice-l3-pod.yaml

验证 netdevice-l3-pod 创建

在 Cloud Shell 中,验证 netdevice-l3-pod 是否正在运行:

kubectl get pods netdevice-l3-pod

示例:

user@$ kubectl get pods netdevice-l3-pod 
NAME               READY   STATUS    RESTARTS   AGE
netdevice
-l3-pod   1/1     Running   0          74s

在 Cloud Shell 中,验证分配给 Pod 接口的 IP 地址。

kubectl get pods netdevice-l3-pod -o yaml

在提供的示例中,networking.gke.io/pod-ips 字段包含与 l3-network 和 netdevice-network 中的 Pod 接口关联的 IP 地址。PodIP 下详细列出了默认网络 IP 地址 10.0.1.22:

user@$ kubectl get pods netdevice-l3-pod -o yaml
apiVersion
: v1
kind
: Pod
metadata
:
  annotations
:
    kubectl
.kubernetes.io/last-applied-configuration: |
     
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{"networking.gke.io/default-interface":"eth0","networking.gke.io/interfaces":"[\n{\"interfaceName\":\"eth0\",\"network\":\"default\"},\n{\"interfaceName\":\"eth1\",\"network\":\"l3-network\"},\n{\"interfaceName\":\"eth2\",\"network\":\"netdevice-network\"}\n]\n"},"name":"netdevice-l3-pod","namespace":"default"},"spec":{"containers":[{"command":["sleep","10m"],"image":"busybox","name":"netdevice-l3-pod","ports":[{"containerPort":80}]}],"restartPolicy":"Always"}}
    networking
.gke.io/default-interface: eth0
    networking
.gke.io/interfaces: |
     
[
     
{"interfaceName":"eth0","network":"default"},
     
{"interfaceName":"eth1","network":"l3-network"},
     
{"interfaceName":"eth2","network":"netdevice-network"}
     
]
    networking
.gke.io/pod-ips: '[{"networkName":"l3-network","ip":"10.0.8.4"},{"networkName":"netdevice-network","ip":"192.168.10.2"}]'
  creationTimestamp
: "2023-07-30T22:49:27Z"
  name
: netdevice-l3-pod
 
namespace: default
  resourceVersion
: "1585567"
  uid
: d9e43c75-e0d1-4f31-91b0-129bc53bbf64
spec
:
  containers
:
 
- command:
   
- sleep
   
- 10m
    image
: busybox
    imagePullPolicy
: Always
    name
: netdevice-l3-pod
    ports
:
   
- containerPort: 80
      protocol
: TCP
    resources
:
      limits
:
        networking
.gke.io.networks/l3-network.IP: "1"
        networking
.gke.io.networks/netdevice-network: "1"
        networking
.gke.io.networks/netdevice-network.IP: "1"
      requests
:
        networking
.gke.io.networks/l3-network.IP: "1"
        networking
.gke.io.networks/netdevice-network: "1"
        networking
.gke.io.networks/netdevice-network.IP: "1"
    terminationMessagePath
: /dev/termination-log
    terminationMessagePolicy
: File
    volumeMounts
:
   
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name
: kube-api-access-f2wpb
      readOnly
: true
  dnsPolicy
: ClusterFirst
  enableServiceLinks
: true
  nodeName
: gke-multinic-gke-multinic-node-pool-135699a1-86gz
  preemptionPolicy
: PreemptLowerPriority
  priority
: 0
  restartPolicy
: Always
  schedulerName
: default-scheduler
  securityContext
: {}
  serviceAccount
: default
  serviceAccountName
: default
  terminationGracePeriodSeconds
: 30
  tolerations
:
 
- effect: NoExecute
    key
: node.kubernetes.io/not-ready
   
operator: Exists
    tolerationSeconds
: 300
 
- effect: NoExecute
    key
: node.kubernetes.io/unreachable
   
operator: Exists
    tolerationSeconds
: 300
 
- effect: NoSchedule
    key
: networking.gke.io.networks/l3-network.IP
   
operator: Exists
 
- effect: NoSchedule
    key
: networking.gke.io.networks/netdevice-network
   
operator: Exists
 
- effect: NoSchedule
    key
: networking.gke.io.networks/netdevice-network.IP
   
operator: Exists
  volumes
:
 
- name: kube-api-access-f2wpb
    projected
:
      defaultMode
: 420
      sources
:
     
- serviceAccountToken:
          expirationSeconds
: 3607
          path
: token
     
- configMap:
          items
:
         
- key: ca.crt
            path
: ca.crt
          name
: kube-root-ca.crt
     
- downwardAPI:
          items
:
         
- fieldRef:
              apiVersion
: v1
              fieldPath
: metadata.namespace
            path
: namespace
status
:
  conditions
:
 
- lastProbeTime: null
    lastTransitionTime
: "2023-07-30T22:49:28Z"
    status
: "True"
    type
: Initialized
 
- lastProbeTime: null
    lastTransitionTime
: "2023-07-30T22:49:33Z"
    status
: "True"
    type
: Ready
 
- lastProbeTime: null
    lastTransitionTime
: "2023-07-30T22:49:33Z"
    status
: "True"
    type
: ContainersReady
 
- lastProbeTime: null
    lastTransitionTime
: "2023-07-30T22:49:28Z"
    status
: "True"
    type
: PodScheduled
  containerStatuses
:
 
- containerID: containerd://dcd9ead2f69824ccc37c109a47b1f3f5eb7b3e60ce3865e317dd729685b66a5c
    image
: docker.io/library/busybox:latest
    imageID
: docker.io/library/busybox@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79
    lastState
: {}
    name
: netdevice-l3-pod
    ready
: true
    restartCount
: 0
    started
: true
    state
:
      running
:
        startedAt
: "2023-07-30T22:49:32Z"
  hostIP
: 192.168.0.4
  phase
: Running
  podIP
: 10.0.1.22
  podIPs
:
 
- ip: 10.0.1.22
  qosClass
: BestEffort
  startTime
: "2023-07-30T22:49:28Z"

验证 netdevice-l3-pod 路由

在 Cloud Shell 中,验证从 netdevice-l3-pod 到 netdevice-vpc 和 l3-vpc 的路由:

kubectl exec --stdin --tty netdevice-l3-pod   -- /bin/sh

构建实例,验证 Pod 接口:

ifconfig

在本示例中,eth0 会连接到默认网络,eth1 会连接到 l3-network,eth2 会连接到 netdevice-network。

/ # ifconfig
eth0      
Link encap:Ethernet  HWaddr 26:E3:1B:14:6E:0C  
          inet addr
:10.0.1.22  Bcast:10.0.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU
:1460  Metric:1
          RX packets
:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets
:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions
:0 txqueuelen:0
          RX bytes
:446 (446.0 B)  TX bytes:558 (558.0 B)

eth1      
Link encap:Ethernet  HWaddr 92:78:4E:CB:F2:D4  
          inet addr
:10.0.8.4  Bcast:0.0.0.0  Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICAST  MTU
:1460  Metric:1
          RX packets
:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets
:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions
:0 txqueuelen:1000
          RX bytes
:446 (446.0 B)  TX bytes:516 (516.0 B)

eth2      
Link encap:Ethernet  HWaddr 42:01:C0:A8:0A:02  
          inet addr
:192.168.10.2  Bcast:0.0.0.0  Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICAST  MTU
:1460  Metric:1
          RX packets
:73 errors:0 dropped:0 overruns:0 frame:0
          TX packets
:50581 errors:0 dropped:0 overruns:0 carrier:0
          collisions
:0 txqueuelen:1000
          RX bytes
:26169 (25.5 KiB)  TX bytes:2148170 (2.0 MiB)

lo        
Link encap:Local Loopback  
          inet addr
:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU
:65536  Metric:1
          RX packets
:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets
:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions
:0 txqueuelen:1000
          RX bytes
:0 (0.0 B)  TX bytes:0 (0.0 B)

从 netdevice-l3-pod 中验证到 netdevice-vpc (172.16.10.0/28) 和 l3-vpc (172.16.20.0/28) 的路由。

构建实例,验证 Pod 路由:

ip route

示例:

/ # ip route
default via 10.0.1.1 dev eth0 #primary-vpc
10.0.1.0/
24 via 10.0.1.1 dev eth0  src 10.0.1.22
10.0.1.1 dev eth0 scope link  src 10.0.1.22
10.0.8.0/21 via 10.0.8.1 dev eth1 #l3-vpc (sec-range-l3-subnet)
10.0.8.1 dev eth1 scope link
172.16.10.0/28 via 192.168.10.1 dev eth2 #netdevice-vpc (netdevice-apache subnet)
172.16.20.0/28 via 10.0.8.1 dev eth1 #l3-vpc (l3-apache subnet)
192.168.10.0/24 via 192.168.10.1 dev eth2 #pod interface subnet
192.168.10.1 dev eth2 scope link

如需返回 Cloud Shell,请从实例中退出 Pod。

exit

12. 创建 l3-pod

在下一部分中,您将创建运行 utterbox 的 l3-pod(称为“瑞士军刀”)支持 300 多条常用命令。此 Pod 配置为仅使用 eth1 与 l3-vpc 进行通信。

在 Cloud Shell 中,使用 VI 编辑器或 nano 创建名为 l3-pod.yaml 的繁忙框容器。

apiVersion: v1
kind
: Pod
metadata
:
  name
: l3-pod
  annotations
:
    networking
.gke.io/default-interface: 'eth0'
    networking
.gke.io/interfaces: |
     
[
     
{"interfaceName":"eth0","network":"default"},
     
{"interfaceName":"eth1","network":"l3-network"}
     
]
spec
:
  containers
:
 
- name: l3-pod
    image
: busybox
    command
: ["sleep", "10m"]
    ports
:
   
- containerPort: 80
  restartPolicy
: Always

在 Cloud Shell 中,应用 l3-pod.yaml

kubectl apply -f l3-pod.yaml

验证 l3-pod 创建

在 Cloud Shell 中,验证 netdevice-l3-pod 是否正在运行:

kubectl get pods l3-pod

示例:

user@$ kubectl get pods l3-pod
NAME     READY   STATUS    RESTARTS   AGE
l3
-pod   1/1     Running   0          52s

在 Cloud Shell 中,验证分配给 Pod 接口的 IP 地址。

kubectl get pods l3-pod -o yaml

在提供的示例中,networking.gke.io/pod-ips 字段包含与 l3-网络中的 Pod 接口关联的 IP 地址。PodIP 下详细列出了默认网络 IP 地址 10.0.2.12:

user@$ kubectl get pods l3-pod -o yaml
apiVersion
: v1
kind
: Pod
metadata
:
  annotations
:
    kubectl
.kubernetes.io/last-applied-configuration: |
     
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{"networking.gke.io/default-interface":"eth0","networking.gke.io/interfaces":"[\n{\"interfaceName\":\"eth0\",\"network\":\"default\"},\n{\"interfaceName\":\"eth1\",\"network\":\"l3-network\"}\n]\n"},"name":"l3-pod","namespace":"default"},"spec":{"containers":[{"command":["sleep","10m"],"image":"busybox","name":"l3-pod","ports":[{"containerPort":80}]}],"restartPolicy":"Always"}}
    networking
.gke.io/default-interface: eth0
    networking
.gke.io/interfaces: |
     
[
     
{"interfaceName":"eth0","network":"default"},
     
{"interfaceName":"eth1","network":"l3-network"}
     
]
    networking
.gke.io/pod-ips: '[{"networkName":"l3-network","ip":"10.0.8.22"}]'
  creationTimestamp
: "2023-07-30T23:22:29Z"
  name
: l3-pod
 
namespace: default
  resourceVersion
: "1604447"
  uid
: 79a86afd-2a50-433d-9d48-367acb82c1d0
spec
:
  containers
:
 
- command:
   
- sleep
   
- 10m
    image
: busybox
    imagePullPolicy
: Always
    name
: l3-pod
    ports
:
   
- containerPort: 80
      protocol
: TCP
    resources
:
      limits
:
        networking
.gke.io.networks/l3-network.IP: "1"
      requests
:
        networking
.gke.io.networks/l3-network.IP: "1"
    terminationMessagePath
: /dev/termination-log
    terminationMessagePolicy
: File
    volumeMounts
:
   
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name
: kube-api-access-w9d24
      readOnly
: true
  dnsPolicy
: ClusterFirst
  enableServiceLinks
: true
  nodeName
: gke-multinic-gke-multinic-node-pool-135699a1-t66p
  preemptionPolicy
: PreemptLowerPriority
  priority
: 0
  restartPolicy
: Always
  schedulerName
: default-scheduler
  securityContext
: {}
  serviceAccount
: default
  serviceAccountName
: default
  terminationGracePeriodSeconds
: 30
  tolerations
:
 
- effect: NoExecute
    key
: node.kubernetes.io/not-ready
   
operator: Exists
    tolerationSeconds
: 300
 
- effect: NoExecute
    key
: node.kubernetes.io/unreachable
   
operator: Exists
    tolerationSeconds
: 300
 
- effect: NoSchedule
    key
: networking.gke.io.networks/l3-network.IP
   
operator: Exists
  volumes
:
 
- name: kube-api-access-w9d24
    projected
:
      defaultMode
: 420
      sources
:
     
- serviceAccountToken:
          expirationSeconds
: 3607
          path
: token
     
- configMap:
          items
:
         
- key: ca.crt
            path
: ca.crt
          name
: kube-root-ca.crt
     
- downwardAPI:
          items
:
         
- fieldRef:
              apiVersion
: v1
              fieldPath
: metadata.namespace
            path
: namespace
status
:
  conditions
:
 
- lastProbeTime: null
    lastTransitionTime
: "2023-07-30T23:22:29Z"
    status
: "True"
    type
: Initialized
 
- lastProbeTime: null
    lastTransitionTime
: "2023-07-30T23:22:35Z"
    status
: "True"
    type
: Ready
 
- lastProbeTime: null
    lastTransitionTime
: "2023-07-30T23:22:35Z"
    status
: "True"
    type
: ContainersReady
 
- lastProbeTime: null
    lastTransitionTime
: "2023-07-30T23:22:29Z"
    status
: "True"
    type
: PodScheduled
  containerStatuses
:
 
- containerID: containerd://1d5fe2854bba0a0d955c157a58bcfd4e34cecf8837edfd7df2760134f869e966
    image
: docker.io/library/busybox:latest
    imageID
: docker.io/library/busybox@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79
    lastState
: {}
    name
: l3-pod
    ready
: true
    restartCount
: 0
    started
: true
    state
:
      running
:
        startedAt
: "2023-07-30T23:22:35Z"
  hostIP
: 192.168.0.5
  phase
: Running
  podIP
: 10.0.2.12
  podIPs
:
 
- ip: 10.0.2.12
  qosClass
: BestEffort
  startTime
: "2023-07-30T23:22:29Z"

验证 l3-pod 路由

在 Cloud Shell 中,验证从 netdevice-l3-pod 到 l3-vpc 的路由:

kubectl exec --stdin --tty l3-pod   -- /bin/sh

构建实例,验证 Pod 接口:

ifconfig

在该示例中,eth0 连接到默认网络,eth1 连接到 l3-网络。

/ # ifconfig
eth0      
Link encap:Ethernet  HWaddr 22:29:30:09:6B:58  
          inet addr
:10.0.2.12  Bcast:10.0.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU
:1460  Metric:1
          RX packets
:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets
:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions
:0 txqueuelen:0
          RX bytes
:446 (446.0 B)  TX bytes:558 (558.0 B)

eth1      
Link encap:Ethernet  HWaddr 6E:6D:FC:C3:FF:AF  
          inet addr
:10.0.8.22  Bcast:0.0.0.0  Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICAST  MTU
:1460  Metric:1
          RX packets
:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets
:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions
:0 txqueuelen:1000
          RX bytes
:446 (446.0 B)  TX bytes:516 (516.0 B)

lo        
Link encap:Local Loopback  
          inet addr
:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU
:65536  Metric:1
          RX packets
:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets
:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions
:0 txqueuelen:1000
          RX bytes
:0 (0.0 B)  TX bytes:0 (0.0 B)

从 l3-pod 中验证到 l3-vpc (172.16.20.0/28) 的路由。

构建实例,验证 Pod 路由:

ip route

示例:

/ # ip route
default via 10.0.2.1 dev eth0 #primary-vpc
10.0.2.0/
24 via 10.0.2.1 dev eth0  src 10.0.2.12
10.0.2.1 dev eth0 scope link  src 10.0.2.12
10.0.8.0/21 via 10.0.8.17 dev eth1 #l3-vpc (sec-range-l3-subnet)
10.0.8.17 dev eth1 scope link #pod interface subnet
172.16.20.0/28 via 10.0.8.17 dev eth1 #l3-vpc (l3-apache subnet)

如需返回 Cloud Shell,请从实例中退出 Pod。

exit

13. 防火墙更新

要允许从 GKE Multicnic-pool 连接到 netdevice-vpc 和 l3-vpc 入站流量防火墙规则,您将创建防火墙规则,将来源范围指定为 Pod 网络子网,例如netdevice-subnet 和 sec-range-l3-subnet。

例如,在连接到 l3-vpc 中的 l3-apache 实例时,最近创建的容器 l3-pod、eth2 接口 10.0.8.22(从 sec-range-l3-subnet 分配)就是来源 IP 地址。

netdevice-vpc:允许从 netdevice-subnet 到 netdevice-apache

在 Cloud Shell 中,在 netdevice-vpc 中创建防火墙规则,允许 netdevice-subnet 访问 netdevice-apache 实例。

gcloud compute --project=$projectid firewall-rules create allow-ingress-from-netdevice-network-to-all-vpc-instances --direction=INGRESS --priority=1000 --network=netdevice-vpc --action=ALLOW --rules=all --source-ranges=192.168.10.0/24 --enable-logging

l3-vpc:允许从 sec-range-l3-subnet 到 l3-apache

在 Cloud Shell 中,在 l3-vpc 中创建防火墙规则,允许 sec-range-l3-subnet 访问 l3-apache 实例。

gcloud compute --project=$projectid firewall-rules create allow-ingress-from-l3-network-to-all-vpc-instances --direction=INGRESS --priority=1000 --network=l3-vpc --action=ALLOW --rules=all --source-ranges=10.0.8.0/21 --enable-logging

14. 验证 Pod 连接

在以下部分中,您将通过登录到 Pod 并运行 wget -S 来验证从 netdevice-l3-pod 和 l3-pod 连接到 Apache 实例的连接,以验证是否下载了 Apache 服务器主页。由于 netdevice-l3-pod 配置了来自 netdevice-network 和 l3-network 的接口,因此可以连接到 netdevice-vpc 和 l3-vpc 中的 Apache 服务器。

相反,从 l3-pod 执行 wget -S 时,无法连接到 netdevice-vpc 中的 Apache 服务器,因为 l3-pod 仅配置了来自 l3-network 的接口。

获取 Apache 服务器 IP 地址

在 Cloud 控制台中,前往 Compute Engine → 虚拟机实例,获取 Apache 服务器的 IP 地址

fee492b4fd303859.png

netdevice-l3-pod 到 netdevice-apache 连接测试

在 Cloud Shell 中,登录 netdevice-l3-pod:

kubectl exec --stdin --tty netdevice-l3-pod   -- /bin/sh

在容器中,根据从上一步获得的 IP 地址对 netdevice-apache 实例执行 ping 操作。

ping <insert-your-ip> -c 4

示例:

/ #  ping 172.16.10.2 -c 4
PING 172.16.10.2 (172.16.10.2): 56 data bytes
64 bytes from 172.16.10.2: seq=0 ttl=64 time=1.952 ms
64 bytes from 172.16.10.2: seq=1 ttl=64 time=0.471 ms
64 bytes from 172.16.10.2: seq=2 ttl=64 time=0.446 ms
64 bytes from 172.16.10.2: seq=3 ttl=64 time=0.505 ms

--- 172.16.10.2 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/
avg/max = 0.446/0.843/1.952 ms
/ #

在 Cloud Shell 中,根据从上一步获得的 IP 地址执行 wget -S 到 netdevice-apache 实例,200 OK 表示网页下载成功。

wget -S <insert-your-ip>

示例:

/ # wget -S 172.16.10.2
Connecting to 172.16.10.2 (172.16.10.2:80)
  HTTP/
1.1 200 OK
 
Date: Mon, 31 Jul 2023 03:12:58 GMT
 
Server: Apache/2.4.56 (Debian)
 
Last-Modified: Sat, 29 Jul 2023 00:32:44 GMT
 
ETag: "2c-6019555f54266"
 
Accept-Ranges: bytes
 
Content-Length: 44
 
Connection: close
 
Content-Type: text/html
 
saving to
'index.html'
index
.html           100% |********************************|    44  0:00:00 ETA
'index.html' saved
/ #

netdevice-l3-pod 到 l3-apache 连接测试

在 Cloud Shell 中,根据从上一步获得的 IP 地址对 l3-apache 实例执行 ping 操作。

ping <insert-your-ip> -c 4

示例:

/ # ping 172.16.20.3 -c 4
PING 172.16.20.3 (172.16.20.3): 56 data bytes
64 bytes from 172.16.20.3: seq=0 ttl=63 time=2.059 ms
64 bytes from 172.16.20.3: seq=1 ttl=63 time=0.533 ms
64 bytes from 172.16.20.3: seq=2 ttl=63 time=0.485 ms
64 bytes from 172.16.20.3: seq=3 ttl=63 time=0.462 ms

--- 172.16.20.3 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/
avg/max = 0.462/0.884/2.059 ms
/ #

在 Cloud Shell 中,删除之前的 index.html 文件,并根据从上一步获得的 IP 地址执行 wget -S 到 l3-apache 实例,200 OK 表示网页下载成功。

rm index.html 
wget
-S <insert-your-ip>

示例:

/ # rm index.html 
/
# wget -S 172.16.20.3
Connecting to 172.16.20.3 (172.16.20.3:80)
  HTTP
/1.1 200 OK
 
Date: Mon, 31 Jul 2023 03:41:32 GMT
 
Server: Apache/2.4.56 (Debian)
 
Last-Modified: Mon, 31 Jul 2023 03:24:21 GMT
 
ETag: "25-601bff76f04b7"
 
Accept-Ranges: bytes
 
Content-Length: 37
 
Connection: close
 
Content-Type: text/html
 
saving to
'index.html'
index
.html           100% |*******************************************************************************************************|    37  0:00:00 ETA
'index.html' saved

如需返回 Cloud Shell,请从实例中退出 Pod。

exit

l3-pod 到 netdevice-apache 连接测试

在 Cloud Shell 中,登录 l3-pod:

kubectl exec --stdin --tty l3-pod   -- /bin/sh

在容器中,根据从上一步获得的 IP 地址对 netdevice-apache 实例执行 ping 操作。由于 l3-pod 没有与 netdevice-network 关联的接口,因此 ping 将失败。

ping <insert-your-ip> -c 4

示例:

/ # ping 172.16.10.2 -c 4
PING
172.16.10.2 (172.16.10.2): 56 data bytes


--- 172.16.10.2 ping statistics ---
4 packets transmitted, 0 packets received, 100% packet loss

可选:在 Cloud Shell 中,根据从上一步获取的会超时的 IP 地址,对 netdevice-apache 实例执行 wget -S 操作。

wget -S <insert-your-ip>

示例:

/ # wget -S 172.16.10.2
Connecting to 172.16.10.2 (172.16.10.2:80)
wget
: can't connect to remote host (172.16.10.2): Connection timed out

l3-pod 到 l3-apache 连接测试

在 Cloud Shell 中,根据从上一步获得的 IP 地址对 l3-apache 实例执行 ping 操作。

ping <insert-your-ip> -c 4

示例:

/ # ping 172.16.20.3 -c 4
PING 172.16.20.3 (172.16.20.3): 56 data bytes
64 bytes from 172.16.20.3: seq=0 ttl=63 time=1.824 ms
64 bytes from 172.16.20.3: seq=1 ttl=63 time=0.513 ms
64 bytes from 172.16.20.3: seq=2 ttl=63 time=0.482 ms
64 bytes from 172.16.20.3: seq=3 ttl=63 time=0.532 ms

--- 172.16.20.3 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/
avg/max = 0.482/0.837/1.824 ms
/ #

在 Cloud Shell 中,根据从上一步获得的 IP 地址执行 wget -S 到 l3-apache 实例,200 OK 表示网页下载成功。

wget -S <insert-your-ip>

示例:

/ # wget -S 172.16.20.3
Connecting to 172.16.20.3 (172.16.20.3:80)
  HTTP/
1.1 200 OK
 
Date: Mon, 31 Jul 2023 03:52:08 GMT
 
Server: Apache/2.4.56 (Debian)
 
Last-Modified: Mon, 31 Jul 2023 03:24:21 GMT
 
ETag: "25-601bff76f04b7"
 
Accept-Ranges: bytes
 
Content-Length: 37
 
Connection: close
 
Content-Type: text/html
 
saving to
'index.html'
index
.html           100% |*******************************************************************************************************|    37  0:00:00 ETA
'index.html' saved
/ #

15. 防火墙日志

通过防火墙规则日志记录,您可以审核、验证和分析防火墙规则所带来的影响。例如,您可以确定用于拒绝流量的防火墙规则是否如期发挥作用。如果您需要确定特定防火墙规则影响的连接数,防火墙规则日志记录也非常有用。

在本教程中,您在创建入站防火墙规则时启用了防火墙日志记录。我们来看看从日志中获得的信息。

从 Cloud Console 中,前往 Logging → 日志浏览器

根据屏幕截图插入以下查询,然后选择 Run query jsonPayload.rule_details.reference:("network:l3-vpc/firewall:allow-ingress-from-l3-network-to-all-vpc-instances")

280d00f2c5ce6109

仔细查看捕获可为安全管理员提供信息元素;范围从来源和目标 IP 地址、端口、协议和节点池名称开始。

ae4638ed9b718ac6.png

如需进一步探索防火墙日志,请依次前往“VPC 网络”→“防火墙”→“allow-ingress-from-netdevice-network-to-all-vpc-instances”,然后在“日志浏览器”中选择“查看”。

16. 清理

从 Cloud Shell 中删除教程组件。

gcloud compute instances delete l3-apache netdevice-apache --zone=us-central1-a --quiet

gcloud compute routers
delete l3-cr netdevice-cr --region=us-central1 --quiet

gcloud container clusters
delete multinic-gke --zone=us-central1-a --quiet

gcloud compute firewall
-rules delete allow-ingress-from-l3-network-to-all-vpc-instances allow-ingress-from-netdevice-network-to-all-vpc-instances --quiet

gcloud compute networks subnets
delete l3-apache l3-subnet netdevice-apache netdevice-subnet primary-node-subnet --region=us-central1 --quiet

gcloud compute networks
delete l3-vpc netdevice-vpc primary-vpc --quiet

17. 恭喜

恭喜!您已成功配置并验证了已创建多 NIC 节点池以及创建运行 buzzbox 的 pod,以使用 PING 和 wget 验证了 L3 和设备类型与 Apache 服务器的连接。

您还学习了如何利用防火墙日志检查 Pod 容器和 Apache 服务器之间的源和目标数据包。

Cosmopup 认为教程很棒!!

e6d3675ca7c6911f.jpeg

补充阅读材料和视频

参考文档