Helm Chart (deprecated)

<< Vttestserver Docker Image

This tutorial is deprecated. We recommend that you use the Operator instead.

This tutorial demonstrates how Vitess can be used with Minikube to deploy Vitess clusters using Helm.

Prerequisites

Before we get started, let’s get a few things out of the way:

  1. Install Minikube and start a Minikube engine:

    1. minikube start
  2. Install kubectl and ensure it is in your PATH. For example, on Linux:

    1. curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
  3. Install Helm 3:

    1. wget https://get.helm.sh/helm-v3.2.1-linux-amd64.tar.gz
    2. tar -xzf helm-v3.*
    3. # copy linux-amd64/helm into your path
  4. Install the MySQL client locally. For example, on Ubuntu:

    1. apt install mysql-client
  5. Install vtctlclient locally:

    If you are familiar with Go development, the easiest way to do this is:

    1. go get vitess.io/vitess/go/cmd/vtctlclient

    If not, you can also download the latest Vitess release and extract vtctlclient from it.

Start a single keyspace cluster

So you searched keyspace on Google and got a bunch of stuff about NoSQL… what’s the deal? It took a few hours, but after diving through the ancient Vitess scrolls you figure out that in the NewSQL world, keyspaces and databases are essentially the same thing when unsharded. Finally, it’s time to get started.

Change to the helm example directory:

  1. git clone git@github.com:vitessio/vitess.git
  2. cd vitess/examples/helm

In this directory, you will see a group of yaml files. The first digit of each file name indicates the phase of example. The next two digits indicate the order in which to execute them. For example, 101_initial_cluster.yaml is the first file of the first phase. We shall execute that now:

  1. helm install vitess ../../helm/vitess -f 101_initial_cluster.yaml

You should see output similar to the following:

  1. $ helm install vitess ../../helm/vitess -f 101_initial_cluster.yaml
  2. NAME: vitess
  3. LAST DEPLOYED: Tue Apr 14 20:32:18 2020
  4. NAMESPACE: default
  5. STATUS: deployed
  6. REVISION: 1
  7. TEST SUITE: None
  8. NOTES:
  9. Release name: vitess
  10. To access administrative web pages, start a proxy with:
  11. kubectl proxy --port=8001
  12. Then use the following URLs:
  13. vtctld: http://localhost:8001/api/v1/namespaces/default/services/vtctld:web/proxy/app/
  14. vtgate: http://localhost:8001/api/v1/namespaces/default/services/vtgate-zone1:web/proxy/

Verify cluster

You can check the state of your cluster with kubectl get pods,jobs. After a few minutes, it should show that all pods are in the status of running:

  1. $ kubectl get pods,jobs
  2. NAME READY STATUS RESTARTS AGE
  3. pod/commerce-apply-schema-initial-vlc6k 0/1 Completed 0 2m42s
  4. pod/commerce-apply-vschema-initial-9wb2k 0/1 Completed 0 2m42s
  5. pod/vtctld-58bd955948-pgz7k 1/1 Running 0 2m43s
  6. pod/vtgate-zone1-c7444bbf6-t5xc6 1/1 Running 3 2m43s
  7. pod/zone1-commerce-0-init-shard-master-gshz9 0/1 Completed 0 2m42s
  8. pod/zone1-commerce-0-replica-0 2/2 Running 0 2m42s
  9. pod/zone1-commerce-0-replica-1 2/2 Running 0 2m42s
  10. pod/zone1-commerce-0-replica-2 2/2 Running 0 2m42s
  11. NAME COMPLETIONS DURATION AGE
  12. job.batch/commerce-apply-schema-initial 1/1 94s 2m43s
  13. job.batch/commerce-apply-vschema-initial 1/1 87s 2m43s
  14. job.batch/zone1-commerce-0-init-shard-master 1/1 90s 2m43s

Setup Port-forward

For ease-of-use, Vitess provides a script to port-forward from kubernetes to your local machine. This script also recommends setting up aliases for mysql and vtctlclient:

  1. ./pf.sh &
  2. sleep 5
  3. alias vtctlclient="vtctlclient -server=localhost:15999"
  4. alias mysql="mysql -h 127.0.0.1 -P 15306"

Setting up aliases changes mysql to always connect to Vitess for your current session. To revert this, type unalias mysql && unalias vtctlclient or close your session.

Connect to your cluster

You should now be able to connect to the VTGate Server in your cluster with the MySQL client:

  1. ~/my-vitess-example> mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 1
  4. Server version: 5.7.9-Vitess Percona Server (GPL), Release 29, Revision 11ad961
  5. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. mysql> SHOW DATABASES;
  11. +-----------+
  12. | Databases |
  13. +-----------+
  14. | commerce |
  15. +-----------+
  16. 1 row in set (0.00 sec)

Summary

In this example, we deployed a single unsharded keyspace named commerce. Unsharded keyspaces have a single shard named 0. The following schema reflects a common ecommerce scenario that was created by the script:

  1. create table product(
  2. sku varbinary(128),
  3. description varbinary(128),
  4. price bigint,
  5. primary key(sku)
  6. );
  7. create table customer(
  8. customer_id bigint not null auto_increment,
  9. email varbinary(128),
  10. primary key(customer_id)
  11. );
  12. create table corder(
  13. order_id bigint not null auto_increment,
  14. customer_id bigint,
  15. sku varbinary(128),
  16. price bigint,
  17. primary key(order_id)
  18. );

The schema has been simplified to include only those fields that are significant to the example:

  • The product table contains the product information for all of the products.
  • The customer table has a customer_id that has an auto_increment. A typical customer table would have a lot more columns, and sometimes additional detail tables.
  • The corder table (named so because order is an SQL reserved word) has an order_id auto-increment column. It also has foreign keys into customer(customer_id) and product(sku).

Next Steps

You can now proceed with MoveTables.

Or alternatively, if you would like to teardown your example:

  1. helm delete vitess
  2. kubectl delete pvc -l "app=vitess"
  3. kubectl delete vitesstoponodes --all

Congratulations on completing this exercise!


<< Vttestserver Docker Image