1. Vpc
从 v1.6.0 开始,用户可以创建自定义 VPC。 每个VPC都有独立的地址空间,用户可以设置重叠的CIDR、Subnet和Routes。
默认情况下,所有没有 VPC 选项的子网都属于默认 VPC。 对于不打算使用自定义 VPC 的用户,所有功能和用法保持不变。
kind: Vpc
metadata:
name: test-vpc-1
spec:
namespaces:
- ns1
---
kind: Vpc
metadata:
name: test-vpc-2
spec: {}
`namespace` 列表可以限制哪个命名空间可以绑定到 VPC,如果列表为空则没有限制
自定义路由,用于编排流量的 VPC 级别策略路由。
kind: Vpc metadata: name: test-vpc-1 spec: staticRoutes: - cidr: 0.0.0.0/0 nextHopIP: 10.0.1.254 policy: policyDst - cidr: 172.31.0.0/24 nextHopIP: 10.0.1.253 policy: policySrc
2. Subnet
apiVersion: kubeovn.io/v1
kind: Subnet
metadata:
name: subnet-gateway
spec:
protocol: IPv4
default: false
namespaces:
- ns1
- ns2
cidrBlock: 10.10.0.0/16
gateway: 10.10.0.1
excludeIps:
- 10.10.0.1
private: true
allowSubnets:
- 10.16.0.0/16
- 10.18.0.0/16
gatewayType: centralized
gatewayNode: node1
natOutgoing: true
基本配置
- protocol, IPV4 / IPV6
- default, 如果设置为 true,则所有未绑定到任何子网的命名空间都将使用此子网分配 pod ip 并共享
- namespaces, 绑定到该子网的 namespace 列表
- cidrBlock, 该子网的 CIDR
- gatteway, 该子网的网关
- excludeIps, 不想分配的 ip 列表,格式 192.168.10.20..192.168.10.30 可以表示范围
隔离配置
除了标准的 NetworkPolicy 之外,Kube-OVN 还支持 Subnet 级别的网络隔离和访问控制,以简化访问控制的使用。
- private, 控制是否拒绝来自此子网之外的 IP 地址的流量。 默认值:false
- allowSubnets, 如果 private: true,控制是否这些地址可以与该子网通信
网关配置
网关用于为 OVN 虚拟网络中的 Pod 启用外部网络连接。Kube-OVN 支持两种网关:分布式网关和集中式网关。 用户也可以将 pod ip 直接暴露给外部网络。对于分布式网关,从 OVN 网络内的 Pod 到外部目的地的传出流量将通过托管 Pod 的节点。对于集中式网关,从 OVN 网络内的 Pod 到外部目的地的传出流量将通过命名空间的网关节点。
- gatewayType,distributed / centralized,默认为 distributed
- gatewayNode,当 gatewayType 指定集中化的网关类型,使用此字段来指定哪个节点充当命名空间网关。
- natOutgoing, true / false,通过网关时是否需要伪装 pod ip。 当为f alse 时 pod ip将 直接暴露给外网,默认为 false。
高级配置
vlan: 如果启用 vlan 网络,使用此字段指定子网应绑定到哪个 vlan。
underlayGateway: 如果启用vlan网络,该字段直接使用 underlay 网络网关,而不是 ovs 虚拟网关
externalEgressGateway
policyRoutingPriority
/policyRoutingTableID
disableGatewayCheck
disableInterConnection
默认情况下,Pod 会自动从 Namespace 继承子网,从 1.5.1 开始,用户可以通过为 Pod 手动设置 `logical_switch` 注释来将 Pod 绑定到另一个子网。
apiVersion: v1
kind: Pod
metadata:
annotations:
ovn.kubernetes.io/logical_switch: another-subnet
namespace: default
name: another-subnet-pod
3. Pod Gateway
Kube-OVN 支持将特定 pod 分配为另一个 pod 的网关。 从 pod 到外部集群的所有流量都将重定向到网关 pod。 因此,用户可以在此 pod 中自定义流量策略,如计费、eip、qos 等。
在 pod 资源定义中使用以下注释:
ovn.kubernetes.io/north_gateway:网关pod的IP地址
apiVersion: v1
kind: Pod
metadata:
name: pod-gw
annotations:
ovn.kubernetes.io/north_gateway: 10.16.0.100
spec:
containers:
- name: pod-gw
image: nginx:alpine
4. Vlan
默认情况下,Kube-OVN 使用 Geneve 来封装主机之间的数据包,这将在您的基础设施之上构建一个覆盖网络。 Kube-OVN 还支持底层 Vlan 模式网络,以获得更好的性能和吞吐量。 在 Vlan 模式下,来自 pod 的数据包带有 vlan 标签直接发送到物理交换机。
要启用 Vlan 模式,容器网络需要一个专用的网络接口。 Mac 地址、MTU、IP 地址和连接到接口的路由将被复制/传输到名为 br-PROVIDER 的 OVS 网桥,其中 PROVIDER 是提供商网络的名称。 相关的交换机端口必须工作在 trunk 模式才能接受 802.1q 数据包。 对于没有 vlan tag 的 underlay 网络,需要设置 VLAN ID 为 0。
引入了一种新的混合模式,允许 Geneve 和 Vlan 同时存在。 您可以拥有使用 Geneve 封装的子网 A 和使用 Vlan 标记的子网 B。
从 v1.7.1 开始,Kube-OVN 支持动态 underlay/VLAN 网络管理。
4.1 Create Underlay Network
对于v1.7.1以下版本的Kube-OVN,Kube-OVN必须部署 vlan 网络类型; 从 v1.7.1 开始,您可以通过使用 CRD 创建提供商网络和 vlan 来动态创建底层网络。
4.1.1 Deploy With Vlan Mode
在默认 Vlan 模式下,Kube-OVN 创建一个名为 ovn-default 的默认子网,该子网在 underlay/VLAN 模式下工作。
wget https://raw.githubusercontent.com/alauda/kube-ovn/release-1.7/dist/images/install.sh
编辑修改设置 NETWORK_TYPE 为 vlan,以及设置 VLAN_INTERFACE_NAME 网络接口,执行安装
创建一个 vlan
apiVersion: kubeovn.io/v1
kind: Vlan
metadata:
name: product
spec:
vlanId: 10
对于 v1.7.1 以上的版本:
apiVersion: kubeovn.io/v1
kind: Vlan
metadata:
name: product
spec:
id: 10
provider: provider
创建一个 subnet
apiVersion: kubeovn.io/v1
kind: Subnet
metadata:
name: product
spec:
cidrBlock: 10.100.0.0/16
default: false
gateway: 10.100.0.1
vlan: product
underlayGateway: true
4.1.2 Dynamical Management
注意:该特性是 v1.7.1 以上版本支持
4.1.2.1 创建 Provider Network
apiVersion: kubeovn.io/v1
kind: ProviderNetwork
metadata:
name: net1
spec:
defaultInterface: eth1
customInterfaces:
- interface: eth2
nodes:
- node1
excludeNodes:
- node2
CRD Field | Required | Usage |
---|---|---|
.spec.defaultInterface | Yes | Specify the default interface to be used |
.spec.customInterfaces | No | Specify the custom interfaces to be used |
.spec.excludeNodes | No | Specify the nodes on which the provider network will not be deployed |
5. Static IP
Kube-OVN 支持为单个 Pod 分配静态 IP 地址,或为具有多个 Pod 的工作负载(Deployment/DaemonSet/StatefulSet)分配静态 IP 池。 要启用此功能,请将以下注释添加到 Pod spec 模板。
5.1 For a single Pod
使用以下注解指定静态 IP
ovn.kubernetes.io/ip_address
: Specifies IP addressovn.kubernetes.io/mac_address
: Specifies MAC address
apiVersion: v1
kind: Pod
metadata:
name: static-ip
namespace: ls1
annotations:
ovn.kubernetes.io/ip_address: 10.16.0.15
ovn.kubernetes.io/mac_address: 00:00:00:53:6B:B6
spec:
containers:
- name: static-ip
image: nginx:alpine
注意:
address 必须在相应的 subnet 的 CIDR 范围内
address 不能跟已经分配的地址冲突
静态 mac 地址是可选的
5.2 For Workloads
对于 workload 使用下列注解来分配静态地址:
ovn.kubernetes.io/ip_pool
: For Deployments/DaemonSets, we will randomly choose an available IP address for a Pod. For StatefulSets, the IP allocation will follow the order specified in the list.
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: ovn-test
name: starter-backend
labels:
app: starter-backend
spec:
replicas: 2
selector:
matchLabels:
app: starter-backend
template:
metadata:
labels:
app: starter-backend
annotations:
ovn.kubernetes.io/ip_pool: 10.16.0.15,10.16.0.16,10.16.0.17
spec:
containers:
- name: backend
image: nginx:alpine
6. Qos
Kube-OVN 支持动态配置单个 pod 级别和网关级别的 Ingress 和 Egress 流量速率限制。
6.1 Pod Qos
ovn.kubernetes.io/ingress_rate
: Rate limit for Ingress traffic, unit: Mbit/sovn.kubernetes.io/egress_rate
: Rate limit for Egress traffic, unit: Mbit/s
apiVersion: v1
kind: Pod
metadata:
name: qos
namespace: ls1
annotations:
ovn.kubernetes.io/ingress_rate: "3"
ovn.kubernetes.io/egress_rate: "1"
spec:
containers:
- name: qos
image: nginx:alpine
6.2 Gateway QoS
Kube-OVN 将在每个主机上创建一个 ovn0 接口,以将流量从集群 pod 网络路由到外部网络。 Kube-OVN 通过修改 ovn0 接口的 QoS 配置来控制网关 QoS。
对于集中网关模式的子网,只有一个节点作为网关,可以通过修改节点QoS注解来控制子网对外网的 QoS。
apiVersion: v1
kind: Node
metadata:
annotations:
ovn.kubernetes.io/ingress_rate: "3"
ovn.kubernetes.io/egress_rate: "1"
name: liumengxin-ovn1-192.168.16.44