diff --git a/images/Makefile b/images/Makefile index 00e51c2bf..86bfdcb86 100644 --- a/images/Makefile +++ b/images/Makefile @@ -1,6 +1,6 @@ SHELL:=/bin/bash # Set the command for running `docker` -# -- allows user to override for things like sudo usage or container images +# -- allows user to override for things like sudo usage or container images DOCKER := docker # Set the first containerd.sock that successfully stats -- fallback to the docker4mac default CONTAINERD_SOCK := $(shell \ @@ -32,14 +32,15 @@ DOCKER_USER?=weaveworks VERSION?=$(shell git describe HEAD --tags) RELEASE?=latest FULL_IMAGE_NAME=${DOCKER_USER}/ignite-${WHAT}:${TAG} -RELEASE_IMAGE_NAME=${DOCKER_USER}/ignite-${WHAT}:${RELEASE} +escaped_RELEASE:=$(subst +,-,$(RELEASE)) +RELEASE_IMAGE_NAME=${DOCKER_USER}/ignite-${WHAT}:${escaped_RELEASE} LATEST_IMAGE_NAME=${DOCKER_USER}/ignite-${WHAT}:latest GOARCH?=amd64 GOARCH_LIST=amd64 arm64 # Set this flag to build a multiarch image IS_MANIFEST_LIST?=0 -TAG:=${RELEASE}$(if $(strip $(VERSION)),-${VERSION}) +TAG:=${escaped_RELEASE}$(if $(strip $(VERSION)),-${VERSION}) OP:=build TMPDIR?=/tmp @@ -141,7 +142,7 @@ push-all: build-all $(MAKE) OP=push build-all -build-all: build-alpine build-amazon-kernel build-amazonlinux build-centos build-kubeadm build-opensuse build-ubuntu +build-all: build-alpine build-amazon-kernel build-amazonlinux build-centos build-k3s build-kubeadm build-opensuse build-ubuntu build-alpine: ifeq ($(OP),build) @@ -161,6 +162,9 @@ build-centos: $(MAKE) ${OP} WHAT=centos RELEASE=7 $(MAKE) ${OP} WHAT=centos RELEASE=8 IS_LATEST=true +build-k3s: + $(MAKE) ${OP} WHAT=k3s RELEASE=v1.19.4+k3s1 IS_LATEST=true + build-kubeadm: $(MAKE) ${OP} WHAT=kubeadm RELEASE=v1.18.3 BINARY_REF=release/stable-1.18 IS_LATEST=true IS_MANIFEST_LIST=1 GOARCH=arm64 $(MAKE) ${OP} WHAT=kubeadm RELEASE=v1.18.3 BINARY_REF=release/stable-1.18 IS_LATEST=true IS_MANIFEST_LIST=1 GOARCH=amd64 diff --git a/images/k3s/Dockerfile b/images/k3s/Dockerfile new file mode 100644 index 000000000..938191ed9 --- /dev/null +++ b/images/k3s/Dockerfile @@ -0,0 +1,38 @@ +FROM ubuntu:20.04 + +# udev is needed for booting a "real" VM, setting up the ttyS0 console properly +# kmod is needed for modprobing modules +# systemd is needed for running as PID 1 as /sbin/init +# Also, other utilities are installed +RUN apt-get update && apt-get install -y \ + curl \ + dbus \ + jq \ + kmod \ + iproute2 \ + iputils-ping \ + net-tools \ + openssh-server \ + sudo \ + systemd \ + udev \ + wget && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Create the following files, but unset them +RUN echo "" > /etc/machine-id && echo "" > /var/lib/dbus/machine-id + +# Install k3s. The intermediate container used to run this command does not run systemd, so +# the installer can't automatically enable the k3s service. Instead, we do so manually. +ARG RELEASE +RUN curl -sfL https://get.k3s.io | INSTALL_K3S_SKIP_ENABLE=true INSTALL_K3S_VERSION="${RELEASE}" sh - +RUN ln -s /etc/systemd/system/k3s.service /etc/systemd/system/multi-user.target.wants/k3s.service + +# This container image doesn't have locales installed. Disable forwarding the +# user locale env variables or we get warnings such as: +# bash: warning: setlocale: LC_ALL: cannot change locale +RUN sed -i -e 's/^AcceptEnv LANG LC_\*$/#AcceptEnv LANG LC_*/' /etc/ssh/sshd_config + +# Set the root password to root when logging in through the VM's ttyS0 console +RUN echo "root:root" | chpasswd diff --git a/images/k3s/README.md b/images/k3s/README.md new file mode 100644 index 000000000..a34873c17 --- /dev/null +++ b/images/k3s/README.md @@ -0,0 +1,37 @@ +# Run k3s with Ignite VMs + +This short guide shows you how to setup Rancher's Lightweight Kubernetes (k3s) distribution with Ignite VMs. + +**NOTE:** At the moment, you need to execute all these commands as `root`. + +**NOTE:** k3s requires ~2 GiB of memory to function properly. The default 512 MiB of memory is not enough. + +The image contains a minimal Ubuntu 20.04 installation with the k3s server running as a daemon on boot. +Thus, spawning a single k3s Ignite VM is sufficient to operate a single-node k3s cluster. To get started: + +```bash +ignite run weaveworks/ignite-k3s:latest \ + --cpus 2 \ + --memory 2GB \ + --ssh \ + --name k3s-master +``` + +We can test the installation by checking the installed k3s version: + +```bash +ignite exec k3s-master -- k3s --version + +> k3s version v1.19.4+k3s1 (2532c10f) +``` + +We can also try to administrate the cluster from the host machine, if `kubectl` is installed: + +```bash +VM_IP=$(ignite inspect vm k3s-master | jq -r ".status.network.ipAddresses[0]") +ignite exec k3s-master -- cat /etc/rancher/k3s/k3s.yaml > kubeconfig +sed -i'' "s/127.0.0.1/$VM_IP/" kubeconfig +kubectl --kubeconfig=kubeconfig get nodes + +# Should list a single Master node, running the same k3s version displayed earlier +```