Goals
The goals of this quickstart are:- Deploy the StarRocks Kubernetes Operator and a cluster with Helm
- Configure a password for the database user
root - Provide for high-availability with three FEs and three BEs
- Store metadata in persistent storage
- Store data in persistent storage
- Allow MySQL clients to connect from outside the Kubernetes cluster
- Allow loading data from outside the Kubernetes cluster using Stream Load
- Load some public datasets
- Query the data
- Get the system deployed with Helm.
- Allow the reader to load data in the database and analyze that data.
- Explain the basics of data transformation during loading.
Prerequisites
Kubernetes environment
The Kubernetes environment used while writing this guide consists of three nodes with four vCPUS, and 16GB RAM each (GCPe2-standard-4 machines). The Kubernetes cluster was deployed with this gcloud command:
Tip
This command is for your reference, if you are using AWS, Azure, or any other Kubernetes provider you will need to modify this for your environment. In Google Cloud you will need to specify your own project and an appropriate location.
Helm
Helm is a package manager for Kubernetes that simplifies the deployment and management of applications. In this lab you will use Helm to deploy the CelerData Enterprise Edition Kubernetes operator and the sample cluster. Install helmSQL client
You can use the SQL client provided in the Kubernetes environment, or use one on your system. This guide uses themysql CLI Many MySQL-compatible clients will work.
curl
curl is used to issue the data load job to the database, and to download the datasets. Check to see if you have it installed by running curl or curl.exe at your OS prompt. If curl is not installed, get curl here.
Terminology
FE
Frontend nodes are responsible for metadata management, client connection management, query planning, and query scheduling. Each FE stores and maintains a complete copy of metadata in its memory, which guarantees indiscriminate services among the FEs.BE
Backend nodes are responsible for both data storage and executing query plans.Add the database Helm chart repo
The Helm Chart contains the definitions of the StarRocks Operator and the custom resource StarRocksCluster.-
Add the Helm Chart Repo.
-
Update the Helm Chart Repo to the latest version.
-
View the Helm Chart Repo that you added.
Download the data
Download these two datasets to your machine.New York City crash data
Weather data
Create a Helm values file
The goals for this quick start are:- Configure a password for the database user
root - Provide for high-availability with three FEs and three BEs
- Store metadata in persistent storage
- Store data in persistent storage
- Allow MySQL clients to connect from outside the Kubernetes cluster
- Allow loading data from outside the Kubernetes cluster using Stream Load
1. Password for the database user
This bit of YAML instructs the StarRocks operator to set the password for the database userroot to the value of the password key of the Kubernetes secret `starrocks-root-pass.
-
Task: Create the Kubernetes secret
2. High Availability with 3 FEs and 3 BEs
By settingstarrocks.starrockFESpec.replicas to 3, and starrocks.starrockBeSpec.replicas to 3 you will have enough FEs and BEs for high availability. Setting the CPU and memory requests low allows the pods to be created in a small Kubernetes environment.
3. Store metadata in persistent storage
Setting a value forstarrocks.starrocksFESpec.storageSpec.name to anything other than "" causes:
- Persistent storage to be used
- the value of
starrocks.starrocksFESpec.storageSpec.nameto be used as the prefix for all storage volumes for the service.
fe these PVs will be created for FE 0:
fe-meta-kube-starrocks-fe-0fe-log-kube-starrocks-fe-0
4. Store data in persistent storage
Setting a value forstarrocks.starrocksBeSpec.storageSpec.name to anything other than "" causes:
- Persistent storage to be used
- the value of
starrocks.starrocksBeSpec.storageSpec.nameto be used as the prefix for all storage volumes for the service.
be these PVs will be created for BE 0:
be-data-kube-starrocks-be-0be-log-kube-starrocks-be-0
storageSize to 15Gi reduces the storage from the default of 1Ti to fit smaller quotas for storage.
5. LoadBalancer for MySQL clients
By default, access to the FE service is through cluster IPs. To allow external access,service.type is set to LoadBalancer
6. LoadBalancer for external data loading
Stream Load requires external access to both FEs and BEs. The requests are sent to the FE and then the FE assigns a BE to process the upload. To allow thecurl command to be redirected to the BE the starroclFeProxySpec needs to be enabled and set to type LoadBalancer.
The complete values file
The above snippets combined provide a full values file. Save this tomy-values.yaml:
Set the database root database user password
To load data from outside of the Kubernetes cluster the database will be exposed externally. You should set a password for the database userroot. The operator will apply the password to the FE and BE nodes.
Deploy the operator and cluster
Check the status of the cluster
You can check the progress with these commands:kube-starrocks-initpwd pod will go through error and CrashLoopBackOff states as it attempts to connect to the FE and BE pods to set the database root password. You should ignore these errors and wait for a status of Completed for this pod.
Verify that the cluster is healthy
Tip These are the same commands as above, but show the desired state.kube-starrocks-initpwd show 1/1 in the READY column. The kube-starrocks-initpwd pod should show 0/1 and a STATUS of Completed.
EXTERNAL-IP addresses in the highlighted lines will be used to provide SQL client and Stream Load access from outside the Kubernetes cluster.
EXTERNAL-IP addresses from the highlighted lines in environment variables so that you have them handy:
Connect to the database with a SQL client
Tip If you are using a client other than the mysql CLI, open that now. This command will run themysql command in a Kubernetes pod:
Create some tables
Create a database
Type these two lines in at theStarRocks > prompt and press enter after each:
Create two tables
Crashdata
The crash dataset contains many more fields than these, the schema has been trimmed down to include only the fields that might be useful to answer questions about the impact weather has on driving conditions.Weatherdata
Similar to the crash data, the weather dataset has many more columns (a total of 125 columns) and only the ones that are expected to answer the questions are included in the database.Upload data
There are many ways to load data into the database. For this tutorial, the simplest way is to use curl and Stream Load. Upload the two datasets that you downloaded earlier. Tip Open a new shell as these curl commands are run at the operating system prompt, not in themysql client. The commands refer to the datasets that you downloaded, so run them from the directory where you downloaded the files.
Since this is a new shell, run the export commands again:
starrocks-root-pass. If you used the command provided, the password is g()()dpa$$word.
The curl commands look complex, but they are explained in detail at the end of the tutorial. For now, we recommend running the commands and running some SQL to analyze the data, and then reading about the data loading details at the end.
Connect with a MySQL client
Connect with a MySQL client if you are not connected. Remember to use the external IP address of thekube-starrocks-fe-service service and the password that you configured in the Kubernetes secret starrocks-root-pass.
Answer some questions
These queries can be run in your SQL client. All of the queries use the
quickstart database.
How many crashes are there per hour in NYC?
What is the average temperature in NYC?
Is it safe to drive in NYC when visibility is poor?
Letās look at the number of crashes when visibility is poor (between 0 and 1.0 miles). To answer this question use a JOIN across the two tables on the DATETIME column.- February 3rd 2014 was a Monday
- 8AM is rush hour
- It was raining (0.12 inches or precipitation that hour)
- The temperature is 32 degrees F (the freezing point for water)
- Visibility is bad at 0.25 miles, normal for NYC is 10 miles
What about driving in icy conditions?
Water vapor can desublimate to ice at 40 degrees F; this query looks at temps between 0 and 40 degrees F.Cleanup
Run this command if you are finished and would like to remove the cluster and the StarRocks operator.Summary
In this tutorial you:- Deployed the database with Helm and the StarRocks Operator
- Loaded crash data provided by New York City and weather data provided by NOAA
- Analyzed the data using SQL JOINs to find out that driving in low visibility or icy streets is a bad idea
Notes on the curl commands
Stream Load and curl take many arguments. Only the ones used in this tutorial are described here, the rest will be linked to in the more information section.
--location-trusted
This configures curl to pass credentials to any redirected URLs.
-u root
The username used to log in to the database
-T filename
T is for transfer, the filename to transfer.
label:name-num
The label to associate with this Stream Load job. The label must be unique, so if you run the job multiple times you can add a number and keep incrementing that.
column_separator:,
If you load a file that uses a single , then set it as shown above, if you use a different delimiter then set that delimiter here. Common choices are \t, ,, and |.
skip_header:1
Some CSV files have a single header row with all of the column names listed, and some add a second line with datatypes. Set skip_header to 1 or 2 if you have one or two header lines, and set it to 0 if you have none.
enclose:\"
It is common to enclose strings that contain embedded commas with double-quotes. The sample datasets used in this tutorial have geo locations that contain commas and so the enclose setting is set to \". Remember to escape the " with a \.
max_filter_ratio:1
This allows some errors in the data. Ideally this would be set to 0 and the job would fail with any errors. It is set to 1 to allow all rows to fail during debugging.
columns:
The mapping of CSV file columns to table columns. You will notice that there are many more columns in the CSV files than columns in the table. Any columns that are not included in the table are skipped.
You will also notice that there is some transformation of data included in the columns: line for the crash dataset. It is very common to find dates and times in CSV files that do not conform to standards. This is the logic for converting the CSV data for the time and date of the crash to a DATETIME type:
The columns line
This is the beginning of one data record. The date is inMM/DD/YYYY format, and the time is HH:MI. Since DATETIME is generally YYYY-MM-DD HH:MI:SS we need to transform this data.
columns: parameter:
- Assign the content of the first column of the CSV file to
tmp_CRASH_DATE - Assign the content of the second column of the CSV file to
tmp_CRASH_TIME concat_ws()concatenatestmp_CRASH_DATEandtmp_CRASH_TIMEtogether with a space between themstr_to_date()creates a DATETIME from the concatenated string- store the resulting DATETIME in the column
CRASH_DATE
More information
Defaultvalues.yaml
Stream Load
The Motor Vehicle Collisions - Crashes dataset is provided by New York City subject to these terms of use and privacy policy.
The Local Climatological Data(LCD) is provided by NOAA with this disclaimer and this privacy policy.
Helm is a package manager for Kubernetes. A Helm Chart is a Helm package and contains all of the resource definitions necessary to run an application on a Kubernetes cluster.
starrocks-kubernetes-operator and kube-starrocks Helm Chart.