UncleNUC Wiki

Second chance for NUCs

User Tools

Site Tools


lab:stack_-_install_haproxy

This is an old revision of the document!


Install HAProxy

In our previous step we deployed a web app to Kubernetes on our Stack of NUCs.

Now we are going to install HAProxy.

Purpose:

  • Demonstrate a using HAProxy in front of a web application on Kubernetes

References

Step 1 - Connect to the Ansible control node

From NUC 1, log in to the Ansible control node, NUC 2.

Step 2 - Set Up a Folder for Configuration and Playbooks

  1. Create folder /home/ansible/my-project/haproxy and change directory to it
  2. Copy the hosts file we created early in the lab
    • cp /home/ansible/my-project/hosts /home/ansible/my-project/haproxy/
  3. Create the file /home/ansible/my-project/haproxy/ansible.cfg
  4. Create the file /home/ansible/my-project/haproxy/haproxy.cfg.j2
    • haproxy.cfg.j2
      # ------------------------
      # main frontend which proxys to the backends
      # ------------------------
      frontend main
          bind *:8080
          acl url_static  path_beg    -i /static /images /javascript /stylesheets
          acl url_static  path_end    -i .jpg .gif .png .css .js
       
          use_backend static  if url_static
          default_backend app
      # ------------------------
      # static backend for serving up images, stylesheets and such
      # ------------------------
      backend static
          balance roundrobin
          server  static 127.0.0.1:4331 check
      # ------------------------
      # round robin balancing between the various backends
      # ------------------------
      backend app
          balance roundrobin
      {% for ip in groups['nodes']}
          server app{{ loop.index}} {{ ip }}:80 check

Step 3 - Install HAProxy

haproxy-install.yml
---
- hosts: nodes
  tasks:
    - name: Install haproxy
      package:
        name: haproxy
        state: present
    - name: Configure haproxy.cfg file
      template:
        src: "/home/ansible/my-project/haproxy/haproxy.cfg.j2"
        dest: "/etc/haproxy/haproxy.cfg"
    - name: "haproxy service start"
      service:
        name: haproxy
        state: restarted

ansible-playbook haproxy-install.yml

lab/stack_-_install_haproxy.1682904498.txt.gz ยท Last modified: 2023/05/01 01:28 by user