diff --git a/Makefile b/Makefile index d01dd5d6..bae6f5c1 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ # Commands YQ=docker run --rm -i -v $(shell pwd):/workdir mikefarah/yq:4 -KINDCONFIG := $(or $(KINDCONFIG),control-plane/kind.yaml) +USER := $(USER) KUBECONFIG := $(shell pwd)/.kubeconfig MKE2FS_CONFIG := $(shell pwd)/mke2fs.conf @@ -31,11 +31,6 @@ else $(error Unknown flavor $(MINI_LAB_FLAVOR)) endif -KIND_ARGS= -ifneq ($(K8S_VERSION),) -KIND_ARGS=--image kindest/node:v$(K8S_VERSION) -endif - ifeq ($(CI),true) DOCKER_COMPOSE_TTY_ARG=-T else @@ -43,7 +38,7 @@ else endif .PHONY: up -up: env control-plane-bake partition-bake +up: env only-control-plane only-partition @chmod 600 files/ssh/id_rsa docker compose up --remove-orphans --force-recreate control-plane partition @$(MAKE) --no-print-directory start-machines @@ -61,30 +56,28 @@ restart: down up down: cleanup .PHONY: control-plane -control-plane: control-plane-bake env +control-plane: only-control-plane env docker compose up --remove-orphans --force-recreate control-plane -.PHONY: control-plane-bake -control-plane-bake: - @if ! which kind > /dev/null; then echo "kind needs to be installed"; exit 1; fi - @if ! kind get clusters | grep metal-control-plane > /dev/null; then \ - kind create cluster $(KIND_ARGS) \ - --name metal-control-plane \ - --config $(KINDCONFIG) \ - --kubeconfig $(KUBECONFIG); fi - .PHONY: partition -partition: partition-bake +partition: only-partition docker compose up --remove-orphans --force-recreate partition -.PHONY: partition-bake -partition-bake: +.PHONY: only-control-plane +only-control-plane: + @if ! sudo $(CONTAINERLAB) --topo $(LAB_TOPOLOGY) inspect | grep -i metal-control-plane > /dev/null; then \ + sudo --preserve-env $(CONTAINERLAB) deploy --topo $(LAB_TOPOLOGY) --node-filter metal-control-plane --reconfigure && \ + ./scripts/deactivate_offloading.sh && \ + sudo chown $(USER):$(USER) $(KUBECONFIG); fi + +.PHONY: only-partition +only-partition: docker pull $(MINI_LAB_VM_IMAGE) ifeq ($(MINI_LAB_FLAVOR),sonic) docker pull $(MINI_LAB_SONIC_IMAGE) endif @if ! sudo $(CONTAINERLAB) --topo $(LAB_TOPOLOGY) inspect | grep -i leaf01 > /dev/null; then \ - sudo --preserve-env $(CONTAINERLAB) deploy --topo $(LAB_TOPOLOGY) --reconfigure && \ + sudo --preserve-env $(CONTAINERLAB) deploy --topo $(LAB_TOPOLOGY) --node-filter leaf01,leaf02,inet,vms --reconfigure && \ ./scripts/deactivate_offloading.sh; fi .PHONY: env @@ -102,19 +95,23 @@ route: _ips eval "sudo ip r a ${staticR}" .PHONY: cleanup -cleanup: cleanup-control-plane cleanup-partition +cleanup: cleanup-only-control-plane cleanup-only-partition -.PHONY: cleanup-control-plane -cleanup-control-plane: - kind delete cluster --name metal-control-plane +.PHONY: cleanup-only-control-plane +cleanup-only-control-plane: + docker rm -f metal-control-plane-control-plane docker compose down rm -f $(KUBECONFIG) -.PHONY: cleanup-partition -cleanup-partition: - mkdir -p clab-mini-lab - sudo $(CONTAINERLAB) destroy --topo mini-lab.cumulus.yaml - sudo $(CONTAINERLAB) destroy --topo mini-lab.sonic.yaml +.PHONY: cleanup-only-partition +cleanup-only-partition: +ifeq ($(MINI_LAB_FLAVOR),cumulus) + sudo --preserve-env $(CONTAINERLAB) destroy --topo $(LAB_TOPOLOGY) +else ifeq ($(MINI_LAB_FLAVOR),sonic) + sudo --preserve-env $(CONTAINERLAB) destroy --topo $(LAB_TOPOLOGY) --node-filter leaf01,leaf02,inet,vms +else + $(error Unknown flavor $(MINI_LAB_FLAVOR)) +endif .PHONY: _privatenet _privatenet: env diff --git a/README.md b/README.md index 94798a6c..df077902 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ The mini-lab is a small, virtual setup to locally run the metal-stack. It deploy - [Requirements](#requirements) - [Known Limitations](#known-limitations) - [Try it out](#try-it-out) - - [Reinstall machine](#reinstall-machine) - - [Free machine](#free-machine) + - [Reinstall machine](#reinstall-machine) + - [Free machine](#free-machine) - [Flavors](#flavors) @@ -22,14 +22,13 @@ The mini-lab is a small, virtual setup to locally run the metal-stack. It deploy - Linux machine with hardware virtualization support - kvm as hypervisor for the VMs (you can check through the `kvm-ok` command) - [docker](https://www.docker.com/) >= 20.10.13 (for using kind and our deployment base image) -- [kind](https://github.com/kubernetes-sigs/kind/releases) == v0.20.0 (for hosting the metal control plane) - [containerlab](https://containerlab.srlinux.dev/install/) >= v0.47.1 - the lab creates a docker network on your host machine (`172.17.0.1`), this hopefully does not overlap with other networks you have - (recommended) haveged to have enough random entropy (only needed if the PXE process does not work) Here is some code that should help you to set up most of the requirements: - ```bash +```bash # If UFW enabled. # Disable the firewall or allow traffic through Docker network IP range. sudo ufw status @@ -49,20 +48,16 @@ sudo usermod -G docker -a ${USER} # Install containerlab bash -c "$(curl -sL https://get.containerlab.dev)" - -# Install kind (kubernetes in docker), for more details see https://kind.sigs.k8s.io/docs/user/quick-start/#installation -sudo curl -Lo /usr/local/bin/kind "https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64" -sudo chmod +x /usr/local/bin/kind ``` The following ports are used statically on your host machine: | Port | Bind Address | Description | -|:----:|:------------ |:---------------------------------- | -| 6443 | 0.0.0.0 | kube-apiserver of the kind cluster | -| 4443 | 0.0.0.0 | HTTPS ingress | -| 4150 | 0.0.0.0 | nsqd | -| 8080 | 0.0.0.0 | HTTP ingress | +| :--: | :----------- | :--------------------------------- | +| 6443 | 0.0.0.0 | kube-apiserver of the kind cluster | +| 4443 | 0.0.0.0 | HTTPS ingress | +| 4150 | 0.0.0.0 | nsqd | +| 8080 | 0.0.0.0 | HTTP ingress | ## Known Limitations @@ -111,7 +106,7 @@ make firewall make machine ``` -__Alternatively__, you may want to issue the `metalctl` commands on your own: +**Alternatively**, you may want to issue the `metalctl` commands on your own: ```bash docker compose run --rm metalctl network allocate \ diff --git a/mini-lab.sonic.yaml b/mini-lab.sonic.yaml index 5e26099e..f4ff77c8 100644 --- a/mini-lab.sonic.yaml +++ b/mini-lab.sonic.yaml @@ -6,6 +6,9 @@ mgmt: topology: nodes: + metal-control-plane: + kind: k8s-kind + startup-config: control-plane/kind.yaml leaf01: kind: linux image: ${MINI_LAB_SONIC_IMAGE}