diff --git a/docs/installation/fromsource.md b/docs/installation/fromsource.md index 95a9f880b..52219d1ea 100644 --- a/docs/installation/fromsource.md +++ b/docs/installation/fromsource.md @@ -19,24 +19,21 @@ your clusters based on the codebase. The `hack/remote-up-karmada.sh` will install `karmada-apiserver` and provide two ways to expose the server: -### 1. expose by service with `LoadBalancer` type +### 1. expose by `HostNetwork` type -By default, the `hack/remote-up-karmada.sh` will expose `karmada-apiserver` by a service with `LoadBalancer` -type, and continue the installation progress after the `Load Balancer` allocates an external IP for the -`karmada-apiserver`. +By default, the `hack/remote-up-karmada.sh` will expose `karmada-apiserver` by `HostNetwork`. -No extra operations needed with this type, but that *requires your cluster have deployed the `Load Balancer`*. +No extra operations needed with this type. -### 2. expose by service with `ClusterIP` type -If you don't want to use the `Load Balancer`, you can ask `hack/remote-up-karmada.sh` to expose `karmada-apiserver` -by a service with `ClusterIP` type. All you need to do is set an environment: +### 2. expose by service with `LoadBalancer` type + +If you don't want to use the `HostNetwork`, you can ask `hack/remote-up-karmada.sh` to expose `karmada-apiserver` +by a service with `LoadBalancer` type that *requires your cluster have deployed the `Load Balancer`*. +All you need to do is set an environment: ```bash -export CLUSTER_IP_ONLY=true +export LOAD_BALANCER=true ``` -> Note: You should run `hack/remote-up-karmada.sh` on one of the nodes of the cluster, otherwise the `hack/remote-up-karmada.sh` -> can't access the `karmada-apiserver` exposed by a `cluster IP`. - ## Install From the `root` directory the `karmada` repo, install Karmada by command: ```bash diff --git a/hack/README.md b/hack/README.md index 19b432905..559cff3f2 100644 --- a/hack/README.md +++ b/hack/README.md @@ -14,7 +14,7 @@ ensures development quality. - [`remote-up-karmada.sh`](remote-up-karmada.sh) This script will install Karmada to a standalone K8s cluster, this cluster may be real, remote , and even for production. It is worth noting for the connectivity from your client to Karmada API server, - it will create a load balancer service with an external IP by default, else type `export CLUSTER_IP_ONLY=true` with the `ClusterIP` type service before the following script. + it will directly use host network by default, else `export LOAD_BALANCER=true` with the `LoadBalancer` type service before the following script. If your want to customize a load balancer service, you may add the annotations at the metadata part of service `karmada-apiserver` in [`../artifacts/deploy/karmada-apiserver.yaml`](../artifacts/deploy/karmada-apiserver.yaml) before the installing. The following is an example. diff --git a/hack/deploy-karmada-agent.sh b/hack/deploy-karmada-agent.sh index 485e5df26..bdf6db0b8 100755 --- a/hack/deploy-karmada-agent.sh +++ b/hack/deploy-karmada-agent.sh @@ -8,7 +8,7 @@ REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. function usage() { echo "This script will deploy karmada agent to a cluster." echo "Usage: hack/deploy-karmada-agent.sh " - echo "Example: hack/deploy-karmada-agent.sh ~/.kube/karmada.config karmada-apiserver ~/.kube/karmada.config member1" + echo "Example: hack/deploy-karmada-agent.sh ~/.kube/karmada.config karmada-apiserver ~/.kube/members.config member1" } if [[ $# -ne 4 ]]; then diff --git a/hack/deploy-karmada.sh b/hack/deploy-karmada.sh index d0107ad8a..344183d04 100755 --- a/hack/deploy-karmada.sh +++ b/hack/deploy-karmada.sh @@ -16,7 +16,7 @@ KARMADA_APISERVER_SECURE_PORT=${KARMADA_APISERVER_SECURE_PORT:-5443} HOST_CLUSTER_NAME=${HOST_CLUSTER_NAME:-"karmada-host"} ROOT_CA_FILE=${CERT_DIR}/server-ca.crt CFSSL_VERSION="v1.5.0" -CLUSTER_IP_ONLY=${CLUSTER_IP_ONLY:-false} # whether create a 'ClusterIP' type service for karmada apiserver +LOAD_BALANCER=${LOAD_BALANCER:-false} # whether create a 'LoadBalancer' type service for karmada apiserver source "${REPO_ROOT}"/hack/util.sh function usage() { @@ -145,15 +145,15 @@ util::wait_pod_ready "${ETCD_POD_LABEL}" "${KARMADA_SYSTEM_NAMESPACE}" #KARMADA_APISERVER_SERVICE_TYPE is the service type of karmada API Server, For connectivity, it will be different when # HOST_CLUSTER_TYPE is different. When HOST_CLUSTER_TYPE=local, we will create a ClusterIP type Service. And when -# HOST_CLUSTER_TYPE=remote, we need to create a LoadBalancer service to access Karmada API Server outside the -# karmada-host cluster. Of course, you can still use a ClusterIP type Service by setting $CLUSTER_IP_ONLY=true +# HOST_CLUSTER_TYPE=remote, we directly use hostNetwork to access Karmada API Server outside the +# karmada-host cluster. Of course, you can create a LoadBalancer service by setting $LOAD_BALANCER=true KARMADA_APISERVER_SERVICE_TYPE="ClusterIP" if [ "${HOST_CLUSTER_TYPE}" = "local" ]; then # local mode KARMADA_APISERVER_IP=$(util::get_apiserver_ip_from_kubeconfig "${HOST_CLUSTER_NAME}") else # remote mode # KARMADA_APISERVER_IP will be got when Karmada API Server is ready - if [ "${CLUSTER_IP_ONLY}" = false ]; then + if [ "${LOAD_BALANCER}" = true ]; then KARMADA_APISERVER_SERVICE_TYPE="LoadBalancer" fi HOST_CLUSTER_TYPE="remote" # make sure HOST_CLUSTER_TYPE is in local and remote @@ -173,7 +173,7 @@ util::wait_pod_ready "${APISERVER_POD_LABEL}" "${KARMADA_SYSTEM_NAMESPACE}" if [ "${HOST_CLUSTER_TYPE}" = "remote" ]; then case $KARMADA_APISERVER_SERVICE_TYPE in ClusterIP) - KARMADA_APISERVER_IP=$(kubectl get service karmada-apiserver -n "${KARMADA_SYSTEM_NAMESPACE}" -o=jsonpath='{.spec.clusterIP}') + KARMADA_APISERVER_IP=$(kubectl get pod -l app=karmada-apiserver -n "${KARMADA_SYSTEM_NAMESPACE}" -o=jsonpath='{.items[0].status.podIP}') ;; LoadBalancer) if util::wait_service_external_ip "karmada-apiserver" "${KARMADA_SYSTEM_NAMESPACE}"; then diff --git a/hack/remote-up-karmada.sh b/hack/remote-up-karmada.sh index 8eacb80cd..2f7681d5a 100755 --- a/hack/remote-up-karmada.sh +++ b/hack/remote-up-karmada.sh @@ -6,13 +6,13 @@ set -o pipefail function usage() { echo "This script will deploy karmada control plane to a given cluster." - echo "Usage: hack/remote-up-karmada.sh [CLUSTER_IP_ONLY]" + echo "Usage: hack/remote-up-karmada.sh [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 "\tCLUSTER_IP_ONLY\tThis option default is 'false', and there will create a 'LoadBalancer' type service - \t\t\tfor karmada apiserver so that it can easy communicate outside the karmada-host cluster, - \t\t\tif you want only a 'ClusterIP' type service for karmada apiserver, set as 'true'." + 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 @@ -39,8 +39,8 @@ then fi if [ "${3:-false}" = true ]; then - CLUSTER_IP_ONLY=true - export CLUSTER_IP_ONLY + LOAD_BALANCER=true + export LOAD_BALANCER fi # deploy karmada control plane diff --git a/hack/undeploy-karmada.sh b/hack/undeploy-karmada.sh index 63402dcdf..874feb60a 100755 --- a/hack/undeploy-karmada.sh +++ b/hack/undeploy-karmada.sh @@ -4,32 +4,38 @@ set -o errexit set -o nounset set -o pipefail +SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. + function usage() { echo "This script will remove karmada control plane from a cluster." echo "Usage: hack/undeploy-karmada.sh [KUBECONFIG] [CONTEXT_NAME]" echo "Example: hack/undeploy-karmada.sh ~/.kube/karmada.config karmada-host" } -SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +if [[ $# -ne 2 ]]; 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 use-context "${2}" --kubeconfig="${HOST_CLUSTER_KUBECONFIG}" > /dev/null 2>&1; +then + echo -e "ERROR: failed to use context: '${2}' not in ${HOST_CLUSTER_KUBECONFIG}. \n" + usage + exit 1 +fi +HOST_CLUSTER_NAME=$2 + # delete all keys and certificates rm -fr "${HOME}/.karmada" -# set default host cluster's kubeconfig file (created by kind) -KUBECONFIG_PATH=${KUBECONFIG_PATH:-"${HOME}/.kube"} -HOST_CLUSTER_KUBECONFIG="${KUBECONFIG_PATH}/karmada.config" -HOST_CLUSTER_NAME=${HOST_CLUSTER_NAME:-"karmada-host"} - -# if provider the custom kubeconfig and context name -if [[ -f "${1:-}" ]]; then - if ! kubectl config get-contexts "${2:-}" --kubeconfig="${1}" > /dev/null 2>&1; - then - echo -e "ERROR: failed to get context: '${2:-}' not in ${1}. \n" - usage - exit 1 - else - HOST_CLUSTER_KUBECONFIG=${1:-} - HOST_CLUSTER_NAME=${2:-} - fi -fi kubectl config use-context "${HOST_CLUSTER_NAME}" --kubeconfig="${HOST_CLUSTER_KUBECONFIG}"