improve deployment script

Signed-off-by: Kevin Wang <kevinwzf0126@gmail.com>
This commit is contained in:
Kevin Wang 2020-12-22 17:46:02 +08:00 committed by Hongcai Ren
parent 23a62796e4
commit 162f609c36
3 changed files with 20 additions and 32 deletions

View File

@ -8,11 +8,9 @@ CERT_DIR=${CERT_DIR:-"/var/run/karmada"}
KARMADA_APISERVER_CONFIG="${CERT_DIR}/karmada-apiserver.config"
KUBECONFIG_PATH=${KUBECONFIG_PATH:-"${HOME}/.kube"}
KARMADA_KUBECONFIG="${KUBECONFIG_PATH}/karmada.config"
etcd_replicas=1
etcd_pod_label="etcd"
apiserver_replicas=1
apiserver_pod_label="karmada-apiserver"
controller_replicas=1
controller_pod_label="kube-controller-manager"
function usage() {
@ -23,32 +21,10 @@ function usage() {
function waitPodReady() {
local pod_label=$1
local pod_namespaces=$2
local pod_replicas=$3
local pod_namespace=$2
timeout=200
while [[ $timeout -gt 0 ]]; do
echo "Waiting for $pod_label pods to become Ready"
statuses=$(kubectl get pods -n $pod_namespaces -l app=$pod_label \
-o jsonpath='{.items[*].status.conditions[?(@.type=="Ready")].status}' \
| grep "True" | wc -w)
if [[ $statuses -eq $pod_replicas ]]; then
break
else
sleep 1
(( timeout=timeout-1 ))
fi
done
if [[ $timeout -gt 0 ]]; then
echo "All $pod_label pods became Ready"
else
echo "ERROR: Not all $pod_label pods became Ready"
echo "kubectl get pods -l app=$pod_label"
kubectl get pods -l app=$pod_label
exit 1
fi
echo "wait the $pod_label ready..."
kubectl wait --for=condition=Ready --timeout=60s pods -l app=$pod_label -n $pod_namespace
}
function installCRDs() {
@ -80,7 +56,7 @@ kubectl create -f "${SCRIPT_ROOT}/artifacts/deploy/clusterrolebinding.yaml"
kubectl create -f "${SCRIPT_ROOT}/artifacts/deploy/karmada-etcd.yaml"
# Wait for karmada-etcd to come up before launching the rest of the components.
waitPodReady $etcd_pod_label "karmada-system" $etcd_replicas
waitPodReady $etcd_pod_label "karmada-system"
# deploy karmada apiserver
KARMADA_API_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "karmada-control-plane")
@ -90,13 +66,13 @@ sed -i "s/{{api_addr}}/${KARMADA_API_IP}/g" ${SCRIPT_ROOT}/artifacts/deploy/karm
kubectl create -f "${SCRIPT_ROOT}/artifacts/deploy/karmada-apiserver-tmp.yaml"
# Wait for karmada-apiserver to come up before launching the rest of the components.
waitPodReady $apiserver_pod_label "karmada-system" $apiserver_replicas
waitPodReady $apiserver_pod_label "karmada-system"
# deploy kube controller manager
kubectl create -f "${SCRIPT_ROOT}/artifacts/deploy/kube-controller-manager.yaml"
# Wait for karmada kube controller manager to come up before launching the rest of the components.
waitPodReady $controller_pod_label "karmada-system" $controller_replicas
waitPodReady $controller_pod_label "karmada-system"
export KUBECONFIG=${KARMADA_APISERVER_CONFIG}

View File

@ -29,3 +29,15 @@ karmadactl join member1 --member-cluster-kubeconfig="${MEMBER_CLUSTER_1_KUBECONF
MEMBER_CLUSTER_2_KUBECONFIG="${KUBECONFIG_PATH}/member2.config"
"${REPO_ROOT}"/hack/create-cluster.sh member2 "${MEMBER_CLUSTER_2_KUBECONFIG}"
karmadactl join member2 --member-cluster-kubeconfig="${MEMBER_CLUSTER_2_KUBECONFIG}"
function print_success() {
echo
echo "Local Karmada is running."
echo "To start using your karmada, run:"
cat <<EOF
export KUBECONFIG=${KUBECONFIG}
EOF
}
print_success

View File

@ -39,7 +39,7 @@ function print_success() {
echo "Local Karmada is running."
echo "To start using your karmada, run:"
cat <<EOF
export KUBECONFIG=${KARMADA_KUBECONFIG}
export KUBECONFIG=${KUBECONFIG_PATH}/karmada-apiserver.config
EOF
}