---
title: 设置出网网关
description: "Kube-OVN网络中的Pod通过网关来访问集群外网络，目前支持两种类型的网关，用户可以在子网中对网关的类型进行调整。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengcpfs/ecosystemEnable/Kubernetes/kunpengkubeovn_06_0027.html
sourcePath: /source/zh/kunpengcpfs/ecosystemEnable/Kubernetes/kunpengkubeovn_06_0027.html
indexId: 643f8c3a9bbdd0f21d4a8b84c41f785497153226c9070290336931f624e3be3877
---
# 设置出网网关

Kube-OVN网络中的Pod通过网关来访问集群外网络，目前支持两种类型的网关，用户可以在子网中对网关的类型进行调整。

- 分布式网关
  子网的默认类型网关，每个Node会作为当前Node上Pod访问外部网络的网关。数据包会通过本机的ovn0网卡流入主机网络栈，再根据主机的路由规则进行出网。当natOutgoing属性为true时，Pod访问外部网络将会使用当前所在宿主机的IP地址。

  子网配置示例：

  vim distributed.yaml

  1 2 3 4 5 6 7 8 9 10 11 12 apiVersion: kubeovn.io/v1 kind: Subnet metadata: name: distributed spec: cidrBlock: 10.166.0.0/16 default: false excludeIps: - 10.166.0.1 gateway: 10.166.0.1 gatewayType: distributed natOutgoing: true

  1 kubectl create -f distributed.yaml

- 集中式网关
  如果希望子网内流量访问外网使用固定的IP地址，以便审计和白名单等安全操作，可以在子网中设置集中式网关。在集中式网关模式下，Pod访问外网的数据包会首先被路由到特定节点的ovn0网卡，再通过主机的路由规则进行出网。当natOutgoing为true时，Pod访问外部网络将会使用特定宿主机的IP地址。

  子网配置示例：

  1 vim centralized.yaml

  1 2 3 4 5 6 7 8 9 10 11 12 13 apiVersion: kubeovn.io/v1 kind: Subnet metadata: name: centralized spec: cidrBlock: 10.166.0.0/16 default: false excludeIps: - 10.166.0.1 gateway: 10.166.0.1 gatewayType: centralized gatewayNode: "node1,node2" natOutgoing: true

  1 kubectl create -f centralized.yaml
