forked from karmada-io/karmada
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathremote-up-karmada.sh
executable file
·82 lines (70 loc) · 2.82 KB
/
remote-up-karmada.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
# Copyright 2021 The Karmada 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.
set -o errexit
set -o nounset
set -o pipefail
function usage() {
echo "This script will deploy karmada control plane to a given cluster."
echo "Usage: hack/remote-up-karmada.sh <KUBECONFIG> <CONTEXT_NAME> [LOAD_BALANCER]"
echo "Example: hack/remote-up-karmada.sh ~/.kube/config karmada-host"
echo -e "Parameters:\n\tKUBECONFIG\tYour cluster's kubeconfig that you want to install to"
echo -e "\tCONTEXT_NAME\tThe name of context in 'kubeconfig'"
echo -e "\tLOAD_BALANCER\tThis option default is 'false', and there will directly use 'hostNetwork' to communicate
\t\t\toutside the karmada-host cluster
\t\t\tif you want to create a 'LoadBalancer' type service for karmada apiserver, set as 'true'."
}
if [[ $# -lt 2 ]]; then
usage
exit 1
fi
# check config file existence
HOST_CLUSTER_KUBECONFIG=$1
if [[ ! -f "${HOST_CLUSTER_KUBECONFIG}" ]]; then
echo -e "ERROR: failed to get kubernetes config file: '${HOST_CLUSTER_KUBECONFIG}', not existed.\n"
usage
exit 1
fi
# check context existence
export KUBECONFIG="${HOST_CLUSTER_KUBECONFIG}"
HOST_CLUSTER_NAME=$2
if ! kubectl config get-contexts "${HOST_CLUSTER_NAME}" > /dev/null 2>&1;
then
echo -e "ERROR: failed to get context: '${HOST_CLUSTER_NAME}' not in ${HOST_CLUSTER_KUBECONFIG}. \n"
usage
exit 1
fi
if [ "${3:-false}" = true ]; then
LOAD_BALANCER=true
export LOAD_BALANCER
fi
# deploy karmada control plane
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${SCRIPT_ROOT}"/hack/util.sh
# proxy setting in China mainland
if [[ -n ${CHINA_MAINLAND:-} ]]; then
util::set_mirror_registry_for_china_mainland ${SCRIPT_ROOT}
fi
"${SCRIPT_ROOT}"/hack/deploy-karmada.sh "${HOST_CLUSTER_KUBECONFIG}" "${HOST_CLUSTER_NAME}" "remote"
function print_success() {
echo -e "$KARMADA_GREETING"
echo "Karmada is installed successfully."
echo
echo "Kubeconfig for karmada in file: ${HOST_CLUSTER_KUBECONFIG}, so you can run:"
echo " export KUBECONFIG=\"${HOST_CLUSTER_KUBECONFIG}\""
echo "Or use kubectl with --kubeconfig=${HOST_CLUSTER_KUBECONFIG}"
echo "Please use 'kubectl config use-context karmada-apiserver' to switch the cluster of karmada control plane"
echo "And use 'kubectl config use-context ${HOST_CLUSTER_NAME}' for debugging karmada installation"
}
print_success