Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 1 addition & 24 deletions charts/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# to be executed on kubernetes control nodes
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)

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

.PHONY: .helmfile-local-post-install
.helmfile-local-post-install: ## Post install steps for local helmfile deployment
@$(MAKE) -s configure-local-hosts
@echo "";
@echo "Cluster has been deployed locally: https://$(MACHINE_FQDN)";
@echo " For secure connections self-signed certificates are used.";
@echo "";

.PHONY: helmfile-apply
helmfile-apply: .check-helmfile-installed helmfile.yaml ## Applies the helmfile configuration
set -a; source $(REPO_CONFIG_LOCATION); set +a; \
helmfile -f $(REPO_BASE_DIR)/charts/helmfile.yaml apply

@if [ "$(MACHINE_FQDN)" = "osparc.local" ]; then \
$(MAKE) -s .helmfile-local-post-install; \
fi

.PHONY: helmfile-sync
helmfile-sync: .check-helmfile-installed helmfile.yaml ## Syncs the helmfile configuration (use `helmfile-apply` to deploy the app)
set -a; source $(REPO_CONFIG_LOCATION); set +a; \
helmfile -f $(REPO_BASE_DIR)/charts/helmfile.yaml sync

@if [ "$(MACHINE_FQDN)" = "osparc.local" ]; then \
$(MAKE) -s .helmfile-local-post-install; \
fi

.PHONY: configure-local-hosts
configure-local-hosts: $(REPO_CONFIG_LOCATION) ## Adds local hosts entries for the machine
# "Updating /etc/hosts with k8s $(MACHINE_FQDN) hosts ..."
@set -a; source $(REPO_CONFIG_LOCATION); set +a; \
grep -q "127.0.0.1 $$K8S_MONITORING_FQDN" /etc/hosts || echo "127.0.0.1 $$K8S_MONITORING_FQDN" | sudo tee -a /etc/hosts
@set -a; source $(REPO_CONFIG_LOCATION); set +a; \
grep -q "127.0.0.1 $$K8S_PRIVATE_FQDN" /etc/hosts || echo "127.0.0.1 $$K8S_PRIVATE_FQDN" | sudo tee -a /etc/hosts

.PHONY: helmfile-diff
helmfile-diff: .check-helmfile-installed helmfile.yaml ## Shows the differences that would be applied by helmfile
@set -a; source $(REPO_CONFIG_LOCATION); set +a; \
Expand Down
5 changes: 1 addition & 4 deletions charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,4 @@ helmfile init

## Running k8s cluster locally

```bash
cd ./osparc-ops-environments
./scripts/create_local_k8s_cluster.bash
```
Use `./local-k8s.Makefile` targets
28 changes: 28 additions & 0 deletions charts/local-k8s.Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
K8S_CLUSTER_NAME := osparc-cluster
# Determine this makefile's path.
# Be sure to place this BEFORE `include` directives, if any.
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))

include ${REPO_BASE_DIR}/scripts/common.Makefile
include $(REPO_CONFIG_LOCATION)

create-cluster: ## Creates a local Kubernetes cluster
@$(REPO_BASE_DIR)/scripts/create_local_k8s_cluster.bash $(K8S_CLUSTER_NAME)
@$(MAKE) --no-print-directory --file $(THIS_MAKEFILE) configure-local-hosts
@echo "";
@echo "Cluster has been deployed locally: https://$(MACHINE_FQDN)";
@echo " For secure connections self-signed certificates are used.";
@echo "";

delete-cluster: ## Deletes the local Kubernetes cluster
@kind delete cluster --name $(K8S_CLUSTER_NAME)
@echo "Local Kubernetes cluster $(K8S_CLUSTER_NAME) has been deleted."

.PHONY: configure-local-hosts
configure-local-hosts: $(REPO_CONFIG_LOCATION) ## Adds local hosts entries for the machine
# "Updating /etc/hosts with k8s $(MACHINE_FQDN) hosts ..."
@set -a; source $(REPO_CONFIG_LOCATION); set +a; \
grep -q "127.0.0.1 $$K8S_MONITORING_FQDN" /etc/hosts || echo "127.0.0.1 $$K8S_MONITORING_FQDN" | sudo tee -a /etc/hosts
@set -a; source $(REPO_CONFIG_LOCATION); set +a; \
grep -q "127.0.0.1 $$K8S_PRIVATE_FQDN" /etc/hosts || echo "127.0.0.1 $$K8S_PRIVATE_FQDN" | sudo tee -a /etc/hosts
23 changes: 21 additions & 2 deletions scripts/create_local_k8s_cluster.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -o pipefail

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

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

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

Expand All @@ -28,5 +28,24 @@ if [[ ! -f "$KIND_CONFIG_FILE" ]]; then
exit 1
fi

#
# create a k8s cluster
#

echo "Creating a local Kubernetes cluster named '$KIND_CLUSTER_NAME' using configuration from '$KIND_CONFIG_FILE'..."

kind create cluster --config "$KIND_CONFIG_FILE" --name "$KIND_CLUSTER_NAME"

#
# install Calico network CNI
#

# https://archive-os-3-26.netlify.app/calico/3.26/getting-started/kubernetes/kind/

echo "Installing Calico network CNI ..."

kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.4/manifests/tigera-operator.yaml
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.4/manifests/custom-resources.yaml

echo "Waiting for Calico pods to start..."
while ! kubectl get pods -A -l k8s-app=calico-node 2>/dev/null | grep -q "Running"; do sleep 1; done
6 changes: 6 additions & 0 deletions scripts/kind_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ nodes:
labels:
ops: "true"
simcore: "true"

# https://archive-os-3-26.netlify.app/calico/3.26/getting-started/kubernetes/kind/
networking:
disableDefaultCNI: true
# must match with cidr in https://raw.githubusercontent.com/projectcalico/calico/v3.26.4/manifests/custom-resources.yaml
podSubnet: 192.168.0.0/16
Loading