Configure HA Cluster using KeepAliveD on Ubuntu

This tutorial post will help you with Step by Step procedure to configure HA Cluster on Ubuntu with Floating IP.

End of this post, you will be able to understand How to Configure HA Cluster using KeepAliveD on Ubuntu.

If you are new to kubernetes and want to learn about kubernetes from basics, Refer the below links and also you can checkout all tutorial videos for free on YouTube and do subscribe for more free videos.

What is Kubernetes - Learn Kubernetes from Basics
How to Install Kubernetes on Linux (RedHat / CentOS)
How to Install Kubernetes On Ubuntu 16.04 LTS
How to Create Kubernetes Deployment, Services & Pods Using Kubectl
How to Create Kubernetes YAML for Deployment, Service & Pods
Kubernetes Volumes Explained with Examples
Kubernetes Persistent Volumes and Claims Explained

Also You can Watch this Entire Tutorial video on our YouTube Channel - Configure HA Cluster using KeepAliveD on Ubuntu.






Configure HA Cluster using KeepAliveD on Ubuntu


HA Cluster Architecture Lab Setup:
Configure HA Cluster using KeepAliveD on Ubuntu

Web Servers - 2 Nos.
HaProxy LB - 2 Nos.

Note: All nodes are installed with Ubuntu 20.04.


Prerequisites:

1. Users must have root or sudo access to perform administrative tasks. (switchover to root user to avoid unnecessary permission issues).

2. (OPTIONAL )- Make an entry of each host in /etc/hosts file for name resolution on all nodes as below or configure it on DNS if you have DNS Server.

$ cat /etc/hosts
192.168.2.11  haproxy-lb1
192.168.2.12  haproxy-lb2
192.168.2.13  apache-web1
192.168.2.14  apache-web2

3. Make sure all the nodes are reachable between each others.

4. Internet must be enabled on all nodes, because we will be using official repositories to download and install required packages to setup keepalived linux cluster.

Steps Involved to Create Linux Cluster using KeepAlived.

On All Web Servers:

1. Install Apache2

2. Configure Apache2 Web Servers

3. Start and Enable Apache2 Service.

On All HAProxy Servers:

4. Install HAProxy

5. Setup HAProxy with Frontend and Backend Configuration.

6. Start and Enable HAProxy Service.

On All HAProxy Servers:

7. Install KeepAlived

8. Configure KeepAlived

9. Start and Enable KeepAlived Service.

Let's Get Started.

On All Web Servers (IP: 192.168.2.13 and 192.168.2.14):

1. Install Apache2

Use apt-get command to install Apache2 package as below.
# sudo apt update && sudo apt install -y apache2

2. Configure Apache2

Once Apache2 package is installed, configure the document root and modify the configuration if required.

I just modify the exsiting default index.html with sample content as below.
sudo echo "Test Data" > /var/www/html/index.html

3. Start and Enable Apache2 Service.

Use systemtctl to enable and start Apache2 service.

sudo systemctl enable apache2
sudo systemctl start apache2


On All HAProxy Servers (IP: 192.168.2.11 and 192.168.2.12):

1. Install HAProxy

Use apt-get command to install HAProxy package as below.
# sudo apt update && sudo apt install -y haproxy

2. Setup HAProxy with Frontend and Backend Configuration

Once HAProxy package is installed, edit the main configuration file /etc/haproxy/haproxy.conf with below frontend and backend configuration. Replace the Web Server IP Address with your Web Servers and even you can more webservers if you have any.

frontend myweb
bind *:80
option tcplog
mode tcp
default_backend web-servers
backend web-servers
mode tcp
balance roundrobin
option tcp-check
server web1 192.168.2.13:80 check fall 3 rise 2
server web2 192.168.2.14:80 check fall 3 rise 2


3. Start and Enable HAProxy.

Use systemctl command to start and enable the HAProxy service as below.

# systemctl restart haproxy
# systemctl enable haproxy

4. Install KeepAlived

Use apt-get command to install KeepAlived package as below.
# sudo apt update && sudo apt install -y keepalived

5. Configure KeepAlived

Once KeepAlived package is installed, create the main configuration file /etc/keepalived/keepalived.conf with below configuration. Replace the Highlighted values as per your configurations.

On Haproxy LB1 (192.168.2.11)
# Define the script used to check if haproxy is still working
vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 2
    weight 2
}
# Configuation for the virtual interface
vrrp_instance VI_1 {
    interface enp0s8
    state MASTER # set this to BACKUP on the other machine
    priority 101        # set this to 100 on the other machine
    virtual_router_id 51
    smtp_alert          # Activate email notifications
    authentication {
        auth_type AH
        auth_pass myPassw0rd      # Set this to some secret phrase
    }
    # The virtual ip address shared between the two loadbalancers
    virtual_ipaddress {
192.168.2.100
    }
    # Use the script above to check if we should fail over
    track_script {
        chk_haproxy
    }
}


On Haproxy LB2 (192.168.2.12)

# Define the script used to check if haproxy is still working
vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 2
    weight 2
}
# Configuation for the virtual interface
vrrp_instance VI_1 {
    interface enp0s8
    state BACKUP # set this to BACKUP on the other machine
    priority 100       # set this to 100 on the other machine
    virtual_router_id 51
    smtp_alert          # Activate email notifications
    authentication {
        auth_type AH
        auth_pass myPassw0rd      # Set this to some secret phrase
    }
    # The virtual ip address shared between the two loadbalancers
    virtual_ipaddress {
192.168.2.100
    }
    # Use the script above to check if we should fail over
    track_script {
        chk_haproxy
    }
}


6. Start and Enable KeepAlived Service.

Use systemctl command to start and enable the KeepAlived service as below.

# systemctl restart keepalived
# systemctl enable keepalived

 7. Test your configurations.

Once the keepalived service is started, we could see an virtual ip address 192.168.2.100 is configured on primary HAProxy Server as shown in the image below. Use ifconfig or ip a command to list the configured address.
ipaddress command examples

Use any browser to access the web through browser using the ip http://192.168.2.100..

In order to test the floating ip failover, shutdown the haproxy lb1 server, this will configure the virtual ip to the other node automatically as below.
linux ipaddress commands

Once you bring up the haproxy lb1 server, virtual ip will be configured back to the primary server.

Thats all for this post. Hope you have got an idea how to Configure HA Cluster using KeepAliveD on Ubuntu

Also You can Watch this Entire Tutorial video on our YouTube Channel - Configure HA Cluster using KeepAliveD on Ubuntu.



Also refer below related articles and checkout all tutorial videos for free on youtube.

What is Kubernetes - Learn Kubernetes from Basics
How to Install Kubernetes on Linux (RedHat / CentOS)
How to Install Kubernetes On Ubuntu 16.04 LTS
How to Create Kubernetes Deployment, Services & Pods Using Kubectl
How to Create Kubernetes YAML for Deployment, Service & Pods
Kubernetes Volumes Explained with Examples
Kubernetes Persistent Volumes and Claims Explained

Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.

إرسال تعليق

0 تعليقات