Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Author: Wu secret

Hi! Welcome to the Tungsten Fabric and Kubernetes Integration Guide series, this article describes the five steps usually create a virtual network.
Tungsten Fabric and K8s Integration Guide series of articles, you rendered by TF Chinese community, is designed to help you understand the basics of Tungsten Fabric and K8s integration. We have little experience in the related deployment, or problems, please contact us.

After doing architecture deployment, and confirm that the initial state Tungsten Fabric and Kubernetes (K8s) cluster is no problem, we can begin to try to create a virtual network.

Step 1: Create a namespace

In K8s, most of the resources belonging to a namespace, we need to first create a namespace, then create corresponding pod, service, and virtual networks. The two new namespaces, were test-ns1 and test-ns2, execute the following command to log K8s the master node:

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Once created, the Tungsten Fabric management interface can see the corresponding project is created, k8s-test-ns1 and k8s-test-ns2.

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Step 2: Create a new IPAM

You need to create an IP address management (IPAM) for your project, based on this to create a virtual network.

In Tungsten Fabric Management Interface select "Configure> Networking> IP Address Management", and select the project - k8s-test-ns1, then click the "Create" button.

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Name and Subnet Method which is required, there are two ways Subnet Method, User Defined is to go to manually specify the subnet of the network at the time of binding, Flat directly create subnets network segment, the two are different, User Defined you can specify a range of IP pool, Flat is directly across the subnet, the default is to use the Flat.

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Step 3: Create Virtual Network

在Tungsten Fabric管理界面选择“Configure > Networking > Networks”,并选择 k8s-test-ns1,然后单击“创建”按钮。
Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

如上图所示,就是完成了一个虚拟网络的创建,为了方便测试,再以相同的方式创建另一个网络 k8s-ns1-pod-net2 (10.10.20.0/24)。
Tungsten Fabric and K8s Integration Guide Shu create a virtual network

第4步:创建pod

首先在名为test-ns1的命名空间上创建一个pod,指定网络为 k8s-ns1-pod-net01,配置如下:

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

然后再创建一个基于虚拟网络k8s-ns1-pod-net02的pod,配置如下:

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

执行kubectl的创建命令之后,两个pod都创建成功,并且容器的IP地址分别为:
属于虚拟网络 k8s-ns1-pod-net01 (10.10.10.0/24)的pod 10.10.10.1
属于虚拟网络 k8s-ns1-pod-net02 (10.10.20.0/24)的pod 10.10.20.1

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

第5步:网络连通性验证

1、验证同一命名空间不通网络pod之间网络连通性

首先进行互ping,验证连通性。测试结果如下截图,同一命名空间下,默认情况两个网络无法通信。
Tungsten Fabric and K8s Integration Guide Shu create a virtual network

需要通信则必须在Tungsten Fabric上添加一个路由器来连接网络 k8s-ns1-pod-net01 和 k8s-ns1-pod-net02,如下所示:

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

路由器创建完成后再验证两个网络的连通性,结果是两个pod能够互相通信。

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

2、验证同一命名空间下pod到service之间的网络连通性

默认情况下,除了 k8s-default-pod-network 之外,其他的虚拟网络是无法连接到K8s的service网络的,通过请求kube-system中的coredns服务来验证,命令为 nslookup kube-dns.kube-system,因为是跨命名空间去解析域名,所以需要在域名中添加命名空间名称后缀(如果pod是在kube-system中,那么执行nslookup kube-dns即可),具体验证情况如下:

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

若需要让k8s-ns1-pod-net01 网段的pod可以访问到K8s的service网络,那么就需要添加一条TF policy,k8s-default项目下的Policies -- k8s-default-service-np,具体策略规则如下图所示,意味着所有添加了此条规则的网络都可以无限制的访问到k8s的service网络的所有端口。

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

现在需要给网络 k8s-ns1-pod-net01添加 k8s-default-service-np 这条策略,让它可以访问k8s的service网络。

Configure --> Networking --> Networks, 选择k8s-test-ns1项目,编辑network k8s-ns1-pod-net01, 附加一条Network Policy -- k8s-default-service-np,具体操作如下:

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

再次验证pod到service之间的网络连通性,此时处在网络k8s-ns1-pod-net01的pod nginx01-ns1-net01 (10.10.10.1) 是可以直接通过请求service的ClusterIP:PORT(coredns服务)来解析域名,而k8s-ns1-pod-net02 没有附加k8s-default-service-np,所以pod nginx01-ns1-net02 (10.10.20.1) 是仍然无法访问service里面的coredns服务。
Tungsten Fabric and K8s Integration Guide Shu create a virtual network

3、验证不同命名空间下pod之间的网络连通性

同一命名空间下的两个网络之间的通信,跟不同命名空间下的两个网络之间的通信是有一些区别的,因为不同命名空间的情况下,无法通过新建TF Router来连接两个网络,所以必须通过TF Policy 来实现不同命名空间下的两个网络之间的互通。

之前的步骤中已经创建了两个命名空间 (test-ns1与test-ns2),并且test-ns1里面已经有了两个网络,所以需要在test-ns2中去新建一个网络。新建的网络为 k8s-ns2-pod-net01 (20.10.10.0/24)。

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

默认情况下,k8s-ns2-pod-net01 (20.10.10.0/24) 与 k8s-ns1-pod-net01 (10.10.10.0/24),k8s-ns1-pod-net02 (10.10.20.0/24) 都是无法通信的,现在需要在网络k8s-ns2-pod-net01 (20.10.10.0/24)中新建两个pod。

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Tungsten Fabric and K8s Integration Guide Shu create a virtual network
在此验证pod nginx01-ns1-net01 与 nginx01-ns2-net01的网络连通性,两者在不同的命名空间,不同的network,验证结果是无法通信,具体见下面截图:
Tungsten Fabric and K8s Integration Guide Shu create a virtual network

若需要让这两个不同命名空间不同network的pod能够互相通信,则需要添加如下的TF Policies:

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Contrial Network Policy 创建好之后,再分别将它附加到网络 k8s-ns1-pod-net01和k8s-ns2-pod-net01。

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Tungsten Fabric and K8s Integration Guide Shu create a virtual network

再次验证,此时两个不同命名空间不同network的pod已经能够互相通信。
Tungsten Fabric and K8s Integration Guide Shu create a virtual network

(作者来自深圳市天源景云科技有限公司)


Tungsten Fabric+K8s集成指南系列文章---
第一篇:部署准备与初始状态

Tungsten Fabric + K8s easy to get started series ---
first article: TF Carbide Evaluation Guide - prepare papers
Second: connection for basic applications through Kubernetes service
Part III: connecting external applications through Advanced Kubernetes Ingress
first four: to achieve the initial application through Kubernetes namespace isolation
Part V: applications that micro-segmentation strategy by Kubernetes network


Tungsten Fabric and K8s Integration Guide Shu create a virtual network
Focus on micro letter: TF Chinese community
Tungsten Fabric and K8s Integration Guide Shu create a virtual network

Guess you like

Origin blog.51cto.com/14638699/2474104