Skip to content

Commit

Permalink
add simple local cluster setup script (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Schrodi authored May 6, 2021
1 parent a1416b1 commit 86bf420
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
13 changes: 8 additions & 5 deletions docs/development/local-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ Further details could be found in

1. [Principles of Kubernetes](https://kubernetes.io/docs/concepts/), and its [components](https://kubernetes.io/docs/concepts/overview/components/)
1. [Kubernetes Development Guide](https://github.com/kubernetes/community/tree/master/contributors/devel)
1. [Architecture of Gardener](https://github.com/gardener/documentation/wiki/Architecture)

This setup is based on [kind](https://github.com/kubernetes-sigs/kind).
Docker for Desktop, [minikube](https://github.com/kubernetes/minikube) or [k3d](https://github.com/rancher/k3d) are also supported.
This setup is based on [k3d](https://github.com/rancher/k3d).
Docker for Desktop, [minikube](https://github.com/kubernetes/minikube) or [kind](https://github.com/kubernetes-sigs/kind) are also supported.

## Installing Golang environment

Expand Down Expand Up @@ -65,11 +64,15 @@ brew install git
On other OS, please check the [Git installation documentation](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).


## Installing Kind
## Installing K3d

You'll need to have [Docker](https://docs.docker.com/get-docker/) installed and running.

Follow the [kind quickstart guide](https://kind.sigs.k8s.io/docs/user/quick-start/) to start a kubernetes cluster .
Follow the [k3s installation guide](https://k3d.io/#installation) to start a kubernetes cluster.

:warning: note that with the default k8s cluster installation some development resources like target may not work as on some os's docker is running in VM with different network access.
We therefore recommend to use our local setup script in [hack/setup-local-env.sh](../../hack/setup-local-env.sh) which automatically setups a local environment.
In that environment controllers running in- and outside of the cluster can access the apiserver. (Note that this script modifies the `/etc/hosts` file which may require root permissions)

## [MacOS only] Install GNU core utilities

Expand Down
7 changes: 7 additions & 0 deletions hack/resources/k3d-cluster-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# k3d configuration file, saved as e.g. /home/me/myk3dcluster.yaml
apiVersion: k3d.io/v1alpha2 # this will change in the future as we make everything more stable
kind: Simple # internally, we also have a Cluster config, which is not yet available externally
kubeAPI: # same as `--api-port myhost.my.domain:6445` (where the name would resolve to 127.0.0.1)
host: "host.k3d.internal" # important for the `server` setting in the kubeconfig
hostIP: "0.0.0.0" # where the Kubernetes API will be listening on
hostPort: "6445" # where the Kubernetes API listening port will be mapped to on your host system
31 changes: 21 additions & 10 deletions hack/setup-local-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@

set -e

CLUSTER_NAME="test"
K3D_INTERNAL_HOST="host.k3d.internal"

CURRENT_DIR=$(dirname $0)
PROJECT_ROOT="${CURRENT_DIR}"/..

if [[ $EFFECTIVE_VERSION == "" ]]; then
EFFECTIVE_VERSION=$(cat $PROJECT_ROOT/VERSION)
echo "Setup local Landscaper development environment"

if ! which k3d 1>/dev/null; then
echo "K3d is not installed, see https://k3d.io/ how to install it..."
exit 1
fi


found_cluster=$(k3d cluster list -o json | jq ".[] | select(.name==\"${CLUSTER_NAME}\").name")
if [[ -z $found_cluster ]]; then
echo "Creating k3d cluster ..."
k3d cluster create $CLUSTER_NAME --config ${CURRENT_DIR}/resources/k3d-cluster-config.yaml
else
echo "k3d cluster ${CLUSTER_NAME} already exists. Skipping..."
fi

echo "> Install $EFFECTIVE_VERSION"
echo "Note: the new cluster context is automatically added to your current scope"

CGO_ENABLED=0 GOOS=$(go env GOOS) GOARCH=$(go env GOARCH) GO111MODULE=on \
go install -mod=vendor \
-ldflags "-X github.com/gardener/landscaper/pkg/version.GitVersion=$EFFECTIVE_VERSION \
-X github.com/gardener/landscaper/pkg/version.gitTreeState=$([ -z git status --porcelain 2>/dev/null ] && echo clean || echo dirty) \
-X github.com/gardener/landscaper/pkg/version.gitCommit=$(git rev-parse --verify HEAD) \
-X github.com/gardener/landscaper/pkg/version.buildDate=$(date --rfc-3339=seconds | sed 's/ /T/')" \
${PROJECT_ROOT}/cmd/...
echo "Adding k3d host entry ..."
echo "# Local k3d cluster" >> /etc/hosts
echo "0.0.0.0 ${K3D_INTERNAL_HOST}" >> /etc/hosts

0 comments on commit 86bf420

Please sign in to comment.