Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize installation #363

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 56 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,52 +117,92 @@ There are several demonstrations of common cases.
```

#### 3. Deploy and run karmada control plane:

Choose a way:

##### 3.1. I have not any cluster

run the following script: (It will create a host cluster by kind)

```
# hack/local-up-karmada.sh
```

The script `hack/local-up-karmada.sh` will do following tasks for you:
- Start a Kubernetes cluster to run the karmada control plane, aka. the `host cluster`.
- Build karmada control plane components based on current codebase.
- Build karmada control plane components based on a current codebase.
- Deploy karmada control plane components on `host cluster`.

If everything goes well, at the end of the script output, you will see similar messages as follows:
```
Local Karmada is running.
To start using your karmada, run:
export KUBECONFIG=/var/run/karmada/karmada-apiserver.config
To start checking karmada components running status on the host cluster, please run:
export KUBECONFIG="/root/.kube/karmada-host.config"

Kubeconfig for karmada in file: /root/.kube/karmada.config, so you can run:
export KUBECONFIG="/root/.kube/karmada.config"
Or use kubectl with --kubeconfig=/root/.kube/karmada.config
Please use 'kubectl config use-context <Context_Name>' to switch cluster to operate,
the following is context intro:
------------------------------------------------------
| Context Name | Purpose |
|----------------------------------------------------|
| karmada-host | the cluster karmada install in |
|----------------------------------------------------|
| karmada-apiserver | karmada control plane |
------------------------------------------------------
```

The two `KUBECONFIG` files after the script run are:
- karmada-apiserver.config
- karmada-host.config
There are two contexts you can switch after the script run are:
- karmada-apiserver `kubectl config use-context karmada-apiserver`
- karmada-host `kubectl config use-context karmada-host`

The `karmada-apiserver.config` is the **main kubeconfig** to be used when interacting with karamda control plane, while `karmada-host.config` is only used for debuging karmada installation with host cluster.
The `karmada-apiserver` is the **main kubeconfig** to be used when interacting with karamda control plane, while `karmada-host` is only used for debugging karmada installation with host cluster, you can check all clusters at any time by run: `kubectl config view` and switch by `kubectl config use-context [CONTEXT_NAME]`

##### 3.2. I have present cluster for installing
Before run the following script, please make sure you are in the node or master of the cluster to install:
```
# hack/remote-up-karmada.sh <kubeconfig> <context_name>
```
`kubeconfig` is your cluster's kubeconfig that you want to install to

`context_name` is the name of context in 'kubeconfig'

If everything goes well, at the end of the script output, you will see similar messages as follows:
```
Karmada is installed.

Kubeconfig for karmada in file: /root/.kube/karmada.config, so you can run:
export KUBECONFIG="/root/.kube/karmada.config"
Or use kubectl with --kubeconfig=/root/.kube/karmada.config
Please use 'kubectl config use-context karmada-apiserver' to switch the cluster of karmada control plane
And use 'kubectl config use-context your-host' for debugging karmada installation
```
#### Tips
- Please make sure you can access google cloud registry: k8s.gcr.io
- Install script will download golang package, if your server is in the mainland, you need set go proxy like this `export GOPROXY=https://goproxy.cn`

### Join member cluster
In the following steps, we are going to create a member cluster and then join the cluster to
karmada control plane.

#### 1. Create member cluster
We are going to create a cluster named `member1` and we want the `KUBECONFIG` file
in `$HOME/.kube/member1.config`. Run following command:
in `/root/.kube/karmada.config`. Run following command:
```
# hack/create-cluster.sh member1 $HOME/.kube/member1.config
# hack/create-cluster.sh member1 /${HOME}/.kube/karmada.config
```
The script `hack/create-cluster.sh` will create a standalone cluster.
The script `hack/create-cluster.sh` will create a standalone cluster by kind.

#### 2. Join member cluster to karmada control plane
The command `karmadactl` will help to join the member cluster to karmada control plane,
before that, we should set `KUBECONFIG` to karmada apiserver:
before that, we should switch to karmada apiserver:
```
# export KUBECONFIG=/var/run/karmada/karmada-apiserver.config
# kubectl config use-context karmada-apiserver
```

Then, install `karmadactl` command and join the member cluster:
```
# go get github.com/karmada-io/karmada/cmd/karmadactl
# karmadactl join member1 --cluster-kubeconfig=$HOME/.kube/member1.config
# karmadactl join member1 --cluster-kubeconfig=/root/.kube/karmada.config
```
The `karmadactl join` command will create a `Cluster` object to reflect the member cluster.

Expand Down Expand Up @@ -222,4 +262,4 @@ details on submitting patches and the contribution workflow.

## License

Karmada is under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details.
Karmada is under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details.
3 changes: 1 addition & 2 deletions artifacts/deploy/karmada-apiserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ spec:
- --etcd-certfile=/etc/kubernetes/pki/karmada.crt
- --etcd-keyfile=/etc/kubernetes/pki/karmada.key
- --etcd-servers=https://etcd-client.karmada-system.svc.cluster.local:2379
- --bind-address=0.0.0.0
- --insecure-port=8080
- --kubelet-client-certificate=/etc/kubernetes/pki/karmada.crt
- --kubelet-client-key=/etc/kubernetes/pki/karmada.key
Expand All @@ -64,7 +65,6 @@ spec:
livenessProbe:
failureThreshold: 8
httpGet:
host: {{api_addr}}
path: /livez
port: 5443
scheme: HTTPS
Expand All @@ -75,7 +75,6 @@ spec:
readinessProbe:
failureThreshold: 3
httpGet:
host: {{api_addr}}
path: /readyz
port: 5443
scheme: HTTPS
Expand Down
29 changes: 23 additions & 6 deletions hack/create-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,46 @@ set -o pipefail

function usage() {
echo "This script starts a kube cluster by kind."
echo "Usage: hack/create-cluster.sh <CLUSTER_NAME> <KUBECONFIG>"
echo "Example: hack/create-cluster.sh host /root/.kube/host.config"
echo "Usage: hack/create-cluster.sh <CLUSTER_NAME> [KUBECONFIG]"
echo "Example: hack/create-cluster.sh host /root/.kube/karmada.config"
}

if [[ $# -ne 2 ]]; then
if [[ $# -lt 1 ]]; then
usage
exit 1
fi

CLUSTER_NAME=$1

if [[ -z "${CLUSTER_NAME}" ]]; then
usage
exit 1
fi
KUBECONFIG=$2

if [[ -z "${2-}" ]]; then
KUBECONFIG=$KUBECONFIG
else
KUBECONFIG=$2
fi

if [[ -z "${KUBECONFIG}" ]]; then
usage
exit 1
fi

# check kind
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
# shellcheck source=util.sh
source "${REPO_ROOT}"/hack/util.sh
util::cmd_must_exist "kind"

if [ -f "${KUBECONFIG}" ];then
echo "Removing old kubeconfig file."
rm -f ${KUBECONFIG}
echo "kubeconfig file is existed, new config will append to it."
if kubectl config get-contexts "${CLUSTER_NAME}" --kubeconfig="${KUBECONFIG}"> /dev/null 2>&1;
then
echo "ERROR: failed to create new cluster for context '${CLUSTER_NAME}' existed in ${KUBECONFIG}. please remove it (use 'kubectl config delete-context') if your want to recover it."
exit 1
fi
fi

kind create cluster --name "${CLUSTER_NAME}" --kubeconfig="${KUBECONFIG}" --wait=120s
Expand Down
2 changes: 1 addition & 1 deletion hack/delete-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -o pipefail
function usage() {
echo "This script delete a kube cluster by kind."
echo "Usage: hack/delete-cluster.sh <CLUSTER_NAME> <KUBECONFIG>"
echo "Example: hack/delete-cluster.sh host /root/.kube/host.config"
echo "Example: hack/delete-cluster.sh host /root/.kube/karmada.config"
}

if [[ $# -ne 2 ]]; then
Expand Down
Loading