-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] conflict, when two vpcs with different subnets, two nat gateways ( an external subnet ) #4566
Comments
Hey there, @cybercoder! I'm here to help you with any bugs, questions, or contributions you have. Let's tackle this together! I found two similar closed issues that might be relevant to your problem:
To resolve the conflict between EIP and DNAT when running a second VPC with a NAT gateway in Kube-OVN v1.12.25 on Kubernetes v1.30.4+k3s1, you need to ensure that the EIP (Elastic IP) is not in use by any DNAT (Destination NAT) rules before proceeding. The provided code includes validation hooks that check for such conflicts. Here is the relevant part of the code that handles the validation for DNAT rules: func (v *ValidatingHook) ValidateIptablesDnat(ctx context.Context, dnat *ovnv1.IptablesDnatRule) error {
if dnat.Spec.EIP == "" {
return errors.New("parameter \"eip\" cannot be empty")
}
eip := &ovnv1.IptablesEIP{}
key := types.NamespacedName{Name: dnat.Spec.EIP}
if err := v.cache.Get(ctx, key, eip); err != nil {
return err
}
if dnat.Spec.ExternalPort == "" {
return errors.New("parameter \"externalPort\" cannot be empty")
}
if dnat.Spec.InternalPort == "" {
return errors.New("parameter \"internalPort\" cannot be empty")
}
if port, err := strconv.Atoi(dnat.Spec.ExternalPort); err != nil {
errMsg := fmt.Errorf("failed to parse externalPort %s: %w", dnat.Spec.ExternalPort, err)
return errMsg
} else if port < 0 || port > 65535 {
err := fmt.Errorf("externalPort %s is not a valid port", dnat.Spec.ExternalPort)
return err
}
if port, err := strconv.Atoi(dnat.Spec.InternalPort); err != nil {
errMsg := fmt.Errorf("failed to parse internalIP %s: %w", dnat.Spec.InternalPort, err)
return errMsg
} else if port < 0 || port > 65535 {
err := fmt.Errorf("internalIP %s is not a valid port", dnat.Spec.InternalPort)
return err
}
if net.ParseIP(dnat.Spec.InternalIP) == nil {
err := fmt.Errorf("internalIP %s is not a valid ip", dnat.Spec.InternalIP)
return err
}
if !strings.EqualFold(dnat.Spec.Protocol, "tcp") &&
!strings.EqualFold(dnat.Spec.Protocol, "udp") {
err := fmt.Errorf("invalid iptable protocol: %s,supported params: \"tcp\", \"udp\"", dnat.Spec.Protocol)
return err
}
return nil
} This function validates the DNAT rule by checking if the EIP is specified and if it is valid. It also ensures that the external and internal ports are within the valid range and that the internal IP is a valid IP address. Additionally, it checks that the protocol is either TCP or UDP [3]. To resolve the conflict, you should ensure that:
Additionally, you can use the provided Here is an example of how to use the script to add an EIP and a DNAT rule: # Initialize the NAT gateway
./nat-gateway.sh init
# Add an EIP
./nat-gateway.sh eip-add 192.168.1.100/24
# Add a DNAT rule
./nat-gateway.sh dnat-add 192.168.1.100,10.0.0.1,80,8080,tcp Furthermore, the By following these steps and using the provided script, you can effectively manage your NAT gateway and resolve conflicts between EIP and DNAT. |
kind: Subnet
apiVersion: kubeovn.io/v1
metadata:
name: roya-subnet1
spec:
vpc: roya-vpc-1
cidrBlock: 10.0.1.0/24
gateway: 10.0.1.254
protocol: IPv4
namespaces:
- roya
---
kind: VpcNatGateway
apiVersion: kubeovn.io/v1
metadata:
name: roya-gw
spec:
vpc: roya-vpc-1
subnet: roya-subnet1
lanIp: 10.0.1.254
externalSubnets:
- external1 Seems field |
Kube-OVN Version
v1.12.25
Kubernetes Version
v1.30.4+k3s1
Operation-system/Kernel Version
Ubuntu 20.04.6 LTS
5.4.0-196-generic
Description
according to this documentation, a custom VPC with a nat gateway works properly.
but EIP, DNAT get conflict, when the second VPC and it's NAT GW starts running.
Steps To Reproduce
Create External (Non-OVN):
VPC, Internal subnet, Nat Gateway:
Now the EIP and the POD:
It needs a custom SNAT/DNAT (seems eip,snat annotations doesn't work like default VPC):
Now, it works and curl on
eip
shows the Nginx page.Current Behavior
When we clone that configs ( except external subnet and NAD ),
The CURL getting timeout on the first POD ( DNAT or GWs seems conflict )
Expected Behavior
Real isolation.
The text was updated successfully, but these errors were encountered: