Skip to content
This repository was archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
Refactoring (#28)
Browse files Browse the repository at this point in the history
* Scripts refactoring
* Update Readme
  • Loading branch information
pbochynski authored Oct 19, 2020
1 parent ba6f9d2 commit e33b8c7
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 [email protected]:kyma-incubator/local-kyma-k3d.git
cd local-kyma-k3d
git clone [email protected]:kyma-incubator/local-kyma.git
cd local-kyma
```

Download kyma charts to resources subfolder:
Expand All @@ -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
Expand Down Expand Up @@ -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?
Expand Down
7 changes: 4 additions & 3 deletions create-cluster.sh → create-cluster-k3d.sh
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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"
18 changes: 18 additions & 0 deletions create-cluster-k3s.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 2 additions & 4 deletions create-cluster-kind.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/sh
#!/bin/bash
set -o errexit



# create a cluster with the local registry enabled in containerd
cat <<EOF | kind create cluster --name kyma --config=-
kind: Cluster
Expand Down Expand Up @@ -35,7 +33,7 @@ nodes:
listenAddress: "127.0.0.1"
EOF

# create registry container unless it already exists
# Start docker Registry
docker run -d \
-p 5000:5000 \
--restart=always \
Expand Down
14 changes: 14 additions & 0 deletions create-cluster-minikube.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -o errexit

# Start docker Registry
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\""
3 changes: 3 additions & 0 deletions install-istio.sh
Original file line number Diff line number Diff line change
@@ -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 -
Expand Down
9 changes: 9 additions & 0 deletions install-kyma.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,16 +34,22 @@ 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

# apiserver-proxy dependencies are not required (cannot be disabled by values yet):
rm resources/apiserver-proxy/requirements.yaml
rm -R resources/apiserver-proxy/charts

set -e

# Create namespaces
cat <<EOF | kubectl apply -f -
apiVersion: v1
Expand Down
7 changes: 5 additions & 2 deletions kyma-k3d.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
./create-cluster.sh
./install-istio.sh
#!/bin/bash
set -o errexit

./create-cluster-k3d.sh
./install-istio.sh -f config-istio.yaml
./install-kyma.sh
2 changes: 1 addition & 1 deletion kyma-kind.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
./create-cluster-kind.sh
./install-istio.sh
./install-istio.sh -f config-istio-nodeport.yaml
./install-kyma.sh
5 changes: 5 additions & 0 deletions kyma-minikube-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -o errexit

minikube delete
docker rm -f registry.localhost
8 changes: 8 additions & 0 deletions kyma-minikube.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -o errexit

./create-cluster-minikube.sh
./install-istio.sh -f config-istio.yaml
IP=$(minikube ssh "grep host.minikube.internal /etc/hosts | cut -f1")
export REGISTRY_IP=${IP//[$'\t\r\n ']}
./install-kyma.sh

0 comments on commit e33b8c7

Please sign in to comment.