Assign public ip to VM using keepalived

bytesite

New Member
Feb 18, 2024
1
0
1
Hi,

I'm trying to setup HAProxy with 2 vms and 1 public floating ip.

My setup is as follows:
- 1 dedicated server with public ip (x.x.x.x/26) for proxmox
- 1 additional public ip (y.y.y.y/26) which I want to use as floating ip

Code:
iface enp0s21f4 inet static

auto vmbr0
iface vmbr0 inet static
    address x.x.x.x/26
    gateway x.x.x.1
    hwaddress xx:xx:xx:xx:xx:xx
    bridge_ports enp0s21f4
    bridge_stp off
    bridge_fd 1
    up route add -net x.x.x.0 netmask 255.255.255.192 gw x.x.x.1 dev enp0s21f4

If I assign vmbr0 to one vm and set ipconfig0 = "ip=y.y.y.y/26,gw=x.x.x.1"the machine is publicly accessible using the ip.

Now I have installed keepalived with the following config. When I start keepalived it logs "(VI_1) entering FAULT state (no IPv4 address for interface)" and removes the public ip from the network interface.
Code:
vrrp_script check_haproxy {
    script "/usr/bin/killall -0 haproxy"
    interval 2
    weight 2
}

vrrp_instance VI_1 {
    interface eth1

    state MASTER
    priority 101

    virtual_router_id 51
    virtual_ipaddress {
        y.y.y.y/26
    }
    track_script {
        check_haproxy
    }
}

Is there some additional Proxmox configuration needed?
 
Last edited:
From first glance and not understanding where you are trying to run keepalived, the error is you indicator here. There is no IP address on the interface. In this case, you specified `interface eth1` and I'm guessing you are doing this on the Proxmox host, where you are using `vmbr0`. You could try just changing it to that. But unless you are running HAProxy on the host, I don't believe this will provide your desired results.

I'm guessing that you really want this VIP to be inside the VM or container running HAProxy, and it will need an IP on the interface for that machine, besides the VIP. Hope that makes sense and helps.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!