-
Notifications
You must be signed in to change notification settings - Fork 433
feat(youki-deploy): add DaemonSet-based installer for installing youki on Kubernetes #3526
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Cargo / build artifacts | ||
| target/ | ||
| contest-target/ | ||
| bin/ | ||
|
|
||
| # Built binaries dropped at repo root by scripts/build.sh | ||
| youki | ||
| runtimetest | ||
| contest | ||
|
|
||
| # Test fixtures (not needed for image builds) | ||
| bundle.tar.gz | ||
| test.log | ||
|
|
||
| # Git / CI metadata (not used inside images) | ||
| .git/ | ||
| .github/ | ||
|
|
||
| # Docs build outputs | ||
| docs/book/book/ | ||
|
|
||
| # IDE / editor / OS noise | ||
| .idea/ | ||
| .vscode/ | ||
| *.swp | ||
| *.swo | ||
| .DS_Store | ||
|
|
||
| # Misc | ||
| node_modules/ | ||
| *.log |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # Using youki as a Kubernetes runtime | ||
|
|
||
| youki implements the OCI runtime spec, so it can be plugged into any | ||
| Kubernetes cluster. Once youki is installed on each node and the | ||
| node's container runtime is configured to know about it, individual | ||
| Pods can opt in via `runtimeClassName: youki`. | ||
|
|
||
| ## youki-deploy: ready-to-use installer for kind / containerd | ||
|
|
||
| The repository ships a small installer under | ||
| [`tools/youki-deploy/`](https://github.com/youki-dev/youki/tree/main/tools/youki-deploy) | ||
| which automates install the youki binary on every node, and register | ||
| it as a containerd runtime. It is composed of: | ||
|
|
||
| - A Docker image that bundles the youki release binary and an | ||
| `install-youki.sh` script. | ||
| - A Kubernetes DaemonSet manifest that runs that image as a privileged | ||
| pod on every node, mounts the host's `/usr/local/bin` and | ||
| `/etc/containerd`, copies the binary into place, patches | ||
| `/etc/containerd/config.toml`, and restarts containerd. | ||
|
|
||
| It is currently exercised against [kind](https://kind.sigs.k8s.io/) | ||
| (Kubernetes-in-Docker) but the manifests are Kubernetes | ||
| resources and should apply to any containerd-based cluster. | ||
|
|
||
| ## Try it locally on kind | ||
|
|
||
| To stand up the cluster + DaemonSet: | ||
|
|
||
| ```console | ||
| $ just kind-deploy | ||
| ``` | ||
|
|
||
| To tear it down: | ||
|
|
||
| ```console | ||
| $ just clean-test-kind-deploy | ||
| ``` | ||
|
|
||
| See also | ||
| [Developer Documentation > Kubernetes test](../developer/e2e/kubernetes_test.md). | ||
|
|
||
| ## Using youki for your own Pods | ||
|
|
||
| Once the DaemonSet is installed, just add `runtimeClassName: youki` to | ||
| the pod spec: | ||
|
|
||
| ```yaml | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: nginx-youki | ||
| spec: | ||
| runtimeClassName: youki | ||
| containers: | ||
| - name: nginx | ||
| image: nginx:1.27-alpine | ||
| ``` | ||
|
|
||
| Pods without `runtimeClassName` continue to use whatever the cluster's | ||
| default OCI runtime is (typically `runc`), so installing youki-deploy | ||
| is non-disruptive for existing workloads. | ||
|
|
||
| ## Caveats | ||
|
|
||
| - The installer modifies `/usr/local/bin/youki` and | ||
| `/etc/containerd/config.toml` on the host. It does not currently | ||
| uninstall on DaemonSet deletion - removing youki and the containerd | ||
| config patch must be done manually. | ||
| - The DaemonSet manifest references the installer image as | ||
| `youki-installer:latest`, which is loaded into the local kind cluster | ||
| by `just kind-deploy`. To deploy on a real cluster, build the image | ||
| from `tools/youki-deploy/Dockerfile` and push it to a registry that | ||
| your cluster nodes can pull from, then update the image field in | ||
| `tools/youki-deploy/youki-deploy.yaml`. |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||
| # syntax=docker/dockerfile:1.4 | ||||||||||||||
|
|
||||||||||||||
| FROM rust:1-slim-bookworm AS youki-build | ||||||||||||||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||||||||||||||
| pkg-config \ | ||||||||||||||
| libsystemd-dev \ | ||||||||||||||
| build-essential \ | ||||||||||||||
| libelf-dev \ | ||||||||||||||
| libseccomp-dev \ | ||||||||||||||
| libclang-dev \ | ||||||||||||||
| libssl-dev \ | ||||||||||||||
| && rm -rf /var/lib/apt/lists/* | ||||||||||||||
| WORKDIR /youki | ||||||||||||||
| COPY . . | ||||||||||||||
| RUN cargo build --release -p youki --features "v2 systemd" | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We’d like to enable the build cache as shown below.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| FROM debian:bookworm-slim | ||||||||||||||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||||||||||||||
| util-linux \ | ||||||||||||||
| && rm -rf /var/lib/apt/lists/* | ||||||||||||||
| COPY --from=youki-build /youki/target/release/youki /opt/youki/bin/youki | ||||||||||||||
| COPY tools/youki-deploy/install-youki.sh /opt/youki/bin/install-youki.sh | ||||||||||||||
| RUN chmod +x /opt/youki/bin/install-youki.sh /opt/youki/bin/youki | ||||||||||||||
| ENTRYPOINT ["/opt/youki/bin/install-youki.sh"] | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/usr/bin/env bash | ||
| # Install youki onto a kind node and register it with containerd. | ||
| # Designed to run inside a privileged DaemonSet pod that mounts the host's | ||
| # /usr/local/bin and /etc/containerd as hostPath volumes, with hostPID enabled. | ||
| set -euo pipefail | ||
|
|
||
| HOST_BIN_DIR=${HOST_BIN_DIR:-/host/usr/local/bin} | ||
| HOST_CONTAINERD_CONFIG=${HOST_CONTAINERD_CONFIG:-/host/etc/containerd/config.toml} | ||
| RUNTIME_HANDLER=${RUNTIME_HANDLER:-youki} | ||
| MARKER="# youki-deploy:${RUNTIME_HANDLER}" | ||
|
|
||
| echo "[youki-deploy] Installing youki on $(hostname)" | ||
|
|
||
| install -m 0755 -D /opt/youki/bin/youki "${HOST_BIN_DIR}/youki" | ||
|
|
||
| if grep -qF "${MARKER}" "${HOST_CONTAINERD_CONFIG}"; then | ||
| echo "[youki-deploy] containerd already configured, skipping config patch" | ||
| else | ||
| echo "[youki-deploy] Patching ${HOST_CONTAINERD_CONFIG}" | ||
| cat >>"${HOST_CONTAINERD_CONFIG}" <<EOF | ||
|
|
||
| ${MARKER} | ||
| [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.${RUNTIME_HANDLER}] | ||
| runtime_type = "io.containerd.runc.v2" | ||
| [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.${RUNTIME_HANDLER}.options] | ||
| BinaryName = "${HOST_BIN_DIR#/host}/youki" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is written with a dependency on the |
||
| SystemdCgroup = false | ||
| EOF | ||
| echo "[youki-deploy] Restarting containerd via host PID 1" | ||
| nsenter -t 1 -m -u -i -n -p -- systemctl restart containerd | ||
| fi | ||
|
|
||
| echo "[youki-deploy] Done. Sleeping to keep DaemonSet pod Ready." | ||
| exec sleep infinity | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| kind: Cluster | ||
| apiVersion: kind.x-k8s.io/v1alpha4 | ||
| nodes: | ||
| - role: control-plane | ||
| - role: worker | ||
| - role: worker |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Namespace | ||
| metadata: | ||
| name: youki-system | ||
| labels: | ||
| pod-security.kubernetes.io/enforce: privileged | ||
| --- | ||
| apiVersion: node.k8s.io/v1 | ||
| kind: RuntimeClass | ||
| metadata: | ||
| name: youki | ||
| handler: youki | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please configure scheduling to avoid failures caused by early scheduling. |
||
| --- | ||
| apiVersion: v1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we’re not configuring RBAC or anything similar, deploying a ServiceAccount probably doesn’t provide much value. |
||
| kind: ServiceAccount | ||
| metadata: | ||
| name: youki-deploy | ||
| namespace: youki-system | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: DaemonSet | ||
| metadata: | ||
| name: youki-deploy | ||
| namespace: youki-system | ||
| labels: | ||
| app: youki-deploy | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| app: youki-deploy | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: youki-deploy | ||
| spec: | ||
| serviceAccountName: youki-deploy | ||
| hostPID: true | ||
| tolerations: | ||
| - operator: Exists | ||
| effect: NoSchedule | ||
| - operator: Exists | ||
| effect: NoExecute | ||
| containers: | ||
| - name: installer | ||
| image: youki-installer:latest | ||
| imagePullPolicy: IfNotPresent | ||
| securityContext: | ||
| privileged: true | ||
| env: | ||
| - name: HOST_BIN_DIR | ||
| value: /host/usr/local/bin | ||
| - name: HOST_CONTAINERD_CONFIG | ||
| value: /host/etc/containerd/config.toml | ||
| - name: RUNTIME_HANDLER | ||
| value: youki | ||
| volumeMounts: | ||
| - name: host-usr-local-bin | ||
| mountPath: /host/usr/local/bin | ||
| - name: host-etc-containerd | ||
| mountPath: /host/etc/containerd | ||
| volumes: | ||
| - name: host-usr-local-bin | ||
| hostPath: | ||
| path: /usr/local/bin | ||
| type: Directory | ||
| - name: host-etc-containerd | ||
| hostPath: | ||
| path: /etc/containerd | ||
| type: Directory | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it’s not idempotent, it would be better to skip it if the cluster already exists.