Open cybercoder opened 1 month ago
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 nat-gateway.sh
script to manage your NAT gateway configurations. This script includes functions to add and delete EIPs, DNAT, and SNAT rules, ensuring that the NAT gateway is properly initialized and configured. For example, to add an EIP, you can use the add_eip
function, and to add a DNAT rule, you can use the add_dnat
function. This script helps automate the setup and management of NAT rules, reducing the risk of conflicts [4].
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 test/e2e/iptables-vpc-nat-gw/e2e_test.go
file in Kube-OVN provides additional context on how the VPC NAT Gateway is managed. The setupVpcNatGwTestEnvironment
function ensures that the VPC NAT Gateway is properly created or updated, and the cleanVpcNatGwTestEnvironment
function cleans up the NAT Gateway, including setting up QoS policies if specified [5].
By following these steps and using the provided script, you can effectively manage your NAT gateway and resolve conflicts between EIP and DNAT.
To continue talking to Dosu, mention @dosu.
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 .spec.lanIp
of the vpc nat gateway is conflict with the subnet gateway. Please change the gateway lanIp or subnet gateway and try again.
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.