examples/vitess: Update for Vitess v2.0.0-alpha5

This also enables built-in backup, so the caveat about starting new pods
no longer applies.
This commit is contained in:
Anthony Yeh 2015-10-27 15:16:32 -07:00
parent 5c903dbcac
commit ec99cc2865
12 changed files with 151 additions and 34 deletions

View File

@ -61,11 +61,36 @@ tune these requirements in the
[resource limits](../../docs/user-guide/compute-resources.md) [resource limits](../../docs/user-guide/compute-resources.md)
section of each YAML file. section of each YAML file.
Lastly, you need to open ports 30000 (for the Vitess admin daemon) and 80 (for Lastly, you need to open ports 30000-30001 (for the Vitess admin daemon) and 80 (for
the guestbook app) in your firewall. See the the guestbook app) in your firewall. See the
[Services and Firewalls](../../docs/user-guide/services-firewalls.md) [Services and Firewalls](../../docs/user-guide/services-firewalls.md)
guide for examples of how to do that. guide for examples of how to do that.
### Configure site-local settings
Run the `configure.sh` script to generate a `config.sh` file, which will be used
to customize your cluster settings.
``` console
./configure.sh
```
Currently, we have out-of-the-box support for storing
[backups](http://vitess.io/user-guide/backup-and-restore.html) in
[Google Cloud Storage](https://cloud.google.com/storage/).
If you're using GCS, fill in the fields requested by the configure script.
Note that your Kubernetes cluster must be running on instances with the
`storage-rw` scope for this to work. With Container Engine, you can do this by
passing `--scopes storage-rw` to the `glcoud container clusters create` command.
For other platforms, you'll need to choose the `file` backup storage plugin,
and mount a read-write network volume into the `vttablet` and `vtctld` pods.
For example, you can mount any storage service accessible through NFS into a
Kubernetes volume. Then provide the mount path to the configure script here.
If you prefer to skip setting up a backup volume for the purpose of this example,
you can choose `file` mode and set the path to `/tmp`.
### Start Vitess ### Start Vitess
``` console ``` console
@ -79,7 +104,7 @@ something like this:
**************************** ****************************
* Complete! * Complete!
* Use the following line to make an alias to kvtctl: * Use the following line to make an alias to kvtctl:
* alias kvtctl='$GOPATH/bin/vtctlclient -server 104.197.47.173:30000' * alias kvtctl='$GOPATH/bin/vtctlclient -server 104.197.47.173:30001'
* See the vtctld UI at: http://104.197.47.173:30000 * See the vtctld UI at: http://104.197.47.173:30000
**************************** ****************************
``` ```
@ -115,18 +140,6 @@ in Vitess. Each page number is assigned to one of the shards using a
You may also want to remove any firewall rules you created. You may also want to remove any firewall rules you created.
### Limitations
Currently this example cluster is not configured to use the built-in
[Backup/Restore](http://vitess.io/user-guide/backup-and-restore.html) feature of
Vitess, because as of
[Vitess v2.0.0-alpha2](https://github.com/youtube/vitess/releases) that feature
requires a network-mounted directory. Usually this system is used to restore
from the latest backup when a pod is moved or added in an existing deployment.
As part of the final Vitess v2.0.0 release, we plan to provide support for
saving backups in a cloud-based blob store (such as Google Cloud Storage or
Amazon S3), which we believe will be better suited to running in Kubernetes.
<!-- BEGIN MUNGE: GENERATED_ANALYTICS --> <!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/examples/vitess/README.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/examples/vitess/README.md?pixel)]()

73
examples/vitess/configure.sh Executable file
View File

@ -0,0 +1,73 @@
#!/bin/bash
# Copyright 2015 The Kubernetes Authors All rights reserved.
#
# 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 script generates config.sh, which is a site-local config file that is not
# checked into source control.
# Select and configure Backup Storage Implementation.
storage=gcs
read -p "Backup Storage (file, gcs) [gcs]: "
if [ -n "$REPLY" ]; then storage="$REPLY"; fi
case "$storage" in
gcs)
# Google Cloud Storage
project=$(gcloud config list project | grep 'project\s*=' | sed -r 's/^.*=\s*(.*)$/\1/')
read -p "Google Developers Console Project [$project]: "
if [ -n "$REPLY" ]; then project="$REPLY"; fi
if [ -z "$project" ]; then
echo "ERROR: Project name must not be empty."
exit 1
fi
read -p "Google Cloud Storage bucket for Vitess backups: " bucket
if [ -z "$bucket" ]; then
echo "ERROR: Bucket name must not be empty."
exit 1
fi
echo
echo "NOTE: If you haven't already created this bucket, you can do so by running:"
echo " gsutil mb gs://$bucket"
echo
backup_flags=$(echo -backup_storage_implementation gcs \
-gcs_backup_storage_project "'$project'" \
-gcs_backup_storage_bucket "'$bucket'")
;;
file)
# Mounted volume (e.g. NFS)
read -p "Root directory for backups (usually an NFS mount): " file_root
if [ -z "$file_root" ]; then
echo "ERROR: Root directory must not be empty."
exit 1
fi
echo
echo "NOTE: You must add your NFS mount to the vtctld-controller-template"
echo " and vttablet-pod-template as described in the Kubernetes docs:"
echo " http://kubernetes.io/v1.0/docs/user-guide/volumes.html#nfs"
echo
backup_flags=$(echo -backup_storage_implementation file \
-file_backup_storage_root "'$file_root'")
;;
*)
echo "ERROR: Unsupported backup storage implementation: $storage"
exit 1
esac
echo "Saving config.sh..."
echo "backup_flags=\"$backup_flags\"" > config.sh

View File

@ -21,7 +21,7 @@
KUBECTL=${KUBECTL:-kubectl} KUBECTL=${KUBECTL:-kubectl}
# This should match the nodePort in vtctld-service.yaml # This should match the nodePort in vtctld-service.yaml
VTCTLD_PORT=${VTCTLD_PORT:-30000} VTCTLD_PORT=${VTCTLD_PORT:-30001}
# Customizable parameters # Customizable parameters
SHARDS=${SHARDS:-'-80,80-'} SHARDS=${SHARDS:-'-80,80-'}
@ -53,3 +53,11 @@ get_vtctld_addr() {
echo "$VTCTLD_ADDR" echo "$VTCTLD_ADDR"
} }
config_file=`dirname "${BASH_SOURCE}"`/config.sh
if [ ! -f $config_file ]; then
echo "Please run ./configure.sh first to generate config.sh file."
exit 1
fi
source $config_file

View File

@ -12,7 +12,7 @@ spec:
spec: spec:
containers: containers:
- name: guestbook - name: guestbook
image: vitess/guestbook:v2.0.0-alpha3 image: vitess/guestbook:v2.0.0-alpha5
ports: ports:
- name: http-server - name: http-server
containerPort: 8080 containerPort: 8080

View File

@ -74,7 +74,7 @@ fi
export KUBECTL='kubectl' export KUBECTL='kubectl'
echo "Downloading and installing vtctlclient..." echo "Downloading and installing vtctlclient..."
go get github.com/youtube/vitess/go/cmd/vtctlclient go get -u github.com/youtube/vitess/go/cmd/vtctlclient
num_shards=`echo $SHARDS | tr "," " " | wc -w` num_shards=`echo $SHARDS | tr "," " " | wc -w`
total_tablet_count=$(($num_shards*$TABLETS_PER_SHARD*$num_cells)) total_tablet_count=$(($num_shards*$TABLETS_PER_SHARD*$num_cells))
vtgate_count=$VTGATE_COUNT vtgate_count=$VTGATE_COUNT
@ -105,7 +105,7 @@ wait_for_running_tasks vtctld 1
wait_for_running_tasks vttablet $total_tablet_count wait_for_running_tasks vttablet $total_tablet_count
wait_for_running_tasks vtgate $vtgate_count wait_for_running_tasks vtgate $vtgate_count
vtctld_port=30000 vtctld_port=30001
vtctld_ip=`kubectl get -o yaml nodes | grep 'type: ExternalIP' -B 1 | head -1 | awk '{print $NF}'` vtctld_ip=`kubectl get -o yaml nodes | grep 'type: ExternalIP' -B 1 | head -1 | awk '{print $NF}'`
vtctl_server="$vtctld_ip:$vtctld_port" vtctl_server="$vtctld_ip:$vtctld_port"
kvtctl="$GOPATH/bin/vtctlclient -server $vtctl_server" kvtctl="$GOPATH/bin/vtctlclient -server $vtctl_server"
@ -160,5 +160,6 @@ echo "****************************"
echo "* Complete!" echo "* Complete!"
echo "* Use the following line to make an alias to kvtctl:" echo "* Use the following line to make an alias to kvtctl:"
echo "* alias kvtctl='\$GOPATH/bin/vtctlclient -server $vtctl_server'" echo "* alias kvtctl='\$GOPATH/bin/vtctlclient -server $vtctl_server'"
echo "* See the vtctld UI at: http://${vtctl_server}" echo "* See the vtctld UI at: http://${vtctld_ip}:30000"
echo "****************************" echo "****************************"

View File

@ -12,12 +12,15 @@ spec:
spec: spec:
containers: containers:
- name: vtctld - name: vtctld
image: vitess/lite:v2.0.0-alpha3 image: vitess/lite:v2.0.0-alpha5
volumeMounts: volumeMounts:
- name: syslog - name: syslog
mountPath: /dev/log mountPath: /dev/log
- name: vtdataroot - name: vtdataroot
mountPath: /vt/vtdataroot mountPath: /vt/vtdataroot
- name: certs
readOnly: true
mountPath: /etc/ssl/certs
resources: resources:
limits: limits:
memory: "128Mi" memory: "128Mi"
@ -35,13 +38,18 @@ spec:
-log_dir $VTDATAROOT/tmp -log_dir $VTDATAROOT/tmp
-alsologtostderr -alsologtostderr
-port 15000 -port 15000
-service_map 'bsonrpc-vt-vtctl' -grpc_port 15001
-service_map 'grpc-vtctl'
-topo_implementation etcd -topo_implementation etcd
-tablet_protocol grpc -tablet_protocol grpc
-tablet_manager_protocol grpc -tablet_manager_protocol grpc
-etcd_global_addrs http://$ETCD_GLOBAL_SERVICE_HOST:$ETCD_GLOBAL_SERVICE_PORT" vitess -etcd_global_addrs http://$ETCD_GLOBAL_SERVICE_HOST:$ETCD_GLOBAL_SERVICE_PORT
{{backup_flags}}" vitess
volumes: volumes:
- name: syslog - name: syslog
hostPath: {path: /dev/log} hostPath: {path: /dev/log}
- name: vtdataroot - name: vtdataroot
emptyDir: {} emptyDir: {}
- name: certs
hostPath: {path: /etc/ssl/certs}

View File

@ -8,8 +8,13 @@ metadata:
spec: spec:
ports: ports:
- port: 15000 - port: 15000
name: web
targetPort: 15000 targetPort: 15000
nodePort: 30000 nodePort: 30000
- port: 15001
name: grpc
targetPort: 15001
nodePort: 30001
selector: selector:
component: vtctld component: vtctld
app: vitess app: vitess

View File

@ -25,7 +25,14 @@ echo "Creating vtctld service..."
$KUBECTL create -f vtctld-service.yaml $KUBECTL create -f vtctld-service.yaml
echo "Creating vtctld replicationcontroller..." echo "Creating vtctld replicationcontroller..."
$KUBECTL create -f vtctld-controller.yaml # Expand template variables
sed_script=""
for var in backup_flags; do
sed_script+="s,{{$var}},${!var},g;"
done
# Instantiate template and send to kubectl.
cat vtctld-controller-template.yaml | sed -e "$sed_script" | $KUBECTL create -f -
server=$(get_vtctld_addr) server=$(get_vtctld_addr)
echo echo

View File

@ -12,7 +12,7 @@ spec:
spec: spec:
containers: containers:
- name: vtgate - name: vtgate
image: vitess/lite:v2.0.0-alpha3 image: vitess/lite:v2.0.0-alpha5
volumeMounts: volumeMounts:
- name: syslog - name: syslog
mountPath: /dev/log mountPath: /dev/log

View File

@ -41,12 +41,6 @@ for shard in `seq 1 $num_shards`; do
uid=$[$uid_base + $uid_index + $cell_index] uid=$[$uid_base + $uid_index + $cell_index]
printf -v alias '%s-%010d' $cell $uid printf -v alias '%s-%010d' $cell $uid
if [ -n "$server" ]; then
echo "Removing tablet $alias from Vitess topology..."
vtctlclient -server $server ScrapTablet -force $alias
vtctlclient -server $server DeleteTablet $alias
fi
echo "Deleting pod for tablet $alias..." echo "Deleting pod for tablet $alias..."
$KUBECTL delete pod vttablet-$uid $KUBECTL delete pod vttablet-$uid
done done
@ -54,3 +48,4 @@ for shard in `seq 1 $num_shards`; do
done done
let uid_base=uid_base+100 let uid_base=uid_base+100
done done

View File

@ -11,12 +11,15 @@ metadata:
spec: spec:
containers: containers:
- name: vttablet - name: vttablet
image: vitess/lite:v2.0.0-alpha3 image: vitess/lite:v2.0.0-alpha5
volumeMounts: volumeMounts:
- name: syslog - name: syslog
mountPath: /dev/log mountPath: /dev/log
- name: vtdataroot - name: vtdataroot
mountPath: /vt/vtdataroot mountPath: /vt/vtdataroot
- name: certs
readOnly: true
mountPath: /etc/ssl/certs
resources: resources:
limits: limits:
memory: "1Gi" memory: "1Gi"
@ -70,9 +73,11 @@ spec:
-db-config-filtered-charset utf8 -db-config-filtered-charset utf8
-enable-rowcache -enable-rowcache
-rowcache-bin /usr/bin/memcached -rowcache-bin /usr/bin/memcached
-rowcache-socket $VTDATAROOT/{{tablet_subdir}}/memcache.sock" vitess -rowcache-socket $VTDATAROOT/{{tablet_subdir}}/memcache.sock
-health_check_interval 5s
-restore_from_backup {{backup_flags}}" vitess
- name: mysql - name: mysql
image: vitess/lite:v2.0.0-alpha3 image: vitess/lite:v2.0.0-alpha5
volumeMounts: volumeMounts:
- name: syslog - name: syslog
mountPath: /dev/log mountPath: /dev/log
@ -118,4 +123,6 @@ spec:
hostPath: {path: /dev/log} hostPath: {path: /dev/log}
- name: vtdataroot - name: vtdataroot
emptyDir: {} emptyDir: {}
- name: certs
hostPath: {path: /etc/ssl/certs}

View File

@ -55,7 +55,7 @@ for shard in $(echo $SHARDS | tr "," " "); do
# Expand template variables # Expand template variables
sed_script="" sed_script=""
for var in alias cell uid keyspace shard shard_label port grpc_port tablet_subdir tablet_type; do for var in alias cell uid keyspace shard shard_label port grpc_port tablet_subdir tablet_type backup_flags; do
sed_script+="s,{{$var}},${!var},g;" sed_script+="s,{{$var}},${!var},g;"
done done