Skip to content

Commit d06c400

Browse files
authored
Kubernetes: refactor local cluster deployment (#1153)
* Kubernetes: refactor local cluster deployment Changes * Use calico CNI for networking as we use it in master deployments * Move local-reated targets to a seperate Makefile (keep clean main Makefile used in master/stag/prod) * Add delete (local) cluster target * Use newer version * Update install calico link * Report progress on waiting for calico to start
1 parent f4e0ba2 commit d06c400

File tree

5 files changed

+58
-30
lines changed

5 files changed

+58
-30
lines changed

charts/Makefile

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# to be executed on kubernetes control nodes
12
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
23

34
include ${REPO_BASE_DIR}/scripts/common.Makefile
@@ -23,40 +24,16 @@ helmfile-lint: .check-helmfile-installed helmfile.yaml ## Lints the helmfile
2324
set -a; source $(REPO_CONFIG_LOCATION); set +a; \
2425
helmfile lint
2526

26-
.PHONY: .helmfile-local-post-install
27-
.helmfile-local-post-install: ## Post install steps for local helmfile deployment
28-
@$(MAKE) -s configure-local-hosts
29-
@echo "";
30-
@echo "Cluster has been deployed locally: https://$(MACHINE_FQDN)";
31-
@echo " For secure connections self-signed certificates are used.";
32-
@echo "";
33-
3427
.PHONY: helmfile-apply
3528
helmfile-apply: .check-helmfile-installed helmfile.yaml ## Applies the helmfile configuration
3629
set -a; source $(REPO_CONFIG_LOCATION); set +a; \
3730
helmfile -f $(REPO_BASE_DIR)/charts/helmfile.yaml apply
3831

39-
@if [ "$(MACHINE_FQDN)" = "osparc.local" ]; then \
40-
$(MAKE) -s .helmfile-local-post-install; \
41-
fi
42-
4332
.PHONY: helmfile-sync
4433
helmfile-sync: .check-helmfile-installed helmfile.yaml ## Syncs the helmfile configuration (use `helmfile-apply` to deploy the app)
4534
set -a; source $(REPO_CONFIG_LOCATION); set +a; \
4635
helmfile -f $(REPO_BASE_DIR)/charts/helmfile.yaml sync
4736

48-
@if [ "$(MACHINE_FQDN)" = "osparc.local" ]; then \
49-
$(MAKE) -s .helmfile-local-post-install; \
50-
fi
51-
52-
.PHONY: configure-local-hosts
53-
configure-local-hosts: $(REPO_CONFIG_LOCATION) ## Adds local hosts entries for the machine
54-
# "Updating /etc/hosts with k8s $(MACHINE_FQDN) hosts ..."
55-
@set -a; source $(REPO_CONFIG_LOCATION); set +a; \
56-
grep -q "127.0.0.1 $$K8S_MONITORING_FQDN" /etc/hosts || echo "127.0.0.1 $$K8S_MONITORING_FQDN" | sudo tee -a /etc/hosts
57-
@set -a; source $(REPO_CONFIG_LOCATION); set +a; \
58-
grep -q "127.0.0.1 $$K8S_PRIVATE_FQDN" /etc/hosts || echo "127.0.0.1 $$K8S_PRIVATE_FQDN" | sudo tee -a /etc/hosts
59-
6037
.PHONY: helmfile-diff
6138
helmfile-diff: .check-helmfile-installed helmfile.yaml ## Shows the differences that would be applied by helmfile
6239
@set -a; source $(REPO_CONFIG_LOCATION); set +a; \

charts/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,4 @@ helmfile init
4545

4646
## Running k8s cluster locally
4747

48-
```bash
49-
cd ./osparc-ops-environments
50-
./scripts/create_local_k8s_cluster.bash
51-
```
48+
Use `./local-k8s.Makefile` targets

charts/local-k8s.Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
2+
K8S_CLUSTER_NAME := osparc-cluster
3+
# Determine this makefile's path.
4+
# Be sure to place this BEFORE `include` directives, if any.
5+
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
6+
7+
include ${REPO_BASE_DIR}/scripts/common.Makefile
8+
include $(REPO_CONFIG_LOCATION)
9+
10+
create-cluster: ## Creates a local Kubernetes cluster
11+
@$(REPO_BASE_DIR)/scripts/create_local_k8s_cluster.bash $(K8S_CLUSTER_NAME)
12+
@$(MAKE) --no-print-directory --file $(THIS_MAKEFILE) configure-local-hosts
13+
@echo "";
14+
@echo "Cluster has been deployed locally: https://$(MACHINE_FQDN)";
15+
@echo " For secure connections self-signed certificates are used.";
16+
@echo "";
17+
18+
delete-cluster: ## Deletes the local Kubernetes cluster
19+
@kind delete cluster --name $(K8S_CLUSTER_NAME)
20+
@echo "Local Kubernetes cluster $(K8S_CLUSTER_NAME) has been deleted."
21+
22+
.PHONY: configure-local-hosts
23+
configure-local-hosts: $(REPO_CONFIG_LOCATION) ## Adds local hosts entries for the machine
24+
# "Updating /etc/hosts with k8s $(MACHINE_FQDN) hosts ..."
25+
@set -a; source $(REPO_CONFIG_LOCATION); set +a; \
26+
grep -q "127.0.0.1 $$K8S_MONITORING_FQDN" /etc/hosts || echo "127.0.0.1 $$K8S_MONITORING_FQDN" | sudo tee -a /etc/hosts
27+
@set -a; source $(REPO_CONFIG_LOCATION); set +a; \
28+
grep -q "127.0.0.1 $$K8S_PRIVATE_FQDN" /etc/hosts || echo "127.0.0.1 $$K8S_PRIVATE_FQDN" | sudo tee -a /etc/hosts

scripts/create_local_k8s_cluster.bash

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -o pipefail
66

77
THIS_SCRIPT_DIR=$(dirname "$0")
88
KIND_CONFIG_FILE="$THIS_SCRIPT_DIR/kind_config.yaml"
9-
KIND_CLUSTER_NAME="kind"
9+
KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-osparc-cluster}"
1010

1111
if ! command -v kind &> /dev/null; then
1212
echo "Error: kind is not installed. Please install kind and try again."
@@ -19,7 +19,7 @@ if ! command -v kubectl &> /dev/null; then
1919
fi
2020

2121
if kind get clusters | grep -q "^$KIND_CLUSTER_NAME$"; then
22-
echo "A cluster is already up."
22+
echo "A cluster '$KIND_CLUSTER_NAME' is already up."
2323
exit 0
2424
fi
2525

@@ -28,5 +28,25 @@ if [[ ! -f "$KIND_CONFIG_FILE" ]]; then
2828
exit 1
2929
fi
3030

31+
#
3132
# create a k8s cluster
33+
#
34+
35+
echo "Creating a local Kubernetes cluster named '$KIND_CLUSTER_NAME' using configuration from '$KIND_CONFIG_FILE'..."
36+
3237
kind create cluster --config "$KIND_CONFIG_FILE" --name "$KIND_CLUSTER_NAME"
38+
39+
#
40+
# install Calico network CNI
41+
#
42+
43+
# https://docs.tigera.io/calico/3.30/getting-started/kubernetes/kind
44+
45+
echo "Installing Calico network CNI ..."
46+
47+
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.30.2/manifests/operator-crds.yaml
48+
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.30.2/manifests/tigera-operator.yaml
49+
50+
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.30.2/manifests/custom-resources.yaml
51+
52+
while ! kubectl get pods -A -l k8s-app=calico-node 2>/dev/null | grep -q "Running"; do echo "Waiting for Calico pods to start..."; sleep 1; done

scripts/kind_config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ nodes:
1313
labels:
1414
ops: "true"
1515
simcore: "true"
16+
17+
# https://archive-os-3-26.netlify.app/calico/3.26/getting-started/kubernetes/kind/
18+
networking:
19+
disableDefaultCNI: true
20+
# must match with cidr in https://raw.githubusercontent.com/projectcalico/calico/v3.26.4/manifests/custom-resources.yaml
21+
podSubnet: 192.168.0.0/16

0 commit comments

Comments
 (0)