This commit is contained in:
Joshua Thompson 2015-12-22 11:06:01 -08:00
Родитель 1c8ec1a227
Коммит ff185537fc
3 изменённых файлов: 65 добавлений и 37 удалений

Просмотреть файл

@ -2,36 +2,53 @@
## Automatically run Vitess on Container Engine
The following command will create a Google Container Engine cluster and bring
The following commands will create a Google Container Engine cluster and bring
up Vitess with two shards and three tablets per shard: (Note that it does not
bring up the Guestbook example)
```
vitess/examples/kubernetes$ export SHARDS=-80,80-
vitess/examples/kubernetes$ export GKE_ZONE=us-central1-b
vitess/examples/kubernetes$ export GKE_NUM_NODES=10
vitess/examples/kubernetes$ export GKE_MACHINE_TYPE=n1-standard-8
vitess/examples/kubernetes$ ./cluster-up.sh
vitess/examples/kubernetes$ ./vitess-up.sh
```
Run the following to tear down the entire Vitess + container engine cluster:
```
vitess/examples/kubernetes$ ./vitess-down.sh
vitess/examples/kubernetes$ ./cluster-down.sh
```
## Parameterizing configs
The vttablet and cluster scripts both support parameterization via exporting
The vitess and cluster scripts both support parameterization via exporting
environment variables.
### Parameterizing cluster scripts
The cluster-up.sh script supports the following environment variables:
Common environment variables:
* GKE_ZONE - Zone to use for Container Engine (default us-central1-b)
* GKE_MACHINE_TYPE - Container Engine machine type (default n1-standard-1)
* GKE_NUM_NODES - Number of nodes to use for the cluster (default 3).
* GKE_CLUSTER_NAME - Name to use when creating a cluster (default example).
* SHARDS - Comma delimited keyranges for shards (default -80,80- for 2 shards).
Use 0 for an unsharded keyspace.
* TABLETS_PER_SHARD - Number of shards per shard (default 3).
The cluster-up.sh script supports the following environment variables:
* GKE_MACHINE_TYPE - Container Engine machine type (default n1-standard-1)
* GKE_NUM_NODES - Number of nodes to use for the cluster (required).
* GKE_SSD_SIZE_GB - SSD size (in GB) to use (default 0 for no SSD).
The vitess-up.sh script supports the following environment variables:
* TABLETS_PER_SHARD - Number of tablets per shard (default 3).
* RDONLY_COUNT - Number of tablets per shard that are rdonly (default 0).
* VTGATE_COUNT - Number of vtgates (default 25% of total vttablet count,
with a minimum of 3).
For example, to create an unsharded keyspace with 5 tablets, use the following:
@ -39,9 +56,6 @@ For example, to create an unsharded keyspace with 5 tablets, use the following:
export SHARDS=0
export TABLETS_PER_SHARD=5
vitess/examples/kubernetes$ ./cluster-up.sh
vitess/examples/kubernetes$ ./vitess-up.sh
```
### Parameterizing vttablet scripts
Both SHARDS and TABLETS_PER_SHARD from cluster-up.sh apply to vttablet-up.sh.

Просмотреть файл

@ -24,6 +24,7 @@ VTGATE_TEMPLATE=${VTGATE_TEMPLATE:-'vtgate-controller-benchmarking-template.yaml
VTGATE_COUNT=${VTGATE_COUNT:-0}
VTDATAROOT_VOLUME=${VTDATAROOT_VOLUME:-''}
CELLS=${CELLS:-'test'}
KEYSPACE=${KEYSPACE:-'test_keyspace'}
cells=`echo $CELLS | tr ',' ' '`
num_cells=`echo $cells | wc -w`
@ -31,6 +32,13 @@ num_cells=`echo $cells | wc -w`
# Get region from zone (everything to last dash)
gke_region=`echo $GKE_ZONE | sed "s/-[^-]*$//"`
num_shards=`echo $SHARDS | tr "," " " | wc -w`
total_tablet_count=$(($num_shards*$TABLETS_PER_SHARD*$num_cells))
vtgate_count=$VTGATE_COUNT
if [ $vtgate_count -eq 0 ]; then
vtgate_count=$(($total_tablet_count/4>3?$total_tablet_count/4:3))
fi
# export for vttablet scripts
export SHARDS=$SHARDS
export TABLETS_PER_SHARD=$TABLETS_PER_SHARD
@ -38,7 +46,7 @@ export RDONLY_COUNT=$RDONLY_COUNT
export VTDATAROOT_VOLUME=$VTDATAROOT_VOLUME
export VTGATE_TEMPLATE=$VTGATE_TEMPLATE
export VTTABLET_TEMPLATE=$VTTABLET_TEMPLATE
export VTGATE_REPLICAS=$VTGATE_COUNT
export VTGATE_REPLICAS=$vtgate_count
function update_spinner_value () {
spinner='-\|/'
@ -84,12 +92,6 @@ fi
export KUBECTL='kubectl'
go get github.com/youtube/vitess/go/cmd/vtctlclient
num_shards=`echo $SHARDS | tr "," " " | wc -w`
total_tablet_count=$(($num_shards*$TABLETS_PER_SHARD*$num_cells))
vtgate_count=$VTGATE_COUNT
if [ $vtgate_count -eq 0 ]; then
vtgate_count=$(($total_tablet_count/4>3?$total_tablet_count/4:3))
fi
echo "****************************"
echo "*Creating vitess cluster:"
@ -108,26 +110,32 @@ for cell in $cells; do
done
echo 'Running vtctld-up.sh' && ./vtctld-up.sh
echo 'Running vttablet-up.sh' && CELLS=$CELLS ./vttablet-up.sh
echo 'Running vtgate-up.sh' && ./vtgate-up.sh
wait_for_running_tasks vtctld 1
wait_for_running_tasks vttablet $total_tablet_count
wait_for_running_tasks vtgate $vtgate_count
echo Creating firewall rule for vtctld...
vtctld_port=30001
gcloud compute firewall-rules create ${GKE_CLUSTER_NAME}-vtctld --allow tcp:$vtctld_port
vtctld_ip=`$KUBECTL get -o yaml nodes | grep 'type: ExternalIP' -B 1 | head -1 | awk '{print $NF}'`
vtctl_server="$vtctld_ip:$vtctld_port"
kvtctl="$GOPATH/bin/vtctlclient -server $vtctl_server"
kvtctl="./kvtctl.sh"
if [ $num_shards -gt 0 ]
then
echo Calling CreateKeyspace and SetKeyspaceShardingInfo
$kvtctl CreateKeyspace -force $KEYSPACE
$kvtctl SetKeyspaceShardingInfo -force -split_shard_count $num_shards $KEYSPACE keyspace_id uint64
fi
echo 'Running vttablet-up.sh' && CELLS=$CELLS ./vttablet-up.sh
echo 'Running vtgate-up.sh' && ./vtgate-up.sh
wait_for_running_tasks vttablet $total_tablet_count
wait_for_running_tasks vtgate $vtgate_count
echo Waiting for tablets to be visible in the topology
counter=0
while [ $counter -lt $MAX_VTTABLET_TOPO_WAIT_RETRIES ]; do
num_tablets=0
for cell in $cells; do
num_tablets=$(($num_tablets+`$kvtctl ListAllTablets $cell | wc -l`))
num_tablets=$(($num_tablets+`$kvtctl ListAllTablets $cell | grep $KEYSPACE | wc -l`))
done
echo -en "\r$num_tablets out of $total_tablet_count in topology..."
if [ $num_tablets -eq $total_tablet_count ]
@ -152,20 +160,20 @@ if [ $split_shard_count -eq 1 ]; then
fi
echo -n Setting Keyspace Sharding Info...
$kvtctl SetKeyspaceShardingInfo -force -split_shard_count $split_shard_count test_keyspace keyspace_id uint64
$kvtctl SetKeyspaceShardingInfo -force -split_shard_count $split_shard_count $KEYSPACE keyspace_id uint64
echo Done
echo -n Rebuilding Keyspace Graph...
$kvtctl RebuildKeyspaceGraph test_keyspace
$kvtctl RebuildKeyspaceGraph $KEYSPACE
echo Done
echo -n Reparenting...
shard_num=1
for shard in $(echo $SHARDS | tr "," " "); do
$kvtctl InitShardMaster -force test_keyspace/$shard `echo $cells | awk '{print $1}'`-0000000${shard_num}00
$kvtctl InitShardMaster -force $KEYSPACE/$shard `echo $cells | awk '{print $1}'`-0000000${shard_num}00
let shard_num=shard_num+1
done
echo Done
echo -n Applying Schema...
$kvtctl ApplySchema -sql "$(cat create_test_table.sql)" test_keyspace
$kvtctl ApplySchema -sql "$(cat create_test_table.sql)" $KEYSPACE
echo Done
echo Creating firewall rule for vtgate
@ -189,8 +197,8 @@ fi
echo "****************************"
echo "* Complete!"
echo "* Use the following line to make an alias to kvtctl:"
echo "* alias kvtctl='\$GOPATH/bin/vtctlclient -server $vtctl_server'"
echo "* vtctld: [http://${vtctl_server}]"
echo "* Access the vtctld web UI by performing the following steps:"
echo "* $ kubectl proxy --port=8001"
echo "* Visit http://localhost:8001/api/v1/proxy/namespaces/default/services/vtctld:web/"
echo "* vtgate: $vtgate_server"
echo "****************************"

Просмотреть файл

@ -13,15 +13,21 @@ spec:
containers:
- name: vtgate
image: vitess/root
resources:
limits:
memory: "4Gi"
cpu: "6"
livenessProbe:
httpGet:
path: /debug/vars
port: 15001
initialDelaySeconds: 30
timeoutSeconds: 5
volumeMounts:
- name: syslog
mountPath: /dev/log
- name: vtdataroot
mountPath: /vt/vtdataroot
resources:
limits:
memory: "4Gi"
cpu: "6"
command:
- sh
- "-c"