Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create kind metal-control-plane via containerlab #170

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
57 changes: 27 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,19 +31,14 @@ 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
DOCKER_COMPOSE_TTY_ARG=
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
Expand All @@ -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
Expand All @@ -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
Expand Down
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<!-- /TOC -->
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind ist still required

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested without local kinD installation. Besides the .kubeconfig file created with root ownership, the setup still works.

- [containerlab](https://containerlab.srlinux.dev/install/) >= v0.47.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also update the dependency to >= v0.55.0

- 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
Expand All @@ -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

Expand Down Expand Up @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions mini-lab.sonic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down