etcd-up.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. # Copyright 2015 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # This is an example script that creates etcd clusters.
  16. # Vitess requires a global cluster, as well as one for each cell.
  17. #
  18. # For automatic discovery, an etcd cluster can be bootstrapped from an
  19. # existing cluster. In this example, we use an externally-run discovery
  20. # service, but you can use your own. See the etcd docs for more:
  21. # https://github.com/coreos/etcd/blob/v2.0.13/Documentation/clustering.md
  22. set -e
  23. script_root=`dirname "${BASH_SOURCE}"`
  24. source $script_root/env.sh
  25. replicas=${ETCD_REPLICAS:-3}
  26. CELLS=${CELLS:-'test'}
  27. cells=`echo $CELLS | tr ',' ' '`
  28. for cell in 'global' $cells; do
  29. # Generate a discovery token.
  30. echo "Generating discovery token for $cell cell..."
  31. discovery=$(curl -sL https://discovery.etcd.io/new?size=$replicas)
  32. if [ -z "$discovery" ]; then
  33. echo "Failed to get etcd discovery token for cell '$cell'."
  34. exit 1
  35. fi
  36. # Create the client service, which will load-balance across all replicas.
  37. echo "Creating etcd service for $cell cell..."
  38. cat etcd-service-template.yaml | \
  39. sed -e "s/{{cell}}/$cell/g" | \
  40. $KUBECTL create -f -
  41. # Expand template variables
  42. sed_script=""
  43. for var in cell discovery replicas; do
  44. sed_script+="s,{{$var}},${!var},g;"
  45. done
  46. # Create the replication controller.
  47. echo "Creating etcd replicationcontroller for $cell cell..."
  48. cat etcd-controller-template.yaml | sed -e "$sed_script" | $KUBECTL create -f -
  49. done