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
      {% endfor %}

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

Step 4 - Test HAProxy

  1. Point your browser to http://IPANYK8WORKER:8080/
  2. Let's prove that any of the nodes will serve the app from any pod on any host
    • Change directory to /home/ansible/my-project/k8s
    • Edit speedtester-deployment.yml and change the number of replicas to 1
    • kubectl apply -f speedtester-deployment.yml
    • Use kubectl get pows to watch the pods terminated until 1 is left running
    • Point your browser to any of the k8s working IPs on port 8080 and note the app is still up
    • Set the replicas back to equal the number of worker nodes and apply the file again
lab/stack_-_install_haproxy.1682905717.txt.gz ยท Last modified: 2023/05/01 01:48 by user