From f9094ed7cf7e4358fa347245c2821dcc533af306 Mon Sep 17 00:00:00 2001 From: Sugu Sougoumarane Date: Fri, 10 Apr 2020 20:24:43 -0700 Subject: [PATCH] helm: improved commands Signed-off-by: Sugu Sougoumarane --- examples/helm/README.md | 51 ++++++++++++++++++++++++++++++++++++++ examples/helm/alias.source | 35 ++++++++++++++++++++++++++ examples/helm/kmysql.sh | 36 --------------------------- 3 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 examples/helm/README.md create mode 100644 examples/helm/alias.source delete mode 100755 examples/helm/kmysql.sh diff --git a/examples/helm/README.md b/examples/helm/README.md new file mode 100644 index 00000000000..0e13d99dc2f --- /dev/null +++ b/examples/helm/README.md @@ -0,0 +1,51 @@ +# Instructions + +Detailed instructions for running this example can be found at https://vitess.io. +This document contains the summary of the commands to be run. + + +``` +# Start minikube +minikube start --kubernetes-version v1.15.0 --cpus=4 --memory=5000 + +# Bring up initial cluster and commerce keyspace +helm install vitess ../../helm/vitess -f 101_initial_cluster.yaml + +# Setup aliases +source alias.source + +# Insert and verify data +vmysql < ../common/insert_commerce_data.sql +vmysql --table < ../common/select_commerce_data.sql + +# Bring up customer keyspace +helm upgrade vitess ../../helm/vitess/ -f 201_customer_tablets.yaml + +# Initiate move tables +vclient MoveTables -workflow=commerce2customer commerce customer '{"customer":{}, "corder":{}}' + +# Cut-over +vclient SwitchReads -tablet_type=rdonly customer.commerce2customer +vclient SwitchReads -tablet_type=replica customer.commerce2customer +vclient SwitchWrites customer.commerce2customer + +# Clean-up +vclient SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 rdonly +vclient SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 replica +vclient SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 master +vclient ApplyRoutingRules -rules='{}' + +# Prepare for resharding +helm upgrade vitess ../../helm/vitess/ -f 301_customer_sharded.yaml +helm upgrade vitess ../../helm/vitess/ -f 302_new_shards.yaml + +# Reshard +vclient Reshard customer.cust2cust '0' '-80,80-' +vclient SwitchReads -tablet_type=rdonly customer.cust2cust +vclient SwitchReads -tablet_type=replica customer.cust2cust +vclient SwitchWrites customer.cust2cust + +# Down shard 0 +helm upgrade vitess ../../helm/vitess/ -f 306_down_shard_0.yaml +vclient DeleteShard -recursive customer/0 +``` diff --git a/examples/helm/alias.source b/examples/helm/alias.source new file mode 100644 index 00000000000..15d203da711 --- /dev/null +++ b/examples/helm/alias.source @@ -0,0 +1,35 @@ +function vhostport() { + vhost=$(minikube service $1 --url=true --format="{{.IP}}" | tail -n 1) + vport=$(minikube service $1 --url=true --format="{{.Port}}" | tail -n 1) + + if [ -z $vport ]; then + # This checks K8s running on an single node by kubeadm + if [ $(kubectl get nodes | grep -v NAM | wc -l) -eq 1 -o $(kubectl get nodes | grep -v NAM | grep master | wc -l ) -eq 1 ]; then + vhost="127.0.0.1" + vport=`kubectl describe service vtgate-zone1 | grep NodePort | grep mysql | awk '{print $3}' | awk -F'/' '{print $1}'` + fi + fi +} + +function vsetmysql() { + vhostport vtgate-zone1 + if [ -z $vport ]; then + echo "Error: failed to obtain [host:port] minikube or kubectl." + return 1 + fi + echo "Setting alias vmysql to: mysql -h $vhost -P $vport" + alias vmysql="mysql -h $vhost -P $vport" +} + +function vsetvclient() { + vhostport vtctld + if [ -z $vport ]; then + echo "Error: failed to: obtain [host:port] minikube or kubectl." + return 1 + fi + echo "Setting alias vclient to vtctlclient -server=$vhost:$vport" + alias vclient="vtctlclient -server=$vhost:$vport" +} + +vsetmysql +vsetvclient diff --git a/examples/helm/kmysql.sh b/examples/helm/kmysql.sh deleted file mode 100755 index f9cfaaf80a4..00000000000 --- a/examples/helm/kmysql.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -# Copyright 2019 The Vitess Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is a convenience script to run the mysql client against the local example. - -host=$(minikube service vtgate-zone1 --url=true --format="{{.IP}}" | tail -n 1) -port=$(minikube service vtgate-zone1 --url=true --format="{{.Port}}" | tail -n 1) - -if [ -z $port ]; then - #This checks K8s running on an single node by kubeadm - if [ $(kubectl get nodes | grep -v NAM | wc -l) -eq 1 -o $(kubectl get nodes | grep -v NAM | grep master | wc -l ) -eq 1 ]; then - host="127.0.0.1" - port=`kubectl describe service vtgate-zone1 | grep NodePort | grep mysql | awk '{print $3}' | awk -F'/' '{print $1}'` - fi -fi - -if [ -z $port ]; then - echo "Error: failed to obtain [host:port] minikube or kubectl." - exit 1; - -fi - -mysql -h "$host" -P "$port" $*