From e33b8c7ad55b22ff00f07ca8bf33e19335ec6038 Mon Sep 17 00:00:00 2001 From: Piotr Date: Mon, 19 Oct 2020 13:57:15 +0200 Subject: [PATCH] Refactoring (#28) * Scripts refactoring * Update Readme --- ...ctor-e2e.yml => app-connector-e2e-k3s.yml} | 21 +----------- ...ube.yml => app-connector-e2e-minikube.yml} | 10 +----- README.md | 32 ++++++++++++++----- create-cluster.sh => create-cluster-k3d.sh | 7 ++-- create-cluster-k3s.sh | 18 +++++++++++ create-cluster-kind.sh | 6 ++-- create-cluster-minikube.sh | 14 ++++++++ install-istio.sh | 3 ++ install-kyma.sh | 9 ++++++ kyma-k3d.sh | 7 ++-- kyma-kind.sh | 2 +- kyma-minikube-cleanup.sh | 5 +++ kyma-minikube.sh | 8 +++++ 13 files changed, 95 insertions(+), 47 deletions(-) rename .github/workflows/{app-connector-e2e.yml => app-connector-e2e-k3s.yml} (62%) rename .github/workflows/{e2e-minikube.yml => app-connector-e2e-minikube.yml} (77%) rename create-cluster.sh => create-cluster-k3d.sh (84%) create mode 100755 create-cluster-k3s.sh create mode 100755 create-cluster-minikube.sh create mode 100755 kyma-minikube-cleanup.sh create mode 100755 kyma-minikube.sh diff --git a/.github/workflows/app-connector-e2e.yml b/.github/workflows/app-connector-e2e-k3s.yml similarity index 62% rename from .github/workflows/app-connector-e2e.yml rename to .github/workflows/app-connector-e2e-k3s.yml index 1de9cf8..4246f6e 100644 --- a/.github/workflows/app-connector-e2e.yml +++ b/.github/workflows/app-connector-e2e-k3s.yml @@ -15,26 +15,7 @@ jobs: - uses: actions/checkout@v2 - name: Prepare docker registry, k3s and helm 3 run: | - mkdir -p ~/.kube - if [[ -f ./kubeconfig ]]; - then - echo "use existing kubeconfig" - cp ./kubeconfig ~/.kube/config - else - echo "starting docker registry" - sudo mkdir -p /etc/rancher/k3s - sudo cp registries.yaml /etc/rancher/k3s - docker run -d \ - -p 5000:5000 \ - --restart=always \ - --name registry.localhost \ - -v $PWD/registry:/var/lib/registry \ - registry:2 - echo "starting cluster" - curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE=777 INSTALL_K3S_EXEC="server --disable traefik" sh - - cp /etc/rancher/k3s/k3s.yaml ~/.kube/config - chmod 600 ~/.kube/config - fi + ./create-cluster-k3s.sh echo "Installing helm" curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash while [[ $(kubectl get nodes -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "Waiting for cluster nodes to be ready"; sleep 2; done diff --git a/.github/workflows/e2e-minikube.yml b/.github/workflows/app-connector-e2e-minikube.yml similarity index 77% rename from .github/workflows/e2e-minikube.yml rename to .github/workflows/app-connector-e2e-minikube.yml index af68516..72ba1a0 100644 --- a/.github/workflows/e2e-minikube.yml +++ b/.github/workflows/app-connector-e2e-minikube.yml @@ -17,15 +17,7 @@ jobs: run: | curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube - docker run -d \ - -p 5000:5000 \ - --restart=always \ - --name registry.localhost \ - -v $PWD/registry:/var/lib/registry \ - registry:2 - echo "starting cluster" - minikube start --memory=6800m --kubernetes-version=1.18.9 --insecure-registry="registry.localhost:5000" - minikube ssh "sudo sh -c \"grep host.minikube.internal /etc/hosts | sed s/host.minikube.internal/registry.localhost/ >>/etc/hosts\"" + ./create-cluster-minikube.sh echo "Installing helm" curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash while [[ $(kubectl get nodes -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "Waiting for cluster nodes to be ready"; sleep 2; done diff --git a/README.md b/README.md index 9685615..21a6735 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ ![Tests on k3s](https://github.com/kyma-incubator/local-kyma-k3d/workflows/Tests%20on%20k3s/badge.svg) ![Tests on minikube](https://github.com/kyma-incubator/local-kyma-k3d/workflows/Tests%20on%20minikube/badge.svg) ![Tests on kind](https://github.com/kyma-incubator/local-kyma-k3d/workflows/Tests%20on%20kind/badge.svg) # Overview -This repository contains scripts to start Kyma on local K3S cluster in about 5 minutes! +This repository contains scripts to start Kyma on local kubernetes cluster (k3s) in about 5 minutes! > Tested on Mac Book Pro 2017 (2,9 GHz Quad-Core Intel Core i7, 16 GB RAM, SSD disk) - # Prerequisites - [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) - [helm 3](https://helm.sh/docs/intro/quickstart/#install-helm) @@ -15,8 +14,8 @@ This repository contains scripts to start Kyma on local K3S cluster in about 5 m Checkout this repository and go to the main folder: ``` -git clone git@github.com:kyma-incubator/local-kyma-k3d.git -cd local-kyma-k3d +git clone git@github.com:kyma-incubator/local-kyma.git +cd local-kyma ``` Download kyma charts to resources subfolder: @@ -40,7 +39,7 @@ Your cluster is ready! ![asciicast](local-kyma-k3d.gif) -# Clean up +When you are done you can clean up with this command: ``` ./kyma-k3d-delete.sh @@ -108,12 +107,29 @@ Please bear in mind that after restart Kubernetes will probably restart most of ## Can I use the script on Linux or Windows -The script was tested only on Mac OS. It should not be a big problem to adapt it to Linux, but it wasn't tested there. There is a plan to move the script to Kyma CLI - once it is done all platforms will be supported. +The script was tested only on Mac OS and Linux (ubuntu). Please be aware that for Linux you should use k3s (not k3d) version of create cluster script. It should also work with Windows Linux Subsystem (WSL 2), but I didn't test it yet. --- -## Why not minikube? +## I see k3s, k3d, kind and minikube - what should I use? + +Short answer: k3d (Mac Os) or k3s (Linux, WSL). + +Long answer: + +K3d is a docker wrapper around k3s (which runs on linux only) - it is more or less the same. Here is a small comparison with kind and minikube: + +| | k3s/k3d | minikube | kind | +----|:-------:|:--------:|:----:| +K8s installation + startup time | ~ 25 sec | ~ 90 sec | ~ 100 sec +Cluster startup time (second run) | ~ 15 sec | ~ 30 sec | ~ 30 sec +Allocated memory (e2e scenario) | 4.2 GB | 6.6 GB | 6.8 GB +Kyma installation time | ~ 3 min | ~ 5-6 min | ~ 4-5 min +LoadBalancer support | yes | yes/no (requires another process for minikube tunnel command) | no +Expose LB ports on host machine (use localhost) | yes | yes(mac) / no(linux) | yes/no (extraPortMappings to service exposed with NodePort) + +Summary: if you pick minikube or kind you need 50% more resources, 50% more time for cluster startup or Kyma installation and you need a special configuration or process to access ingress gateway from your localhost. -K3S starts in about 10 seconds - you can use kubeconfig and access API server. It also takes fewer resources than minikube. For the local development, speed and low resource consumption are critical requirements. +**A winner is: k3s/k3d!** --- ## What are the hardware requirements to run Kyma locally? diff --git a/create-cluster.sh b/create-cluster-k3d.sh similarity index 84% rename from create-cluster.sh rename to create-cluster-k3d.sh index a937e3a..46cb8ab 100755 --- a/create-cluster.sh +++ b/create-cluster-k3d.sh @@ -1,8 +1,11 @@ +#!/bin/bash +set -o errexit + SECONDS=0 REGISTRY_CONFIG=${1:-registries.yaml} # Create docker network -docker network create k3d-kyma +docker network create k3d-kyma || echo "k3d-kyma network already exists" # Start docker Registry docker run -d \ @@ -25,6 +28,4 @@ k3d cluster create kyma \ --switch-context \ --timeout 60s -# Delete cluster with keep-registry-volume to cache docker images -# k3d cluster delete kyma echo "Cluster created in $(( $SECONDS/60 )) min $(( $SECONDS % 60 )) sec" \ No newline at end of file diff --git a/create-cluster-k3s.sh b/create-cluster-k3s.sh new file mode 100755 index 0000000..8dc1b54 --- /dev/null +++ b/create-cluster-k3s.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -o errexit + +echo "starting docker registry" +sudo mkdir -p /etc/rancher/k3s +sudo cp registries.yaml /etc/rancher/k3s +docker run -d \ +-p 5000:5000 \ +--restart=always \ +--name registry.localhost \ +-v $PWD/registry:/var/lib/registry \ +registry:2 + +echo "starting cluster" +curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE=777 INSTALL_K3S_EXEC="server --disable traefik" sh - +mkdir -p ~/.kube +cp /etc/rancher/k3s/k3s.yaml ~/.kube/config +chmod 600 ~/.kube/config diff --git a/create-cluster-kind.sh b/create-cluster-kind.sh index da4713f..27e2d92 100755 --- a/create-cluster-kind.sh +++ b/create-cluster-kind.sh @@ -1,8 +1,6 @@ -#!/bin/sh +#!/bin/bash set -o errexit - - # create a cluster with the local registry enabled in containerd cat <>/etc/hosts\"" \ No newline at end of file diff --git a/install-istio.sh b/install-istio.sh index ce2bf29..13d8924 100755 --- a/install-istio.sh +++ b/install-istio.sh @@ -1,3 +1,6 @@ +#!/bin/bash +set -e + # Instal istio if [[ ! -f istio-1.5.10/bin/istioctl ]]; then curl -sL https://istio.io/downloadIstio | ISTIO_VERSION=1.5.10 sh - diff --git a/install-kyma.sh b/install-kyma.sh index 94491b5..f32ed7c 100755 --- a/install-kyma.sh +++ b/install-kyma.sh @@ -1,3 +1,6 @@ +#!/bin/bash +set -o errexit + SECONDS=0 export DOMAIN=local.kyma.dev export OVERRIDES=global.isLocalEnv=false,global.ingress.domainName=$DOMAIN,global.environment.gardener=false,global.domainName=$DOMAIN,global.tlsCrt=ZHVtbXkK @@ -31,9 +34,13 @@ function helm_install() { break fi echo "Installing $1 in the namespace $namespace" + set +e helm upgrade --wait -i $release $chart -n $namespace "${@:4}" + set -e done } + +set +e # This file will be created by cert-manager (not needed anymore): rm resources/core/charts/gateway/templates/kyma-gateway-certs.yaml @@ -41,6 +48,8 @@ rm resources/core/charts/gateway/templates/kyma-gateway-certs.yaml rm resources/apiserver-proxy/requirements.yaml rm -R resources/apiserver-proxy/charts +set -e + # Create namespaces cat <