vitess.io/vitess@v0.16.2/examples/common/scripts/k3s-up.sh (about) 1 #!/bin/bash 2 3 # Copyright 2019 The Vitess Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # This is an example script that creates a Kubernetes api for topo use by running k3s 18 19 set -e 20 cell=${CELL:-'test'} 21 22 script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")" 23 source "${script_dir}/../env.sh" 24 25 case $(uname) in 26 Linux) ;; 27 *) echo "WARNING: unsupported platform. K3s only supports running on Linux, the k8s topology is available for local examples."; exit 1;; 28 esac 29 30 case $(uname -m) in 31 aarch64) ;; 32 x86_64) ;; 33 *) echo "ERROR: unsupported architecture, the k8s topology is not available for local examples."; exit 1;; 34 esac 35 36 k3s server --disable-agent --data-dir "${VTDATAROOT}/k3s/" --https-listen-port "${K8S_PORT}" --write-kubeconfig "${K8S_KUBECONFIG}" > "${VTDATAROOT}"/tmp/k3s.out 2>&1 & 37 PID=$! 38 echo $PID > "${VTDATAROOT}/tmp/k3s.pid" 39 disown -a 40 echo "Waiting for k3s server to start" 41 sleep 15 42 43 # Use k3s built-in kubectl with custom config 44 KUBECTL="k3s kubectl --kubeconfig=${K8S_KUBECONFIG}" 45 46 # Create the CRD for vitesstopologynodes 47 $KUBECTL create -f "${script_dir}/../../../go/vt/topo/k8stopo/VitessTopoNodes-crd.yaml" 48 49 # Add the CellInfo description for the cell 50 set +e 51 echo "add $cell CellInfo" 52 vtctl $TOPOLOGY_FLAGS VtctldCommand AddCellInfo \ 53 --root /vitess/$cell \ 54 $cell 55 set -e 56 57 echo "k3s start done..."