5

Deploy ProxySQL as a service on Kubernetes using Azure Database for MySQL

 3 years ago
source link: https://techcommunity.microsoft.com/t5/azure-database-for-mysql/deploy-proxysql-as-a-service-on-kubernetes-using-azure-database/ba-p/1105959
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Deploy ProxySQL as a service on Kubernetes using Azure Database for MySQL%3CLINGO-SUB%20id%3D%22lingo-sub-1106658%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20ProxySQL%20as%20a%20service%20on%20Kubernetes%20using%20Azure%20Database%20for%20MySQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1106658%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%26nbsp%3B%3CSPAN%20style%3D%22display%3A%20inline%20!important%3B%20float%3A%20none%3B%20background-color%3A%20%23ffffff%3B%20color%3A%20%23333333%3B%20font-family%3A%20'SegoeUI'%2C'Lato'%2C'Helvetica%20Neue'%2CHelvetica%2CArial%2Csans-serif%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%3EAmol%20Bhatnagar%3C%2FSPAN%3E%20for%20sharing%20the%20Great%20blogpost%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Fhtml%2Fimages%2Femoticons%2Fcool_40x40.gif%22%20alt%3D%22%3Acool%3A%22%20title%3D%22%3Acool%3A%22%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1105959%22%20slang%3D%22en-US%22%3EDeploy%20ProxySQL%20as%20a%20service%20on%20Kubernetes%20using%20Azure%20Database%20for%20MySQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1105959%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--1416308594%22%20id%3D%22toc-hId--1416308594%22%20id%3D%22toc-hId--1416308594%22%3E%3CSPAN%3EOverview%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EIn%20the%20distributed%20application%2C%20it%E2%80%99s%20quite%20common%20to%20use%20load%20balancers%20so%20that%20your%20application%20isn%E2%80%99t%20dependent%20on%20database%20topologies%2C%20to%20easily%20load%20balance%20the%20workload%2C%20and%20to%20do%20connection%20failover.%20%3CA%20href%3D%22https%3A%2F%2Fwww.proxysql.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EProxySQL%3C%2FA%3E%3CSPAN%3E%2C%20a%20high-performance%20MySQL%20proxy%2C%3C%2FSPAN%3E%3CSPAN%3E%20allows%20users%20to%20send%20different%20queries%20to%20multiple%20servers%20to%20distribute%20the%20load%20more%20efficiently.%3C%2FSPAN%3E%20%3CSPAN%3EProxySQL%20has%20several%20benefits%2C%20including%20intelligent%20load%20balancing%20across%20different%20databases%20and%20the%20ability%20to%20determine%20if%20a%20database%20instance%20is%20running%20so%20that%20read%20traffic%20can%20be%20redirected%20accordingly.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThis%3CSPAN%3E%20blog%20post%20takes%20an%20example%20of%20Azure%20Kubernetes%20Service%20(AKS)%20to%20deploy%20ProxySQL%20as%20a%20service%20to%20split%20the%20read%20and%20write%20%3C%2FSPAN%3E%3CSPAN%3Eworkloads%3C%2FSPAN%3E%3CSPAN%3E%20to%20Azure%20Database%20for%20MySQL.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImportant%3C%2FSTRONG%3E%3A%20Azure%20Database%20for%20MySQL%20supports%20ProxySQL%20version%202.0.6%20and%20later.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENote%3A%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EProxySQL%20is%20an%20open%20source%20community%20tool.%20It%20is%20supported%20by%20Microsoft%20on%20a%20best%20effort%20basis.%20In%20order%20to%20get%20production%20support%20with%20authoritative%20guidance%2C%20you%20can%20evaluate%20and%20reach%20out%20to%20%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fproxysql.com%252Fservices%252Fsupport%252F%26amp%3Bdata%3D02%257C01%257CAmol.Bhatnagar%2540microsoft.com%257C648e1ab1ec23494dc5bd08d814d6de91%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C637282260392282862%26amp%3Bsdata%3Dv7EoCThD9VAeoZOOwmxGqUlfDtu9W7FqCRN1ZhfSnEE%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EProxySQL%20Product%20support%3C%2FA%3E.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1071204239%22%20id%3D%22toc-hId-1071204239%22%20id%3D%22toc-hId-1071204239%22%3E%3CSPAN%3EProxySQL%20as%20a%20service%20in%20AKS%20using%20Azure%20Database%20for%20MySQL%20setup%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EThe%20basic%20setup%20for%20running%20ProxySQL%20as%20a%20service%20in%20AKS%20using%20Azure%20Database%20for%20MySQL%20is%20shown%20in%20Figure%201.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22Capture.PNG%22%20style%3D%22width%3A%20433px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F165084i3553FF5488720D82%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Capture.PNG%22%20alt%3D%22Capture.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--736250224%22%20id%3D%22toc-hId--736250224%22%20id%3D%22toc-hId--736250224%22%3E%3CSPAN%3EPrerequisites%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3ETo%20prepare%20for%20setting%20up%20ProxySQL%20as%20a%20service%20in%20AKS%2C%20you%20need%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EAzure%20CLI%3C%2FSTRONG%3E.%20To%20install%20Azure%20CLI%2C%20refer%20to%20-ERR%3AREF-NOT-FOUND-installing%20Azure%20CLI.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EKubernetes%20command-line%20interface%3C%2FSTRONG%3E.%20To%20install%20Kubernetes%20command-line%20interface%2C%20run%20the%20following%20command%3A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Esudo%20az%20aks%20install-cli%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EAn%20Azure%20Kubernetes%20Service%20cluster%3C%2FSTRONG%3E.%20For%20more%20information%2C%20see%20the%20article%20-ERR%3AREF-NOT-FOUND-Deploy%20an%20Azure%20Kubernetes%20Service%20(AKS)%20cluster%20using%20Azure%20portal.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EAn%20Azure%20Database%20for%20MySQL%20server%20to%20use%20as%20host%20group%200%20(the%20Master%20Server)%3C%2FSTRONG%3E.%20For%20more%20information%2C%20see%20the%20article%20-ERR%3AREF-NOT-FOUND-Create%20an%20Azure%20Database%20for%20MySQL%20server%20by%20using%20the%20Azure%20portal.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BProxySQL%20will%20be%20configured%20to%20direct%20all%20the%20write%20workload%20to%20this%20server.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EEnable%20%E2%80%9CAllow%20access%20to%20Azure%20services%E2%80%9D%20in%20Azure%20Database%20for%20MySQL%20master%20server%3C%2FSTRONG%3E.%20For%20more%20information%2C%20see%20-ERR%3AREF-NOT-FOUND-Connecting%20from%20Azure%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EAn%20Azure%20Database%20for%20MySQL%20server%20to%20use%20as%20the%20host%20group%201%20(the%20Read%20Replica%20server%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FSTRONG%3E.%20For%20more%20information%2C%20see%20-ERR%3AREF-NOT-FOUND-Create%20a%20replica.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BProxySQL%20will%20be%20configured%20to%20direct%20all%20the%20read%20workload%20to%20this%20server.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImportant%3C%2FSTRONG%3E%3A%20Enforcement%20of%20SSL%20connections%20is%20enabled%20by%20default%20in%20Azure%20Database%20for%20MySQL.%20You%20should%20avoid%20disabling%20the%20SSL%20option%20and%20instead%20configure%20ProxySQL%20to%20use%20SSL%20as%20outlined%20below.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1751262609%22%20id%3D%22toc-hId-1751262609%22%20id%3D%22toc-hId-1751262609%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--56191854%22%20id%3D%22toc-hId--56191854%22%20id%3D%22toc-hId--56191854%22%3E%3CSPAN%3EProcedure%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3ESetting%20up%20ProxySQL%20as%20a%20service%20in%20AKS%20using%20Azure%20Database%20for%20MySQL%20involves%20the%20following%20tasks%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%3ECreating%3C%2FSPAN%3E%20MySQL%20users%20on%20the%20Master%20Server.%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3EPreparing%20configMap%20for%20ProxySQL.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3EPreparing%20the%20ProxySQL%20pod%20and%20service%20definition.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3EDeploying%20the%20resources.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId--1863646317%22%20id%3D%22toc-hId--1863646317%22%20id%3D%22toc-hId--1863646317%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId-623866516%22%20id%3D%22toc-hId-623866516%22%20id%3D%22toc-hId-623866516%22%3E%3CSPAN%3ECreate%20MySQL%20users%20on%20the%20Master%20Server%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EWith%20ProxySQL%2C%20the%20user%20connects%20to%20ProxySQL%20and%20in%20turn%20ProxySQL%20passes%20the%20connection%20to%20the%20MySQL%20node.%20To%20allow%20ProxySQL%20to%20access%20to%20the%20MySQL%20database%2C%20you%20need%20to%20create%20a%20user%20on%20the%20MySQL%20database%20with%20the%20same%20credentials%20as%20on%20the%20ProxySQL%20server%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ELog%20in%20to%20the%20Azure%20Database%20for%20MySQL%20Master%20Server.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Emysql%20-hmydemomaster.mysql.database.azure.com%20-umydemo%40mydemomaster%20-p%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3ECreate%20a%20new%20%3C%2FSPAN%3Euser%3CSPAN%3E%3CSPAN%3E%20%E2%80%98mydemouser%E2%80%99%20that%20has%20the%20password%20%E2%80%98secretpassword%E2%80%99.%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ECREATE%20USER%20'mydemouser'%40'%25'%20IDENTIFIED%20BY%20'secretpassword'%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3EGrant%20%E2%80%98mydemouser%E2%80%99%20privileges%20to%20fully%20access%20the%20Azure%20Database%20for%20MySQL%20server.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGRANT%20SELECT%2C%20INSERT%2C%20UPDATE%2C%20DELETE%2C%20CREATE%2C%20DROP%2C%20RELOAD%2C%20PROCESS%2C%20REFERENCES%2C%20INDEX%2C%20ALTER%2C%20SHOW%20DATABASES%2C%20CREATE%20TEMPORARY%20TABLES%2C%20LOCK%20TABLES%2C%20EXECUTE%2C%20REPLICATION%20SLAVE%2C%20REPLICATION%20CLIENT%2C%20CREATE%20VIEW%2C%20SHOW%20VIEW%2C%20CREATE%20ROUTINE%2C%20ALTER%20ROUTINE%2C%20CREATE%20USER%2C%20EVENT%2C%20TRIGGER%20ON%20*.*%20TO%20'mydemouser'%40'%25'%20WITH%20GRANT%20OPTION%3B%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3EApply%20the%20changes%20to%20the%20permissions.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EFLUSH%20PRIVILEGES%3B%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22toc-hId--1183587947%22%20id%3D%22toc-hId--1183587947%22%20id%3D%22toc-hId--1183587947%22%3E%3CSPAN%3EPrepare%20configMap%20for%20ProxySQL%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EFor%20the%20purposes%20of%20this%20post%2C%20we%20use%20the%20configMap%20to%20deploy%20the%20configuration%20to%20the%20ProxySQL%20container.%3CSPAN%3E%20Begin%20with%20the%20sample%20ProxySQL%20configMap%20file%20provided%20below.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Edatadir%3D%22%2Fvar%2Flib%2Fproxysql%22%0Aadmin_variables%3D%0A%7B%0A%20%20%20%20%20%20%20%20admin_credentials%3D%22admin%3Aadmin%22%0A%20%20%20%20%20%20%20%20mysql_ifaces%3D%220.0.0.0%3A6032%22%0A%7D%0Amysql_variables%3D%0A%7B%0A%20%20%20%20%20%20%20%20threads%3D4%0A%20%20%20%20%20%20%20%20max_connections%3D2048%0A%20%20%20%20%20%20%20%20default_query_delay%3D0%0A%20%20%20%20%20%20%20%20default_query_timeout%3D36000000%0A%20%20%20%20%20%20%20%20have_compress%3Dtrue%0A%20%20%20%20%20%20%20%20poll_timeout%3D2000%0A%20%20%20%20%20%20%20%20interfaces%3D%220.0.0.0%3A3306%3B%2Ftmp%2Fproxysql.sock%22%0A%20%20%20%20%20%20%20%20default_schema%3D%22information_schema%22%0A%20%20%20%20%20%20%20%20stacksize%3D1048576%0A%20%20%20%20%20%20%20%20server_version%3D%225.1.30%22%0A%20%20%20%20%20%20%20%20connect_timeout_server%3D10000%0A%20%20%20%20%20%20%20%20monitor_history%3D60000%0A%20%20%20%20%20%20%20%20monitor_connect_interval%3D200000%0A%20%20%20%20%20%20%20%20monitor_ping_interval%3D200000%0A%20%20%20%20%20%20%20%20ping_interval_server_msec%3D10000%0A%20%20%20%20%20%20%20%20ping_timeout_server%3D200%0A%20%20%20%20%20%20%20%20commands_stats%3Dtrue%0A%20%20%20%20%20%20%20%20sessions_sort%3Dtrue%0A%20%20%20%20%20%20%20%20monitor_username%3D%22proxysql%22%0A%20%20%20%20%20%20%20%20monitor_password%3D%22proxysqlsecretpassword%22%0A%7D%0Amysql_servers%20%3D%0A(%0A%20%20%20%20%20%20%20%20%7B%20hostgroup_id%3D1%2C%20hostname%3D%22mydemomaster.mysql.database.azure.com%22%2C%20port%3D3306%20%2C%20weight%3D1%2C%20comment%3D%22write%20Group%22%2C%20use_ssl%3D1%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%20hostgroup_id%3D2%2C%20hostname%3D%22mydemoreplica.mysql.database.azure.com%22%2C%20port%3D3306%20%2C%20weight%3D1%2C%20comment%3D%22Read%20Group%22%2C%20use_ssl%3D1%20%20%7D%0A)%0Amysql_users%20%3D%0A(%0A%20%20%20%20%20%20%20%20%7B%20username%20%3D%20%22mydemouser%22%20%2C%20password%20%3D%20%22secretpassword%22%20%2C%20default_hostgroup%20%3D%201%20%2C%20active%20%3D%201%20%7D%0A)%0Amysql_query_rules%20%3D%0A(%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rule_id%3D1%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20active%3D1%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20match_digest%3D%22%5ESELECT%20.*%20FOR%20UPDATE%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20destination_hostgroup%3D1%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20apply%3D1%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rule_id%3D2%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20active%3D1%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20match_digest%3D%22%5ESELECT%20.*%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20destination_hostgroup%3D2%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20apply%3D1%0A%20%20%20%20%20%20%20%20%7D%2C%0A)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%3EIn%20the%20configMap%20file%2C%20modify%20the%20following%20parameters%3A%3C%2FSPAN%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%3E%3CSTRONG%3Eadmin_variables%3C%2FSTRONG%3E%3C%2FSPAN%3E%3CSPAN%3E%3A%20Modify%20admin_credentials%20to%20update%20the%20ProxySQL%20admin%20credentials.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSTRONG%3Emysql_servers%3C%2FSTRONG%3E%3C%2FSPAN%3E%3CSPAN%3E%3A%20Modify%20this%20parameter%20to%20update%20Azure%20Database%20for%20MySQL%20server%20and%20read-replica%20details.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSTRONG%3Emysql_variables%3C%2FSTRONG%3E%3C%2FSPAN%3E%3CSPAN%3E%3A%20Add%20or%20modify%20the%20variables.%20For%20example%2C%20you%20can%20modify%20monitoring%20user%20and%20password.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSTRONG%3Emysql_users%3C%2FSTRONG%3E%3C%2FSPAN%3E%3CSPAN%3E%3A%20Modify%20this%20parameter%20to%20update%20the%20ProxySQL%20user.%20You%20can%20connect%20to%20the%20ProxySQL%20through%20this%20user.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSTRONG%3Emysql_query_rules%3C%2FSTRONG%3E%3C%2FSPAN%3E%3CSPAN%3E%3A%20Modify%20this%20parameter%20to%20configure%20the%20routing%20rules%20for%20read%20and%20write%20split.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId-1303924886%22%20id%3D%22toc-hId-1303924886%22%20id%3D%22toc-hId-1303924886%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--503529577%22%20id%3D%22toc-hId--503529577%22%20id%3D%22toc-hId--503529577%22%3E%3CSPAN%3EPrepare%20ProxySQL%20pod%20and%20service%20definition%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%3CSPAN%3EBegin%20with%20the%20sample%20ProxySQL%20deployment%20file%20below.%20This%20template%20uses%20the%20latest%20ProxySQL%20docker%20image.%20You%20can%20update%20the%20number%20of%20replicas%2C%20restart%20policy%20and%20container%20port%20for%20ProxySQL.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EapiVersion%3A%20apps%2Fv1%0Akind%3A%20Deployment%0Ametadata%3A%0A%20%20name%3A%20proxysql%0Aspec%3A%0A%20%20replicas%3A%201%0A%20%20selector%3A%0A%20%20%20%20matchLabels%3A%0A%20%20%20%20%20%20app%3A%20proxysql%0A%20%20%20%20%20%20tier%3A%20frontend%0A%20%20template%3A%0A%20%20%20%20metadata%3A%0A%20%20%20%20%20%20labels%3A%0A%20%20%20%20%20%20%20%20app%3A%20proxysql%0A%20%20%20%20%20%20%20%20tier%3A%20frontend%0A%20%20%20%20spec%3A%0A%20%20%20%20%20%20restartPolicy%3A%20Always%0A%20%20%20%20%20%20containers%3A%0A%20%20%20%20%20%20-%20name%3A%20proxysql%0A%20%20%20%20%20%20%20%20image%3A%20proxysql%2Fproxysql%3Alatest%0A%20%20%20%20%20%20%20%20volumeMounts%3A%0A%20%20%20%20%20%20%20%20-%20name%3A%20%22proxysql-config%22%0A%20%20%20%20%20%20%20%20%20%20mountPath%3A%20%22%2Fetc%2Fproxysql.cnf%22%0A%20%20%20%20%20%20%20%20%20%20subPath%3A%20%22proxysql.cnf%22%0A%20%20%20%20%20%20%20%20ports%3A%0A%20%20%20%20%20%20%20%20-%20containerPort%3A%203306%0A%20%20%20%20%20%20%20%20%20%20name%3A%20%22proxysql-mysqldb%22%0A%20%20%20%20%20%20%20%20-%20containerPort%3A%206032%0A%20%20%20%20%20%20%20%20%20%20name%3A%20%22proxysql-admin%22%0A%20%20%20%20%20%20volumes%3A%0A%20%20%20%20%20%20-%20name%3A%20%22proxysql-config%22%0A%20%20%20%20%20%20%20%20configMap%3A%0A%20%20%20%20%20%20%20%20%20%20name%3A%20%22proxysql-configmap%22%0A---%0AapiVersion%3A%20v1%0Akind%3A%20Service%0Ametadata%3A%0A%20%20name%3A%20proxysql%0A%20%20labels%3A%0A%20%20%20%20app%3A%20proxysql%0A%20%20%20%20tier%3A%20frontend%0Aspec%3A%0A%20%20type%3A%20LoadBalancer%0A%20%20ports%3A%0A%20%20-%20port%3A%203306%0A%20%20%20%20name%3A%20%22proxysql-mysqldb%22%0A%20%20-%20port%3A%206032%0A%20%20%20%20name%3A%20%22proxysql-admin%22%0A%20%20selector%3A%0A%20%20%20%20app%3A%20proxysql%0A%20%20%20%20tier%3A%20frontend%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--637214301%22%20id%3D%22toc-hId--637214301%22%20id%3D%22toc-hId--637214301%22%3E%3CSPAN%3EDeploy%20the%20resources%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3ENext%2C%20you%E2%80%99ll%20deploy%20ProxySQL%20on%20AKS.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EConfigure%20kubectl%20to%20use%20the%20credential%20for%20the%20new%20AKS%20cluster.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Eaz%20aks%20get-credentials%20--name%20aks-cluster-name%20%20--resource-group%20%22mydemo%22%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3EDeploy%20the%20configMap.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Ekubectl%20create%20configmap%20proxysql-configmap%20--from-file%3Dproxysql.cnf%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3EDeploy%20ProxySQL%20using%20the%20proxysql%20deployment%20file.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Ekubectl%20apply%20-f%20.%2Fproxysqlaks.yml%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3EWatch%20the%20deployment%20to%20see%20whether%20external%20links%20are%20generated%20by%20AKS.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Ekubectl%20get%20service%20proxysql%20-w%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3CSTRONG%3E%5BUse%20CTRL%20%2B%20C%20to%20break%20out%5D%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EAfter%20the%20external%20IP%20is%20generated%20for%20ProxySQL%20service%2C%20use%20the%20below%20command%20to%20connect%20to%20ProxySQL%20and%20verify%20all%20config.%0A%3COL%3E%0A%3CLI%3EUse%20the%20below%20command%20to%20get%20the%20external%20IP%20of%20the%20proxysql%20service.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Ekubectl%20get%20pods%2Cservices%20-o%20wide%20%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FLI%3E%0A%3CLI%3EConnect%20to%20ProxySQL%20using%20this%20external%20IP%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Emysql%20-h%5BExternal_IP%5D%20-umydemouser%20-psecretpassword%20-P3306%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%3ETo%20learn%20%3C%2FSPAN%3Ehow%20to%20scale%20your%20WordPress%20application%20using%20ProxySQL%20deployed%20as%20service%20in%20AKS%20to%20perform%20transparent%20read%2Fwrite%20split%20across%20Azure%20Database%20for%20MySQL%20replicas%2C%20see%20the%20blog%20post%20-ERR%3AREF-NOT-FOUND-scaling%20your%20Azure%20Database%20for%20MySQL%20workload%20running%20on%20Kubernetes%20with%20read%20replicas%20and%20ProxySQL.%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIf%20you%20have%20trouble%20setting%20up%20ProxySQL%20as%20a%20service%20using%20Azure%20Database%20for%20MySQL%2C%20please%20contact%20the%20Azure%20Database%20for%20MySQL%20team%20at%20%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-AskAzureDBforMySQL%40service.microsoft.com%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThank%20you!%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EAmol%20Bhatnagar%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EProgram%20Manager%20-%20Microsoft%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1105959%22%20slang%3D%22en-US%22%3E%3CP%3EThis%3CSPAN%3E%20blog%20post%20takes%20an%20example%20of%20Azure%20Kubernetes%20Service%20(AKS)%20to%20deploy%20ProxySQL%20as%20a%20service%20to%20split%20the%20read%20and%20write%20%3C%2FSPAN%3E%3CSPAN%3Eworkloads%3C%2FSPAN%3E%3CSPAN%3E%20to%20Azure%20Database%20for%20MySQL.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1105959%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeploy%20ProxySQL%20as%20a%20service%20on%20Kubernetes%20using%20Azure%20Database%20for%20MySQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1570522%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20ProxySQL%20as%20a%20service%20on%20Kubernetes%20using%20Azure%20Database%20for%20MySQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1570522%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20using%20App%20Service%20and%20MySQL%20PaaS%20with%20Read%20Replicas%20in%20Azure.%20Is%20it%20possible%20to%20have%20the%20ProxySQL%20feature%20in%20App%20Service%20without%20AKS%20or%20Dedicated%20VM%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E

‎01-13-2020 12:00 PM

Overview

In the distributed application, it’s quite common to use load balancers so that your application isn’t dependent on database topologies, to easily load balance the workload, and to do connection failover. ProxySQL, a high-performance MySQL proxy, allows users to send different queries to multiple servers to distribute the load more efficiently. ProxySQL has several benefits, including intelligent load balancing across different databases and the ability to determine if a database instance is running so that read traffic can be redirected accordingly.

This blog post takes an example of Azure Kubernetes Service (AKS) to deploy ProxySQL as a service to split the read and write workloads to Azure Database for MySQL.

Important: Azure Database for MySQL supports ProxySQL version 2.0.6 and later.

Note:

ProxySQL is an open source community tool. It is supported by Microsoft on a best effort basis. In order to get production support with authoritative guidance, you can evaluate and reach out to ProxySQL Product support.

ProxySQL as a service in AKS using Azure Database for MySQL setup

The basic setup for running ProxySQL as a service in AKS using Azure Database for MySQL is shown in Figure 1.

Prerequisites

To prepare for setting up ProxySQL as a service in AKS, you need:

         ProxySQL will be configured to direct all the write workload to this server.

  • Enable “Allow access to Azure services” in Azure Database for MySQL master server. For more information, see Connecting from Azure.
  • An Azure Database for MySQL server to use as the host group 1 (the Read Replica server). For more information, see Create a replica.

         ProxySQL will be configured to direct all the read workload to this server.

Important: Enforcement of SSL connections is enabled by default in Azure Database for MySQL. You should avoid disabling the SSL option and instead configure ProxySQL to use SSL as outlined below.

Procedure

Setting up ProxySQL as a service in AKS using Azure Database for MySQL involves the following tasks:

  • Creating MySQL users on the Master Server.
  • Preparing configMap for ProxySQL.
  • Preparing the ProxySQL pod and service definition.
  • Deploying the resources.

Create MySQL users on the Master Server

With ProxySQL, the user connects to ProxySQL and in turn ProxySQL passes the connection to the MySQL node. To allow ProxySQL to access to the MySQL database, you need to create a user on the MySQL database with the same credentials as on the ProxySQL server

  1. Log in to the Azure Database for MySQL Master Server.
    mysql -hmydemomaster.mysql.database.azure.com -umydemo@mydemomaster -p​
  2. Create a new user ‘mydemouser’ that has the password ‘secretpassword’.
    CREATE USER 'mydemouser'@'%' IDENTIFIED BY 'secretpassword';
  3. Grant ‘mydemouser’ privileges to fully access the Azure Database for MySQL server.
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'mydemouser'@'%' WITH GRANT OPTION;​
  4. Apply the changes to the permissions.
    FLUSH PRIVILEGES;​

Prepare configMap for ProxySQL

For the purposes of this post, we use the configMap to deploy the configuration to the ProxySQL container. Begin with the sample ProxySQL configMap file provided below.

datadir="/var/lib/proxysql"
admin_variables=
{
        admin_credentials="admin:admin"
        mysql_ifaces="0.0.0.0:6032"
}
mysql_variables=
{
        threads=4
        max_connections=2048
        default_query_delay=0
        default_query_timeout=36000000
        have_compress=true
        poll_timeout=2000
        interfaces="0.0.0.0:3306;/tmp/proxysql.sock"
        default_schema="information_schema"
        stacksize=1048576
        server_version="5.1.30"
        connect_timeout_server=10000
        monitor_history=60000
        monitor_connect_interval=200000
        monitor_ping_interval=200000
        ping_interval_server_msec=10000
        ping_timeout_server=200
        commands_stats=true
        sessions_sort=true
        monitor_username="proxysql"
        monitor_password="proxysqlsecretpassword"
}
mysql_servers =
(
        { hostgroup_id=1, hostname="mydemomaster.mysql.database.azure.com", port=3306 , weight=1, comment="write Group", use_ssl=1 },
        { hostgroup_id=2, hostname="mydemoreplica.mysql.database.azure.com", port=3306 , weight=1, comment="Read Group", use_ssl=1  }
)
mysql_users =
(
        { username = "mydemouser" , password = "secretpassword" , default_hostgroup = 1 , active = 1 }
)
mysql_query_rules =
(
        {
                rule_id=1
                active=1
                match_digest="^SELECT .* FOR UPDATE"
                destination_hostgroup=1
                apply=1
        },
        {
                rule_id=2
                active=1
                match_digest="^SELECT .*"
                destination_hostgroup=2
                apply=1
        },
)
  • In the configMap file, modify the following parameters:
    • admin_variables: Modify admin_credentials to update the ProxySQL admin credentials.
    • mysql_servers: Modify this parameter to update Azure Database for MySQL server and read-replica details.
    • mysql_variables: Add or modify the variables. For example, you can modify monitoring user and password.
    • mysql_users: Modify this parameter to update the ProxySQL user. You can connect to the ProxySQL through this user.
    • mysql_query_rules: Modify this parameter to configure the routing rules for read and write split.

Prepare ProxySQL pod and service definition

Begin with the sample ProxySQL deployment file below. This template uses the latest ProxySQL docker image. You can update the number of replicas, restart policy and container port for ProxySQL.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: proxysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: proxysql
      tier: frontend
  template:
    metadata:
      labels:
        app: proxysql
        tier: frontend
    spec:
      restartPolicy: Always
      containers:
      - name: proxysql
        image: proxysql/proxysql:latest
        volumeMounts:
        - name: "proxysql-config"
          mountPath: "/etc/proxysql.cnf"
          subPath: "proxysql.cnf"
        ports:
        - containerPort: 3306
          name: "proxysql-mysqldb"
        - containerPort: 6032
          name: "proxysql-admin"
      volumes:
      - name: "proxysql-config"
        configMap:
          name: "proxysql-configmap"
---
apiVersion: v1
kind: Service
metadata:
  name: proxysql
  labels:
    app: proxysql
    tier: frontend
spec:
  type: LoadBalancer
  ports:
  - port: 3306
    name: "proxysql-mysqldb"
  - port: 6032
    name: "proxysql-admin"
  selector:
    app: proxysql
    tier: frontend

Deploy the resources

Next, you’ll deploy ProxySQL on AKS.

  1. Configure kubectl to use the credential for the new AKS cluster.
    az aks get-credentials --name aks-cluster-name  --resource-group "mydemo"​
  2. Deploy the configMap.
    kubectl create configmap proxysql-configmap --from-file=proxysql.cnf​
  3. Deploy ProxySQL using the proxysql deployment file.
    kubectl apply -f ./proxysqlaks.yml​
  4. Watch the deployment to see whether external links are generated by AKS.
    kubectl get service proxysql -w​
    [Use CTRL + C to break out]
  5. After the external IP is generated for ProxySQL service, use the below command to connect to ProxySQL and verify all config.
    1. Use the below command to get the external IP of the proxysql service.
      kubectl get pods,services -o wide ​
  6. Connect to ProxySQL using this external IP
    mysql -h[External_IP] -umydemouser -psecretpassword -P3306​

To learn how to scale your WordPress application using ProxySQL deployed as service in AKS to perform transparent read/write split across Azure Database for MySQL replicas, see the blog post scaling your Azure Database for MySQL workload running on Kubernetes with read replicas and ProxySQL.

If you have trouble setting up ProxySQL as a service using Azure Database for MySQL, please contact the Azure Database for MySQL team at [email protected].

Thank you!

Amol Bhatnagar

Program Manager - Microsoft

2 Comments

‎01-13-2020 10:42 PM

Thank you Amol Bhatnagar for sharing the Great blogpost :cool:

‎08-06-2020 05:48 AM

I am using App Service and MySQL PaaS with Read Replicas in Azure. Is it possible to have the ProxySQL feature in App Service without AKS or Dedicated VM?

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK