Auto-scaling OpenStack Instances with Senlin and Prometheus
Prerequisite
openstack cloud
Prometheus
Alertmanager
ทั้ง Prometheus เเละ Alertmanager ควรใช้งานเป็น version ล่าสุด
Installation Openstack client, Senlin client, and Octavia client
update packet cache
sudo apt updateInstall Python3
sudo apt install python3-dev python3-pipinstall the OpenStack client
sudo apt install python3-openstackclientverify by accessing the help tools
openstack --help

build environment python for Senlin client and Octavia client
sudo python3 -m venv /opt/osenv sudo chmod -R 777 /opt/osenvuse command
sourceto use environment pythonsource /opt/osenv/bin/activateinstall the Senlin client and Octavia client
pip install python-senlinclient python-octaviaclientverify install Senlin client and Octavia client
Senlin
openstack cluster -h
Octavia
openstack loadbalancer -h
Requirement
ติดตั้ง Openstack cli ลงในเครื่อง ubuntu
OpenStack RC File
Setup Senlin Cluster
สร้าง Instance ขึ้นมา 1 ตัวที่ติดตั้งเพื่อใช้ในการสร้าง Cluster [OPTIONAL] ด้วย command ดังนี้ :
หลังจากนั้น remote เข้า instance ด้วย command ssh -i [path-file-privatekey] username@host-IP เพื่อ install Openstack Client เเละ Senlin Client ดูได้ที่ Prerequisite
สร้าง Cluster ด้วย Senlin
สร้างไฟล์ node_exporter_profile.yaml

ทำการเเก้ไขภายในไฟล์ node_exporter_profile.yaml สามารถดู Properties เพิ่มเติมได้ที่ Nova Profile
Note: ในส่วนของ image: เเละ block_device_mapping_v2: เลือกใช้อย่างใดอย่างหนึ่งเท่านั้น
Limitation: admin_pass ไม่สามารถใช้งานได้
ในส่วนของ userdata จะทำการติดตั้ง Node exporter , Nginx , Nginx Exporter
หากใช้ IIS ให้เเก้ไข node_exporter_profile.yaml ดังนี้เเทน
สร้าง Cluster Profile จาก ไฟล์ node_exporter_profile.yaml
Note : {profile_name} สามารถใส่เป็นชื่ออะไรก็ได้

สร้าง Cluster จาก Profile ที่สร้างไว้ในข้อที่ 2
Note: {Clustername} สามารถใส่เป็นชื่ออะไรก็ได้
หรือ
สร้าง Receiver เพื่อใช้ในการ trigger scale in เเละ scale out
หลังจากสร้าง Receiver ให้ทำการ Copy alarm_url ไว้ทุกครั้ง เพื่อใช้ในส่วนของการ Setup Alertmanager ต่อ
ตัวอย่างเช่น

alarm_url คือ https://cloud-api.nipa.cloud:8778/v1/webhooks/cec91e87-f31d-4471-b451-283a8e382c7d/trigger?V=2

alarm_url คือ https://cloud-api.nipa.cloud:8778/v1/webhooks/e2dc6ab7-4827-4477-b4f7-90f849dfd47a/trigger?V=2
หากต้องการเรียกดู alarm_url ภายหลังสามารถใช้คำสั่ง
สามารถดู metrics ของ node exporter ได้ที่ http://<FloatingIP>:9100/metrics
Config Prometheus
สร้าง Instance สำหรับ ติดตั้ง Prometheus (สามารถนำ command สร้าง Instance จาก Setup Senlin Cluster มาใช้ในการสร้างได้)
ติดตั้ง Prometheus (ควรใช้เวอร์ชั่นล่าสุด)
สร้าง application credential ที่ใช้ใน config ให้ใช้ ซึ่ง application_credential_secret จะเเสดงเเค่ครั้งเเรกที่สร้างเท่านั้น
เมื่อติดตั้ง Prometheus เรียบร้อยแล้ว ให้แก้ไขไฟล์ config ของ prometheus ที่ path: /etc/prometheus/prometheus.yml โดยทำการเเก้ไขไฟล์ config ดังนี้
ในโฟลเดอร์เดียวกันกับ /etc/prometheus/ ให้สร้าง alert_rules.yml ด้วย จากนั้นเเก้ไขไฟล์ alert_rules.yml ดังนี้ โดย rule ที่ใช้จะขึ้นกับตัว Exporter ที่ผู้ใช้งานเลือกใช้
4.1 กรณีใช้กับ Node Exporter
4.2 กรณีใช้กับ Nginx Exporter
4.3 กรณีใช้กับ Window_Exporter(for IIS)
Restart prometheus service
สามารถตรวจสอบได้ที่หน้าเว็บ UI ของ Prometheus http://{FloatingIP}:9090
Config Alertmanager
ติดตั้ง Alertmanager ภายใน instance เดียวกันกับ Prometheus (ควรติดตั้งเวอร์ชั่นล่าสุด)
แก้ไขไฟล์ /etc/alertmanager/alertmanager.yml เพื่อทำการเเก้ไขในส่วนของ url: เป็น alarm_url ที่ copy ไว้ตอนสร้าง senlin receiver
limitation : ควรปรับให้ repeat_interval เป็น 5-10 นาที (5-10m) เนื่องจาก cluster สามารถ scale in ได้รอบละ 1 node ต่อ 1 trigger หากปรับนานกว่านั้นจะทำให้การ scale in ช้าลง
Restart alertmanager service
สามารถตรวจสอบได้จากหน้า web UI ของ Alertmanager
http://{FloatingIP}:9093/#/alerts
Config Load-Balancing Policy
ภายใต้โฟลเดอร์เดียวกันกับที่สร้าง Cluster Profile ให้สร้างไฟล์ ชื่อ lb_policy.yaml

เเก้ไขไฟล์ lb_policy.yaml ดังนี้ ซึ่งมี 2 กรณี
2.1 กรณี ใช้ lb_policy ในการสร้าง loadbalancer ให้อัตโนมัติหลังผูกกับ cluster
2.2 กรณีที่ผู้ใช้สร้าง loadbalancer ไว้เองเเล้วไปผูกกับ cluster ทีหลัง โดยค่าต่างๆที่ใช้ในเเต่ละ argument ควรจะตรงกับค่าของ loadbalancer ที่ต้องการผูก
จากนั้นใช้ command สร้าง policy จากไฟล์ lb_policy.yaml

นำ policy ที่สร้างมาผูกกับ cluster ที่สร้างไว้
Last updated
Was this helpful?