From 21470e3c57434990a1a5d446d2d2b35d3555079e Mon Sep 17 00:00:00 2001 From: Garrybest Date: Sat, 18 Sep 2021 15:48:51 +0800 Subject: [PATCH] add deploy script of scheduler estimator Signed-off-by: Garrybest --- .../deploy/karmada-scheduler-estimator.yaml | 51 +++++++++++++ hack/deploy-scheduler-estimator.sh | 74 +++++++++++++++++++ hack/local-up-karmada.sh | 1 + 3 files changed, 126 insertions(+) create mode 100644 artifacts/deploy/karmada-scheduler-estimator.yaml create mode 100755 hack/deploy-scheduler-estimator.sh diff --git a/artifacts/deploy/karmada-scheduler-estimator.yaml b/artifacts/deploy/karmada-scheduler-estimator.yaml new file mode 100644 index 000000000..88d7e2783 --- /dev/null +++ b/artifacts/deploy/karmada-scheduler-estimator.yaml @@ -0,0 +1,51 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: karmada-scheduler-estimator-{{member_cluster_name}} + namespace: karmada-system + labels: + cluster: {{member_cluster_name}} +spec: + replicas: 1 + selector: + matchLabels: + app: karmada-scheduler-estimator-{{member_cluster_name}} + template: + metadata: + labels: + app: karmada-scheduler-estimator-{{member_cluster_name}} + spec: + tolerations: + - key: node-role.kubernetes.io/master + operator: Exists + containers: + - name: karmada-scheduler-estimator + image: swr.ap-southeast-1.myhuaweicloud.com/karmada/karmada-scheduler-estimator:latest + imagePullPolicy: IfNotPresent + command: + - /bin/karmada-scheduler-estimator + - --kubeconfig=/etc/{{member_cluster_name}}-kubeconfig + - --cluster-name={{member_cluster_name}} + volumeMounts: + - name: member-kubeconfig + subPath: {{member_cluster_name}}-kubeconfig + mountPath: /etc/{{member_cluster_name}}-kubeconfig + volumes: + - name: member-kubeconfig + secret: + secretName: {{member_cluster_name}}-kubeconfig +--- +apiVersion: v1 +kind: Service +metadata: + name: karmada-scheduler-estimator-{{member_cluster_name}} + namespace: karmada-system + labels: + cluster: {{member_cluster_name}} +spec: + selector: + app: karmada-scheduler-estimator-{{member_cluster_name}} + ports: + - protocol: TCP + port: 10352 + targetPort: 10352 diff --git a/hack/deploy-scheduler-estimator.sh b/hack/deploy-scheduler-estimator.sh new file mode 100755 index 000000000..b40aa4b26 --- /dev/null +++ b/hack/deploy-scheduler-estimator.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +set -o errexit +set -o nounset + +REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +function usage() { + echo "This script will deploy karmada-scheduler-estimator of a cluster." + echo "Usage: hack/deploy-scheduler-estimator " + echo "Example: hack/deploy-scheduler-estimator ~/.kube/karmada.config karmada-host ~/.kube/members.config member1" +} + +if [[ $# -ne 4 ]]; then + usage + exit 1 +fi + +# check kube config file existence +if [[ ! -f "${1}" ]]; then + echo -e "ERROR: failed to get kubernetes config file: '${1}', not existed.\n" + usage + exit 1 +fi +HOST_CLUSTER_KUBECONFIG=$1 + +# check context existence +if ! kubectl config get-contexts "${2}" --kubeconfig="${HOST_CLUSTER_KUBECONFIG}" > /dev/null 2>&1; +then + echo -e "ERROR: failed to get context: '${2}' not in ${HOST_CLUSTER_KUBECONFIG}. \n" + usage + exit 1 +fi +HOST_CLUSTER_NAME=$2 + +# check kube config file existence +if [[ ! -f "${3}" ]]; then + echo -e "ERROR: failed to get kubernetes config file: '${3}', not existed.\n" + usage + exit 1 +fi +MEMBER_CLUSTER_KUBECONFIG=$3 + +# check context existence +if ! kubectl config get-contexts "${4}" --kubeconfig="${MEMBER_CLUSTER_KUBECONFIG}" > /dev/null 2>&1; +then + echo -e "ERROR: failed to get context: '${4}' not in ${MEMBER_CLUSTER_KUBECONFIG}. \n" + usage + exit 1 +fi +MEMBER_CLUSTER_NAME=$4 + +kubectl --kubeconfig="${MEMBER_CLUSTER_KUBECONFIG}" config use-context "${MEMBER_CLUSTER_NAME}" + +# check whether the kubeconfig secret has been created before +if ! kubectl --kubeconfig="${HOST_CLUSTER_KUBECONFIG}" get secrets -n karmada-system | grep "${MEMBER_CLUSTER_NAME}-kubeconfig"; then + # create secret + kubectl --kubeconfig="${HOST_CLUSTER_KUBECONFIG}" --context="${HOST_CLUSTER_NAME}" create secret generic ${MEMBER_CLUSTER_NAME}-kubeconfig --from-file=${MEMBER_CLUSTER_NAME}-kubeconfig="${MEMBER_CLUSTER_KUBECONFIG}" -n "karmada-system" +fi + +# deploy karmada agent +TEMP_PATH=$(mktemp -d) +cp "${REPO_ROOT}"/artifacts/deploy/karmada-scheduler-estimator.yaml "${TEMP_PATH}"/karmada-scheduler-estimator.yaml +sed -i'' -e "s/{{member_cluster_name}}/${MEMBER_CLUSTER_NAME}/g" "${TEMP_PATH}"/karmada-scheduler-estimator.yaml +echo -e "Apply dynamic rendered deployment in ${TEMP_PATH}/karmada-scheduler-estimator.yaml\n" +kubectl --kubeconfig="${HOST_CLUSTER_KUBECONFIG}" --context="${HOST_CLUSTER_NAME}" apply -f "${TEMP_PATH}"/karmada-scheduler-estimator.yaml +rm -rf "${TEMP_PATH}" + +function print_success() { + echo -e "\nKarmada scheduler estimator of cluster ${MEMBER_CLUSTER_NAME} has been deployed." + echo "Note: To enable scheduler estimator, please deploy other scheduler estimators of all clusters." + echo " After that, specify the option '--enable-scheduler-estimator=true' of karmada-scheduler." +} + +print_success diff --git a/hack/local-up-karmada.sh b/hack/local-up-karmada.sh index cfd9e5e61..0fd639e1b 100755 --- a/hack/local-up-karmada.sh +++ b/hack/local-up-karmada.sh @@ -93,6 +93,7 @@ export REGISTRY="swr.ap-southeast-1.myhuaweicloud.com/karmada" kind load docker-image "${REGISTRY}/karmada-controller-manager:${VERSION}" --name="${HOST_CLUSTER_NAME}" kind load docker-image "${REGISTRY}/karmada-scheduler:${VERSION}" --name="${HOST_CLUSTER_NAME}" kind load docker-image "${REGISTRY}/karmada-webhook:${VERSION}" --name="${HOST_CLUSTER_NAME}" +kind load docker-image "${REGISTRY}/karmada-scheduler-estimator:${VERSION}" --name="${HOST_CLUSTER_NAME}" #step5. install karmada control plane components "${REPO_ROOT}"/hack/deploy-karmada.sh "${MAIN_KUBECONFIG}" "${HOST_CLUSTER_NAME}"