Last active
May 13, 2020 20:36
-
-
Save haproxytechblog/0a199786f091cf5179219e723bce2e83 to your computer and use it in GitHub Desktop.
HAProxy Data Plane API 2.0 Adds More Dynamic Features
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat urls.map | |
/api/ be_api | |
/documentation/ be_documentation | |
/blog/ be_blog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X POST \ | |
-F "fileUpload=@urls.map" \ | |
-u dataplaneapi:password \ | |
http://192.168.50.20:5555/v2/services/haproxy/runtime/maps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X POST \ | |
-H 'Content-Type: application/json' \ | |
-u dataplaneapi:password \ | |
-d '{"name":"%[path,lower,map_beg(/etc/haproxy/maps/urls.map,be_main)]","index":0}' \ | |
"http://192.168.50.20:5555/v2/services/haproxy/configuration/backend_switching_rules?frontend=fe_main&version=1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X GET -u dataplaneapi:password 192.168.50.20:5555/v2/services/haproxy/runtime/maps | |
[ | |
{ | |
"description": "pattern loaded from file '/etc/haproxy/maps/urls.map' used by map at file '/etc/haproxy/haproxy.cfg' line 37", | |
"file": "/etc/haproxy/maps/urls.map", | |
"id": "1" | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X POST \ | |
-H 'Content-Type: application/json' \ | |
-u dataplaneapi:password \ | |
-d '{"key":"/images/", "value": "be_static"}' \ | |
"http://192.168.50.20:5555/v2/services/haproxy/runtime/maps_entries?map=urls.map" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X DELETE \ | |
-u dataplaneapi:password \ | |
"192.168.50.20:5555/v2/services/haproxy/runtime/maps_entries/%2Fapi%2F?map=urls.map" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X POST \ | |
-H 'Content-Type: application/json' \ | |
-u dataplaneapi:password \ | |
-d '{"name": "login_requests", "stick_table": {"type": "ip", "size": 1000000, "expire": 600, "store": "http_req_rate(10m)"}}' \ | |
'192.168.50.20:5555/v2/services/haproxy/configuration/backends?version=1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X GET -u dataplaneapi:password \ | |
'192.168.50.20:5555/v2/services/haproxy/runtime/stick_tables' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X GET -u dataplaneapi:password \ | |
'192.168.50.20:5555/v2/services/haproxy/runtime/stick_tables/login_requests?process=1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X GET -u dataplaneapi:password \ | |
'192.168.50.20:5555/v2/services/haproxy/runtime/stick_table_entries?process=1&stick_table=http_requests' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
peers lb_cluster | |
peer host1 192.168.50.20:10000 | |
peer host2 192.168.50.21:10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
backend http_requests | |
stick-table type ip size 1m expire 10m peers lb_cluster store http_req_rate(10m) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X POST \ | |
-H 'Content-Type: application/json' \ | |
-u dataplaneapi:password \ | |
'192.168.50.20:5555/v2/services/haproxy/configuration/peer_section?version=1' \ | |
-d '{"name":"lb_cluster"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X POST \ | |
-H 'Content-Type: application/json' \ | |
-u dataplaneapi:password \ | |
'192.168.50.20:5555/v2/services/haproxy/configuration/peer_entries?version=2&peer_section=lb_cluster' \ | |
-d '{"name":"host1", "address":"192.168.50.20", "port":10000}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X PUT \ | |
-H 'Content-Type: application/json' \ | |
-u dataplaneapi:password \ | |
-d '{"name": "login_requests", "stick_table": {"type": "ip", "size": 1000000, "expire": 600, "store": "http_req_rate(10m)", "peers": "lb_cluster"}}' \ | |
'192.168.50.20:5555/v2/services/haproxy/configuration/backends/login_requests?version=1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X POST \ | |
-H 'Content-Type: application/json' \ | |
-u dataplaneapi:password \ | |
-d '{"name": "internal_dns", "parse_resolv-conf": false, "accepted_payload_size": 8192}' \ | |
'192.168.50.20:5555/v2/services/haproxy/configuration/resolvers?version=1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X POST \ | |
-H 'Content-Type: application/json' \ | |
-u dataplaneapi:password \ | |
-d '{"name": "ns1", "address": "10.0.0.1", "port": 53}' \ | |
'192.168.50.20:5555/v2/services/haproxy/configuration/nameservers?version=2&resolver=internal_dns' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resolvers internal_dns | |
nameserver ns1 10.0.0.1:53 | |
accepted_payload_size 8192 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X PUT \ | |
-H 'Content-Type: application/json' \ | |
-u dataplaneapi:password \ | |
-d '{"name": "server1", "address": "server1.site.com", "port": 8080, "check": "enabled", "resolvers": "internal_dns"}' \ | |
'192.168.50.20:5555/v2/services/haproxy/configuration/servers/server1?version=1&backend=be_main' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST \ | |
-H 'Content-Type: application/json' \ | |
-u dataplaneapi:password \ | |
-d '{"index": 0, "type": "track-sc0", "track-sc0-key": "src", "track-sc0-table": "login_requests", "cond": "if", "cond_test": "{ path_beg /login }"}' \ | |
'192.168.50.20:5555/v2/services/haproxy/configuration/http_request_rules?version=1&parent_type=frontend&parent_name=fe_main' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http-request track-sc0 src table login_requests if { path_beg /login } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment