lab:stack_of_nucs:ansible_playbook_-_install_haproxy
This is an old revision of the document!
Table of Contents
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
Step 2 - Set Up a Folder for Configuration and Playbooks
- Create folder
/home/ansible/my-project/haproxy
and change directory to it - Copy the
hosts
file we created early in the labcp /home/ansible/my-project/hosts /home/ansible/my-project/haproxy/
- Create the file
/home/ansible/my-project/haproxy/ansible.cfg
- ansible.cfg
[defaults] inventory = hosts
- 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
- Point your browser to
http://IPANYK8WORKER:8080/
- 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 pods
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
Next Step
You have complete this Lab! What did you think of it? What suggestions do you have for improvement? Let UncleNUC know!
lab/stack_of_nucs/ansible_playbook_-_install_haproxy.1682970030.txt.gz ยท Last modified: 2023/05/01 19:40 by user