-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
edge-inference on k3s on balena! (#64)
POC for edge-endpoint and inferenc-service successfully running on k3s on a machine with Balena OS.
- Loading branch information
1 parent
1e65841
commit 11febf6
Showing
14 changed files
with
212 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
Dockerfile | ||
README.md | ||
test_coverage_reports/ | ||
deploy/balena-k3s/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# https://github.com/balena-io-experimental/balena-k3s/blob/main/balena.yml | ||
name: balena-k3s-edge-endpoint | ||
type: sw.application | ||
version: 0.2.8 | ||
description: >- | ||
Run the edge-endpoint on top of k3s on Balena. The inference-server | ||
will also be deployed on the same k3s cluster. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Running the edge-endpoint via k3s on a balena device | ||
|
||
## Setup | ||
Tested using an EC2 m6 instance with 64GB disk. Everything except for the triton inference server works on a RaspberryPi 5 (which has a 64bit OS and 8Gb RAM), but the inference server is too demanding for the RPi5. | ||
|
||
From the root of `edge-endpoint`, run: | ||
```bash | ||
balena login | ||
balena push <your-fleet> | ||
``` | ||
This will build and push two "services" to the edge devices in your chosen fleet. The first is a [k3s server](https://docs.k3s.io/architecture) named `server`, which effectively acts as our k3s cluster node. The second is the `bastion` service, from which a user can access the k3s cluster (e.g. by running `kubectl get nodes`). The `bastion` service also contains a copy of this repo at `/app/edge-endpoint`. | ||
|
||
Now, we have our k3s cluster built and running, but we have not started our edge deployment. | ||
|
||
Configure the following variables via the `<fleet>/Variables` or `<device>/Device Variables` interfaces on the BalenaCloud dashboard: | ||
``` | ||
GROUNDLIGHT_API_TOKEN - so that we can authorize the fetching of edge model binaries | ||
AWS_ACCESS_KEY_ID - so we can pull the edge-endpoint and gl-tritonserver images from ECR | ||
AWS_SECRET_ACCESS_KEY - needed along with AWS_ACCESS_KEY_ID | ||
``` | ||
|
||
Now, ssh into `bastion` and run the following: | ||
```bash | ||
cd /app/edge-endpoint | ||
INFERENCE_FLAVOR="CPU" DEPLOYMENT_NAMESPACE="default" ./deploy/bin/cluster_setup.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# https://github.com/balena-io-experimental/balena-k3s/blob/main/bastion/Dockerfile | ||
# ------- Build Stage ------- | ||
FROM golang:1.21.0 AS arkade | ||
|
||
WORKDIR /src | ||
|
||
ARG ARKADE_VERSION=0.10.1 | ||
ARG CGO_ENABLED=0 | ||
|
||
ADD https://github.com/alexellis/arkade/archive/refs/tags/${ARKADE_VERSION}.tar.gz ./ | ||
|
||
RUN tar xvf ${ARKADE_VERSION}.tar.gz --strip-components=1 && make build | ||
|
||
# ------- Runtime Stage ------- | ||
FROM debian:bullseye-slim | ||
|
||
WORKDIR /app | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
RUN apt-get update && apt-get install --no-install-recommends -y \ | ||
ca-certificates \ | ||
curl \ | ||
unzip \ | ||
dnsutils \ | ||
vim \ | ||
jq \ | ||
gettext-base && \ | ||
apt-get clean && rm -rf /var/lib/apt/lists/* | ||
|
||
# Note that currently this is only for ARM | ||
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip" | ||
RUN unzip awscliv2.zip && rm awscliv2.zip | ||
RUN ./aws/install | ||
RUN aws --version | ||
|
||
COPY --from=arkade /src/arkade /usr/local/bin/arkade | ||
|
||
ENV PATH "${PATH}:/root/.arkade/bin/" | ||
|
||
RUN arkade version && \ | ||
arkade get --progress=false \ | ||
[email protected] \ | ||
[email protected] \ | ||
[email protected] \ | ||
[email protected] \ | ||
[email protected] | ||
|
||
|
||
# Copy edge-endpoint to /app/edge-endpoint | ||
RUN mkdir -p /app/edge-endpoint | ||
COPY . /app/edge-endpoint | ||
|
||
ENTRYPOINT [] | ||
CMD [ "tail" , "-f", "/dev/null" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# https://hub.docker.com/r/rancher/k3s/tags | ||
# https://github.com/k3s-io/k3s/blob/master/package/Dockerfile | ||
# https://github.com/balena-io-experimental/balena-k3s/blob/main/server/Dockerfile | ||
FROM rancher/k3s:v1.26.14-k3s1 | ||
|
||
COPY server.sh /server.sh | ||
RUN chmod +x /server.sh | ||
|
||
ENTRYPOINT [] | ||
CMD [ "/server.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
# https://docs.k3s.io/cli/server | ||
# https://docs.k3s.io/datastore/ha-embedded | ||
# https://github.com/balena-io-experimental/balena-k3s/blob/main/server/server.sh | ||
|
||
if [ -n "${K3S_URL:-}" ]; then | ||
# shellcheck disable=SC2086 | ||
exec /bin/k3s server --server "${K3S_URL}" ${EXTRA_K3S_SERVER_ARGS:-} | ||
else | ||
# shellcheck disable=SC2086 | ||
exec /bin/k3s server --cluster-init ${EXTRA_K3S_SERVER_ARGS:-} | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.