{"id":370,"date":"2018-10-16T12:56:45","date_gmt":"2018-10-16T12:56:45","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw93\/?p=370"},"modified":"2018-10-17T08:49:05","modified_gmt":"2018-10-17T08:49:05","slug":"introduction-to-vitess-using-vitess-on-kubernetes","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw93\/index.php\/2018\/10\/16\/introduction-to-vitess-using-vitess-on-kubernetes\/","title":{"rendered":"Introduction to Vitess: Using Vitess on Kubernetes"},"content":{"rendered":"<h5>Expert Training in Kubernetes and Rancher<\/h5>\n<p>Join our free online training sessions to learn how to manage Kubernetes workloads with Rancher.<\/p>\n<p><a href=\"https:\/\/rancher.com\/training\/\" target=\"blank\">Sign up here<\/a><\/p>\n<h2>A Vitess overview<\/h2>\n<p><a href=\"https:\/\/vitess.io\/\">Vitess<\/a> is a database solution for deploying, scaling and managing large clusters of MySQL instances. It\u2019s architected to run as effectively in a public or private cloud architecture as it does on dedicated hardware. It combines and extends many important MySQL features with the scalability of a NoSQL database.<\/p>\n<p>In a simple scenario with Relational Databases and MySQL in particular, you would have a master instance, then a couple of replicas. You would then direct read-only queries to the replicas and write queries (and possible critical read queries) to the master instance. Similar to the setup in the image below:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rancher.com\/img\/blog\/2018\/mysql_default_setup.png\" alt=\"MySQL default Setup\" \/><\/p>\n<p>This all works fine, until you hit a limit:<br \/>\n&#8211; when your hardware doesn\u2019t cope with the load and you need a more expensive hardware;<br \/>\n&#8211; you need to manually shard the database;<br \/>\n&#8211; cluster management becomes a growing pain;<br \/>\n&#8211; query monitoring is increasingly difficult.<\/p>\n<p>These are the same problems engineers at youtube dealt with, and they came up with Vitess to solve these problems. Fortunately for us, they made it open source, so everyone can benefit from it.<\/p>\n<p>Now you\u2019ll see a lot of features of Vitess, that will seem like a list of buzzwords, but in this case, they are actually true:<\/p>\n<ul>\n<li>Performance\n<ul>\n<li>Connection pooling &#8211; Multiplex front-end application queries onto a pool of MySQL connections to optimize performance.<\/li>\n<li>Query de-duping \u2013 Reuse results of an in-flight query for any identical requests received while the in-flight query was still executing.<\/li>\n<li>Transaction manager \u2013 Limit number of concurrent transactions and manage deadlines to optimize overall throughput.<\/li>\n<\/ul>\n<\/li>\n<li>Protection\n<ul>\n<li>Query rewriting and sanitization \u2013 Add limits and avoid non-deterministic updates.<\/li>\n<li>Query killer \u2013 Terminate queries that take too long to return data.<\/li>\n<li>Table ACLs \u2013 Specify access control lists (ACLs) for tables based on the connected user.<\/li>\n<\/ul>\n<\/li>\n<li>Monitoring\n<ul>\n<li>Performance analysis: Tools let you monitor, diagnose, and analyze your database performance.<\/li>\n<li>Query streaming \u2013 Use a list of incoming queries to serve OLAP workloads.<\/li>\n<li>Update stream \u2013 A server streams the list of rows changing in the database, which can be used as a mechanism to propagate changes to other data stores.<\/li>\n<\/ul>\n<\/li>\n<li>Topology Management Tools\n<ul>\n<li>Master management tools (handles reparenting)<\/li>\n<li>Web-based management GUI<\/li>\n<li>Designed to work in multiple data centers \/ regions<\/li>\n<\/ul>\n<\/li>\n<li>Sharding\n<ul>\n<li>Virtually seamless dynamic re-sharding<\/li>\n<li>Vertical and Horizontal sharding support<\/li>\n<li>Multiple sharding schemes, with the ability to plug-in custom ones<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>It can be clearly seen that, at scale, the above features become incredibly valuable and necessary.<\/p>\n<p>Now, let\u2019s try it out \ud83d\ude42<\/p>\n<p>Vitess has come a long way and now it is relatively easy to deploy a Vitess cluster with Kubernetes.<\/p>\n<p>The plan is as follows:<\/p>\n<ul>\n<li>deploy a Rancher 2.0 instance and use it for every deploy step in this article;<\/li>\n<li>using Rancher 2.0, create a Kubernetes cluster;<\/li>\n<li>deploy Vitess on the above Kubernetes cluster;<\/li>\n<li>create a database on Vitess and query it;<\/li>\n<li>deploy a test application in the same Kubernetes cluster, that will use Vitess;<\/li>\n<\/ul>\n<p>You should be able to create all the resources needed for the outlined steps with a free trial from Google Cloud Platform. A trial from GCP has a limit of 8 cores per project, keep that in mind when deploying your resources.<\/p>\n<h3>Deploy a Rancher 2.0 instance and start a Kubernetes Cluster<\/h3>\n<p>There\u2019s already a good guide on how to deploy a Rancher 2.0 instance <a href=\"https:\/\/rancher.com\/quick-start\/\">here<\/a>, thus let\u2019s not get into many details here. One note &#8211; if you want to run this guide on Google Cloud Platform trial, then create a separate project for the Rancher instace, thus saving yourself a CPU core for the Kubernetes cluster (remember the 8 cores limit per project for the GCP trial?)<\/p>\n<p>Now onto starting a Kubernetes Cluster. For this, there\u2019s again a pretty good guide <a href=\"https:\/\/rancher.com\/docs\/rancher\/v2.x\/en\/cluster-provisioning\/hosted-kubernetes-clusters\/gke\/\">here<\/a>. One note &#8211; Vitess documentation recommends a cluster of 5 n1-standard-4 instances, that will get you over the GCP trial limit. But, if you create a 4 nodes of n1-standard-2 type, this will get you exactly to the 8 cores limit per project for GCP trial and it\u2019s enough for the outlined tasks. There will be some changes to the Vitess scripts, to deploy less resources, so you can fit needed resources into the smaller cluster.<\/p>\n<p>The Create Cluster part from Rancher should look like in the below image:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rancher.com\/img\/blog\/2018\/rancher-start-kubernetes-cluster.png\" alt=\"Rancher Kubernetes Cluster\" \/><\/p>\n<h4>Start a Vitess control pod<\/h4>\n<p>Note the name of the cluster vitess-demo, it will be referenced further. Once you have your cluster created and active the first thing to do is to create a control instance, where you will have all the necessary tools for this Vitess demo. To do that, go to your newly created vitess-demo cluster, onto to the Default project and click on Deploy. Fill in there the details:<\/p>\n<ul>\n<li>set the Name to vitess-control;<\/li>\n<li>set the docker image to golang;<\/li>\n<li>leave everything else as it is.<\/li>\n<\/ul>\n<p>It should look like in the below image:<br \/>\n<img decoding=\"async\" src=\"https:\/\/rancher.com\/img\/blog\/2018\/rancher-deploy-vitess-control.png\" alt=\"Vitess Control Deploy\" \/><\/p>\n<p>Click confidently on Launch!<\/p>\n<p>In a moment you should have your vitess-control pod running. It will be used as a control plane for your Vitess cluster and thanks to Rancher, you will be able to access it from anywhere you have an internet access and a browser.<\/p>\n<p>Ok, let\u2019s get to installing the control part. To do that, click on the right hand side menu of vitess-control pod and select Execute shell, just like in the screenshot below:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rancher.com\/img\/blog\/2018\/vitess-control-execute-shell.png\" alt=\"Vitess Control Execute Shell\" \/><\/p>\n<h4>Build, install vtctlclient and configure settings<\/h4>\n<p>This will bring you the go command line that we need. Let\u2019s start typing commands there. First build and install vtctlclient by running:<\/p>\n<p>go get vitess.io\/vitess\/go\/cmd\/vtctlclient<\/p>\n<p>When successfull, this command doesn\u2019t provide any output and it will download and build Vitess source code at this location: $GOPATH\/src\/vitess.io\/vitess\/, it will also copy the built vtctlclient binary to $GOPATH\/bin.<\/p>\n<p>Now let\u2019s navigate to the Vitess source code directory and configure site-local settings with the following commands:<\/p>\n<p>cd $GOPATH\/src\/vitess.io\/vitess\/examples\/kubernetes<br \/>\n.\/configure.sh<\/p>\n<p>It should look as below:<br \/>\n<img decoding=\"async\" src=\"https:\/\/rancher.com\/img\/blog\/2018\/vitess-control-begin-steps.png\" alt=\"Vitess begin steps\" \/><\/p>\n<p>At the moment Vitess has out-of-the-box support for backups in Google Cloud Storage. If you want, you can create a bucket in Google Cloud to test the backup in this demo, but it\u2019s not very important for the demo purposes.<\/p>\n<p>There will also be a need to have kubectl configured on the vitess-control instance, to interact directly with the cluster. To do this, run the following commands on the vitess-control command line:<\/p>\n<p>curl -LO https:\/\/storage.googleapis.com\/kubernetes-release\/release\/$(curl -s https:\/\/storage.googleapis.com\/kubernetes-release\/release\/stable.txt)\/bin\/linux\/amd64\/kubectl<br \/>\nchmod +x .\/kubectl<br \/>\nmv .\/kubectl \/usr\/local\/bin\/kubectl<\/p>\n<p>Now you need the kubeconfig file, that you can get from Rancher. You can get that from the vitess-demo default dashboard. On the upper right corner you should see Launch kubectl and Kubeconfig file. Click on Kubeconfig file and you\u2019ll be presented with the contents of the kubeconfig file. On the bottom you will have the Copy to Clipboard option, click on that. Now you need to paste it into ~\/.kube\/config file inside vitess-control instance. To do that, execute shell in vitess-control instance and issue the below commands there:<\/p>\n<p>apt-get update<br \/>\napt-get install -y vim<br \/>\nvim ~\/.kube\/config<\/p>\n<p>Once you opened the file with vim, paste the kubeconfig file inside that file (don\u2019t forget to enter insert mode in vim, by just pressing the I key, before pasting the contents).<\/p>\n<p>Confirm that you have kubectl working properly, by issuing the following command:<\/p>\n<p>You should see the only pod running, the exact one from which you\u2019re running the commands &#8211; vitess-control<\/p>\n<h4>Start Vitess etcd cluster<\/h4>\n<p>The Vitess <a href=\"https:\/\/vitess.io\/overview\/concepts\/#topology-service\">topology service<\/a> stores coordination data for all the servers in a Vitess cluster. It can store this data in one of several consistent storage systems. In this example, we\u2019ll use etcd. This will require a separate etcd cluster, from the Kubernetes one.<\/p>\n<p>To easily create an etcd cluster, let\u2019s install etcd-operator, using Rancher\u2019s Catalog Apps. Go to Catalog Apps, click on Launch, search for etcd-operator. Once you\u2019ve found etcd-operator, click on View Details and from the provided options, change only the namespace where etcd cluster will be deployed, because Vitess\u2019 etcd-cluster will be deployed in the default namespace and etcd-operator has to be in the same namespace. It should look like this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rancher.com\/img\/blog\/2018\/etcd-operator-default-namespace.png\" alt=\"etcd-operator default namespace\" \/><\/p>\n<p>Click on Lauch and wait a couple of moments for the etcd-operator to deploy. Verify that etcd-operator is running, by checking the Workloads tab and inside it, check the Service Discovery tab. If you see there etcd-operator as a workload and etcd-cluster with etcd-cluster-client as services, then everything is fine.<\/p>\n<p>Now let\u2019s start etcd cluster for Vitess. If you\u2019re running this demo from a Google Cloud Platform trial account, then at this step you need to change the number of replicas started by the etcd cluster. To do that go to the Vitess control pod, Execute Shell and run the following command:<\/p>\n<p>cd $GOPATH\/src\/vitess.io\/vitess\/examples\/kubernetes<br \/>\nsed -i &#8216;s\/ETCD_REPLICAS:-3\/ETCD_REPLICAS:-1\/g&#8217; etcd-up.sh<br \/>\n.\/etcd-up.sh<\/p>\n<p>### example output<br \/>\n# Creating etcd service for &#8216;global&#8217; cell&#8230;<br \/>\n# etcdcluster.etcd.database.coreos.com\/etcd-global created<br \/>\n# Creating etcd service for &#8216;test&#8217; cell&#8230;<br \/>\n# etcdcluster.etcd.database.coreos.com\/etcd-test created<\/p>\n<p>Check that pods are running:<\/p>\n<p># kubectl get pod<br \/>\nNAME READY STATUS RESTARTS AGE<br \/>\netcd-cluster-4ftlwdxbrp 1\/1 Running 0 3m<br \/>\netcd-cluster-bjjsrfkm4x 1\/1 Running 0 3m<br \/>\netcd-cluster-cxqkghhjt4 1\/1 Running 0 2m<br \/>\netcd-global-qbnvtfd66b 0\/1 PodInitializing 0 10s<br \/>\netcd-operator-etcd-operator-etcd-operator-7d467bd7fb-kpkvw 1\/1 Running 0 3m<br \/>\netcd-test-x4pn5jw99s 0\/1 Running 0 10s<br \/>\nvitess-control-fdb84cbc4-7l2mp 1\/1 Running 0 1h<br \/>\n#<\/p>\n<h4>Start vtctld<\/h4>\n<p>This one will be used to accept RPC commands from vtctlclient to modify the Vitess cluster. To install it, you\u2019ll also need your vitess-control command line and issue there the following commands:<\/p>\n<p>cd $GOPATH\/src\/vitess.io\/vitess\/examples\/kubernetes<br \/>\n.\/vtctld-up.sh<\/p>\n<p>### example output<br \/>\n# Creating vtctld ClusterIP service&#8230;<br \/>\n# service\/vtctld created<br \/>\n# Creating vtctld replicationcontroller&#8230;<br \/>\n# replicationcontroller\/vtctld created<\/p>\n<p># To access vtctld web UI, start kubectl proxy in another terminal:<br \/>\n# kubectl proxy &#8211;port=8001<br \/>\n# Then visit http:\/\/localhost:8001\/api\/v1\/proxy\/namespaces\/default\/services\/vtctld:web\/<\/p>\n<h4>Try vtctlclient to send commands to vtctld<\/h4>\n<p>At this point you can run vtctlclient from the vitess-control pod, to issue commands to the vtctld service on your Kubernetes cluster.<\/p>\n<p>To enable RPC access into the Kubernetes cluster, you\u2019ll need to use kubectl to set up an authenticated tunnel.<\/p>\n<p>Since the tunnel needs to target a particular vtctld pod name, guys at Vitess provided the kvtctl.sh script, which uses kubectl to discover the pod name and set up the tunnel before running vtctlclient. To test this, let\u2019s run .\/kvtctl.sh help from where we left, this will test your connection to vtctld and list the vtctlclient commands that you can use to administer the Vitess cluster.<\/p>\n<p>.\/kvtctl.sh help<\/p>\n<p>### example output<br \/>\n# Starting port forwarding to vtctld&#8230;<br \/>\n# Available commands:<br \/>\n#<br \/>\n# Tablets:<br \/>\n# InitTablet [-allow_update] [-allow_different_shard] [-allow_master_override] [-parent] [-db_name_override=&lt;db name&gt;] [-hostname=&lt;hostname&gt;] [-mysql_port=&lt;port&gt;] [-port=&lt;port&gt;] [-grpc_port=&lt;port&gt;] -keyspace=&lt;keyspace&gt; -shard=&lt;shard&gt; &lt;tablet alias&gt; &lt;tablet type&gt;<\/p>\n<h4>Setup Vitess cell in the topology (Vitess\u2019s etcd cluster)<\/h4>\n<p>The global etcd cluster is configured from command-line parameters, specified in the Kubernetes configuration files. The per-cell etcd cluster however needs to be configured, so it is reachable by Vitess. Run the following commands from vitess-control pod to set it up:<\/p>\n<p>cd $GOPATH\/src\/vitess.io\/vitess\/examples\/kubernetes<br \/>\n.\/kvtctl.sh AddCellInfo &#8211;root \/test -server_address http:\/\/etcd-test-client:2379 test<\/p>\n<p>If successful you should only see a INFO message that tells you that your command is proxied to vtctld.<\/p>\n<h4>Start a Vitess tablet<\/h4>\n<p>Now starting with the interesting parts. A Vitess <a href=\"https:\/\/vitess.io\/overview\/concepts\/#tablet\">tablet<\/a> is the unit of scaling for the database. A tablet consists of the vttablet and mysqld processes, running on the same host. We enforce this coupling in Kubernetes by putting the respective containers for vttablet and mysqld inside a single pod.<\/p>\n<p>To start a vttablet, guys from Vitess provided a script that will launch 5 vttablet pods. This can be configured, and if you want to fit into the CPU limit provided by GCP trial, you need to change those values. How to do that, will be presented below.<\/p>\n<p>Now go to vitess-control command line and run the following commands:<\/p>\n<p>cd $GOPATH\/src\/vitess.io\/vitess\/examples\/kubernetes<br \/>\n### run below commands only if you want to change the vttable count from 5 to 3<br \/>\n### to fit into the GCP trial CPU limit<br \/>\nsed -i &#8216;s\/TABLETS_PER_SHARD:-5\/TABLETS_PER_SHARD:-3\/g&#8217; vttablet-up.sh<br \/>\nsed -i &#8216;s\/RDONLY_COUNT:-2\/RDONLY_COUNT:-1\/g&#8217; vttablet-up.sh<br \/>\n### end of vttablet count change<br \/>\n.\/vttablet-up.sh<\/p>\n<p>### example output<br \/>\n# Creating test_keyspace.shard-0 pods in cell test&#8230;<br \/>\n# Creating pod for tablet test-0000000100&#8230;<br \/>\n# pod\/vttablet-100 created<br \/>\n# Creating pod for tablet test-0000000101&#8230;<br \/>\n# pod\/vttablet-101 created<br \/>\n# Creating pod for tablet test-0000000102&#8230;<br \/>\n# pod\/vttablet-102 created<\/p>\n<p>At this point you should see tablet pods appearing in Rancher\u2019s Workloads tab, just like shown below:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rancher.com\/img\/blog\/2018\/vttablets-pods.png\" alt=\"vttablets pods\" \/><\/p>\n<p>You can also check the the status of the tablets from the vitess-control command line:<\/p>\n<p>.\/kvtctl.sh ListAllTablets test<br \/>\n### example output<br \/>\n# Starting port forwarding to vtctld&#8230;<br \/>\n# test-0000000100 test_keyspace 0 replica 10.12.0.8:15002 10.12.0.8:3306 []<br \/>\n# test-0000000101 test_keyspace 0 replica 10.12.3.11:15002 10.12.3.11:3306 []<br \/>\n# test-0000000102 test_keyspace 0 rdonly 10.12.4.8:15002 10.12.4.8:3306 []<\/p>\n<h4>Initialize a MySQL Database<\/h4>\n<p>Once all tablets are up and running, it\u2019s a good time to initialise a underlying MySQL database.<\/p>\n<p>Take note that many vtctlclient commands produce no output on success, so the saying \u201cNo news, is good news\u201d is valid here too.<\/p>\n<p>First, designate one of the tablets to be the initial master. Vitess will automatically connect the other slaves\u2019 mysqld instances so that they start replicating from the master\u2019s mysqld. This is also when the default database is created. Since our keyspace is named test_keyspace, the MySQL database will be named vt_test_keyspace. As you can see from the ListAllTablets output, there are 2 replica and one rdonly tablets. Let\u2019s designate the first tablet test-0000000100 as master (again, running from vitess-control command line):<\/p>\n<p>cd $GOPATH\/src\/vitess.io\/vitess\/examples\/kubernetes<br \/>\n.\/kvtctl.sh InitShardMaster -force test_keyspace\/0 test-0000000100<\/p>\n<p>### example output<br \/>\n# Starting port forwarding to vtctld&#8230;<br \/>\n# W0817 22:29:32.961277 2530 main.go:60] W0817 22:29:32.958629 reparent.go:181] master-elect tablet test-0000000100 is not the shard master, proceeding anyway as -force was used<br \/>\n# W0817 22:29:32.961988 2530 main.go:60] W0817 22:29:32.959145 reparent.go:187] master-elect tablet test-0000000100 is not a master in the shard, proceeding anyway as -force was used<\/p>\n<p>Since this is the first time the shard has been started, the tablets are not doing any replication yet, and there is no existing master. That is why the InitShardMaster command above uses the -force flag to bypass the usual sanity checks that would apply if this wasn\u2019t a brand new shard.<\/p>\n<p>Now you should be able to see one master, one replica and one rdonly (if you didn\u2019t change the counts in the scripts, you should see several replicas and rdonly pods):<\/p>\n<p>.\/kvtctl.sh ListAllTablets test<\/p>\n<p>### example output<br \/>\n# Starting port forwarding to vtctld&#8230;<br \/>\n# test-0000000100 test_keyspace 0 master 10.12.0.8:15002 10.12.0.8:3306 []<br \/>\n# test-0000000101 test_keyspace 0 replica 10.12.3.11:15002 10.12.3.11:3306 []<br \/>\n# test-0000000102 test_keyspace 0 rdonly 10.12.4.8:15002 10.12.4.8:3306 []<\/p>\n<p>The replica tablets are used for serving live web traffic, while the rdonly tablets are used for offline processing, such as batch jobs and backups.<\/p>\n<h4>Create a table inside Vitess Cluster<\/h4>\n<p>Now it\u2019s starting to get shape and we can apply a schema to the databases. For this we can use the vtctlclient tool that can apply the database schema across all tablets in a keyspace. There\u2019s already a provided create_test_table.sql file from vitess on your vitess-control pod, let\u2019s apply it:<\/p>\n<p>cd $GOPATH\/src\/vitess.io\/vitess\/examples\/kubernetes<br \/>\n.\/kvtctl.sh ApplySchema -sql &#8220;$(cat create_test_table.sql)&#8221; test_keyspace<\/p>\n<p>The SQL that was applied is the following:<\/p>\n<p>CREATE TABLE messages (<br \/>\npage BIGINT(20) UNSIGNED,<br \/>\ntime_created_ns BIGINT(20) UNSIGNED,<br \/>\nmessage VARCHAR(10000),<br \/>\nPRIMARY KEY (page, time_created_ns)<br \/>\n) ENGINE=InnoDB<\/p>\n<p>And it can be viewed like this:<\/p>\n<p>.\/kvtctl.sh GetSchema test-0000000100<\/p>\n<p>### example output<br \/>\n# Starting port forwarding to vtctld&#8230;<br \/>\n# {<br \/>\n# &#8220;database_schema&#8221;: &#8220;CREATE DATABASE \/*!32312 IF NOT EXISTS*\/ {{.DatabaseName}} \/*!40100 DEFAULT CHARACTER SET utf8 *\/&#8221;,<br \/>\n# &#8220;table_definitions&#8221;: [<br \/>\n# {<br \/>\n# &#8220;name&#8221;: &#8220;messages&#8221;,<br \/>\n# &#8220;schema&#8221;: &#8220;CREATE TABLE `messages` (n `page` bigint(20) unsigned NOT NULL,n `time_created_ns` bigint(20) unsigned NOT NULL,n `message` varchar(10000) DEFAULT NULL,n PRIMARY KEY (`page`,`time_created_ns`)n) ENGINE=InnoDB DEFAULT CHARSET=utf8&#8221;,<br \/>\n# &#8220;columns&#8221;: [<br \/>\n# &#8220;page&#8221;,<br \/>\n# &#8220;time_created_ns&#8221;,<br \/>\n# &#8220;message&#8221;<br \/>\n# ],<br \/>\n# &#8220;primary_key_columns&#8221;: [<br \/>\n# &#8220;page&#8221;,<br \/>\n# &#8220;time_created_ns&#8221;<br \/>\n# ],<br \/>\n# &#8220;type&#8221;: &#8220;BASE TABLE&#8221;,<br \/>\n# &#8220;data_length&#8221;: &#8220;16384&#8221;,<br \/>\n# &#8220;row_count&#8221;: &#8220;0&#8221;<br \/>\n# }<br \/>\n# ],<br \/>\n# &#8220;version&#8221;: &#8220;5b2e5dbcb5766b6c69fe55c81b6ea805&#8221;<br \/>\n# }<\/p>\n<h4>Initialise Vitess routing schema<\/h4>\n<p>The example above we have just a database, with no specific configuration and we need to make that (empty) configuration visible for serving with the following command:<\/p>\n<p>.\/kvtctl.sh RebuildVSchemaGraph<\/p>\n<p>As this command doesn\u2019t produce any output on success, you\u2019re good if you don\u2019t receive any messages.<\/p>\n<h4>Start Vitess routing proxy &#8211; vtgate<\/h4>\n<p>Vitess uses <a href=\"https:\/\/vitess.io\/overview\/#vtgate\">vtgate<\/a> to route each client query to the correct vttablet. In Kubernetes, a vtgate service distributes connections to a pool of vtgate pods. There\u2019s again a script ready to start vtgate and it can also be changed to start a lower number of pods, to fit the GCP trial limit. Now go to vitess-control command line and run the following commands:<\/p>\n<p>cd $GOPATH\/src\/vitess.io\/vitess\/examples\/kubernetes<br \/>\n### run below command only if you want to change the vtgate count from 3 to 1<br \/>\n### to fit into the GCP trial CPU limit<br \/>\nsed -i &#8216;s\/VTGATE_REPLICAS:-3\/VTGATE_REPLICAS:-1\/g&#8217; vtgate-up.sh<br \/>\n### end of vttablet count change<\/p>\n<p>.\/vtgate-up.sh<\/p>\n<p>### example output<br \/>\n# Creating vtgate service in cell test&#8230;<br \/>\n# service\/vtgate-test created<br \/>\n# Creating vtgate replicationcontroller in cell test&#8230;<br \/>\n# replicationcontroller\/vtgate-test created<\/p>\n<p>After a couple of moments, you should see vtgate-test Workload in Rancher\u2019s dashboard.<\/p>\n<h4>Test your cluster with an App<\/h4>\n<p>Now comes the most awaited moment &#8211; testing your Vitess cluster with an App. Guys from Vitess provided that too, that is also already present on your vitess-control pod. It is a GuestBook example that uses Vitess as a backend database. Apply it from the vitess-control pod:<\/p>\n<p>cd $GOPATH\/src\/vitess.io\/vitess\/examples\/kubernetes<br \/>\n.\/guestbook-up.sh<\/p>\n<p>### example output<br \/>\n# Creating guestbook service&#8230;<br \/>\n# service\/guestbook created<br \/>\n# Creating guestbook replicationcontroller&#8230;<br \/>\n# replicationcontroller\/guestbook created<\/p>\n<p>At this moment you should be able to access the GuestBook app in your browser. You need to get the public IP address of it. There are at least 2 ways to do that:<br \/>\n&#8211; first one is to view it in Rancher, by going to Rancher\u2019s workloads, then select Load Balancer, there you should see the GuestBook load balancer. From it\u2019s right hand side menu, select View in API and then in the new opened page, search for PublicEndpoints -&gt; Addresses, there you should have the public IP address of your GuestBook app.<br \/>\n&#8211; second one is to get it from the vitess-control command line, by running the following command:<\/p>\n<p>&#8220;`c<br \/>\nkubectl get service guestbook -o=jsonpath='{.status.loadBalancer.ingress[].ip}&#8217;<\/p>\n<p>### example output<br \/>\n# 35.197.201.4<br \/>\n&#8220;`<\/p>\n<p>Now you can access the GuestBook by pointing your browser to that IP address. It should look like this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rancher.com\/img\/blog\/2018\/guestbook-demo.png\" alt=\"Guestbook demo\" \/><\/p>\n<p>If you click on random page, it will generate a random page and insert it into the above created schema inside Vitess. Do that a couple of times and also post some messages to those pages, so we can view them afterwards in Vitess.<\/p>\n<p>You can see Vitess\u2019 replication capabilities by opening the app in multiple browser windows, with the same Guestbook page number. Each new entry is committed to the master database. In the meantime, JavaScript on the page continuously polls the app server to retrieve a list of GuestBook entries. The app serves read-only requests by querying Vitess in \u2018replica\u2019 mode, confirming that replication is working.<\/p>\n<p>Now let\u2019s see how it looks inside Vitess, go to vitess-control command line and issue the following commands:<\/p>\n<p>cd $GOPATH\/src\/vitess.io\/vitess\/examples\/kubernetes<br \/>\n.\/kvtctl.sh ExecuteFetchAsDba test-0000000100 &#8220;SELECT * FROM messages&#8221;<\/p>\n<p>### example output<br \/>\n# Starting port forwarding to vtctld&#8230;<br \/>\n# +&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+<br \/>\n# | page | time_created_ns | message |<br \/>\n# +&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+<br \/>\n# | 0 | 1534547955692433152 | Hello |<br \/>\n# | 0 | 1534547959825954816 | World |<br \/>\n# | 65 | 1534547943325885184 | And |<br \/>\n# | 65 | 1534547947058206208 | again |<br \/>\n# +&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+<\/p>\n<h4>Next steps<\/h4>\n<p>Now as you\u2019ve seen what Vitess can do on the surface, the next step would be to try <a href=\"https:\/\/vitess.io\/user-guide\/sharding-kubernetes\/\">Vitess resharding<\/a> or <a href=\"https:\/\/vitess.io\/user-guide\/sharding\/#resharding\">dynamic resharding<\/a>, just note that for these you\u2019ll need more resources than those provided by Google Cloud Platform trial limits.<\/p>\n<h4>Tear down the app and the clusters<\/h4>\n<p>To clean up all the demo pods and services you\u2019ve created, there are also scripts provided for that, that you can run from the vitess-control pod:<\/p>\n<p>cd $GOPATH\/src\/vitess.io\/vitess\/examples\/kubernetes<br \/>\n.\/guestbook-down.sh<br \/>\n.\/vtgate-down.sh<br \/>\n.\/vttablet-down.sh<br \/>\n.\/vtctld-down.sh<br \/>\n.\/etcd-down.sh<\/p>\n<p>The last cleaning steps would be to delete the cluster from Rancher and then terminate the Rancher instance from the Google Cloud Platform console.<\/p>\n<h3>Some final thoughts<\/h3>\n<p>Vitess is a very powerful and very useful MySQL backend. Although it requires a little bit of effort to understand and properly set up, it offers a huge advantage for the future management of massive MySQL databases and it will scale easily. If Vitess is the default MySQL backend for giants like YouTube, it certainly has it\u2019s merits.<\/p>\n<p>Rancher helped a lot in this demo to have everything in one place, I only had to have one Rancher instance to be able to do all the work, just by accessing it in a browser. The control instance was there, and all cluster details were there, just at a click distance.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/rancher.com\/img\/bio\/roman-doroschevici.jpg\" alt=\"Roman Doroschevici\" width=\"100\" height=\"100\" \/><\/p>\n<p>Roman Doroschevici<\/p>\n<p><a href=\"https:\/\/github.com\/roma-d\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/rancher.com\/img\/icon-github.svg\" alt=\"github\" width=\"30\" \/><\/a><\/p>\n<p><a href=\"https:\/\/rancher.com\/blog\/2018\/2018-08-31-intro-to-vitess-on-kubernetes\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Expert Training in Kubernetes and Rancher Join our free online training sessions to learn how to manage Kubernetes workloads with Rancher. Sign up here A Vitess overview Vitess is a database solution for deploying, scaling and managing large clusters of MySQL instances. It\u2019s architected to run as effectively in a public or private cloud architecture &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw93\/index.php\/2018\/10\/16\/introduction-to-vitess-using-vitess-on-kubernetes\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Introduction to Vitess: Using Vitess on Kubernetes&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-370","post","type-post","status-publish","format-standard","hentry","category-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/370","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/comments?post=370"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/370\/revisions"}],"predecessor-version":[{"id":517,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/370\/revisions\/517"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/media?parent=370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/categories?post=370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/tags?post=370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}