Skip to main content

Ralsina.Me — Roberto Alsina's website

Posts about raspberry

VMs in small ARM servers

Background (I swear I get to VMs later)

I have been run­ning a per­son­al serv­er at my of­fice for a lit­tle while (See 1 and 2) where I run a num­ber of con­tainer­ized ser­vices.

Since I had it, I want­ed to add a way to eas­i­ly de­ploy my own ex­per­i­men­tal code so I can do quick "server­s" for things I am play­ing with.

I could just cre­ate my code as, say, a flask app and cre­ate con­tain­ers for them and de­ploy them that way, and then add ingress rules in my gate­way and ... it gets ex­haust­ing pret­ty fast.

What I want­ed was a way to run my own Heroku, sor­ta. Just write a bit of code, run a com­mand, have it be avail­able.

Af­ter googling I found a so­lu­tion that did­n't re­quire me to im­ple­ment a k8s clus­ter: faasd. The prom­ise is:

  • Run a shell script to in­stall faasd
  • Write your code as a func­tion
  • Run a com­mand to de­ploy
  • It all runs out of a sin­gle ingress path (ex­cept CORS of course)

So, min­i­mal con­fig, ease of de­ploy­men­t, no need to con­stant tweak­ing of my gate­way. All good!

Ex­cept ... faasd does­n't play along with Dock­er. Both use con­tain­erd and cni and oth­er things as their back­end, and faasd says that re­al­ly, they like spe­cif­ic ver­sions so they should in­stall them, not the sys­tem, and then run­ning dock­er gets pret­ty dicey.

So, I could just get a sec­ond serv­er. It's not like I don't have more small com­put­er­s.

But my serv­er has spare ca­pac­i­ty! So I don't WAN­NA START A SEC­OND SERVER!

Al­so, this is go­ing to of­ten be toy code I have not care­ful­ly vet­ted for se­cu­ri­ty, so it would be bet­ter if it ran in iso­la­tion.

So? I need­ed a VM.

Really, a VM inside a tiny ARM computer

My serv­er is a Radxa Ze­ro. It's small­er than a cred­it card. It has, how­ev­er, 4 cores, and 4GB of RAM, so sure­ly there must be a way to run a VM in it that can iso­late Faasd and let it run its wonky ver­sions of things while the rest of the sys­tem does­n´t care.

And yes, there is!

Fire­crack­er claims that you can start a VM fast, that it has over­head com­pa­ra­ble to a con­tain­er, and that it pro­vides iso­la­tion! It's what Ama­zon us­es for Lamb­da, so it should be enough for me.

On the oth­er hand, Fire­crack­er is a pain if you aren't a freak­ing Ama­zon SRE, which I am re­al­ly not, but ...

Ig­nite is a VM man­ag­er that has a "con­tain­er UX" and can man­age VMs declar­a­tive­ly!

So I set out to run ig­nite on my serv­er. And guess what? It work­s!

It's pack­aged for Arch, which is what I am us­ing, so I just in­stalled it, run a cou­ple of scripts to cre­ate a VM:

[ralsina@pinky faas]$ cat build.sh
#!/bin/sh -x
# Create and configure a VM with faasd in it
set -e

NAME=faas

waitport() {
    while ! nc -z $1 $2 ; do sleep 1 ; done
}

sudo ignite create weaveworks/ignite-ubuntu \
        --cpus 2 \
        --memory 1GB \
        --size 10GB \
        --ssh=id_rsa.pub \
        -p 8082:8081 \
        --name $NAME

sudo ignite vm start $NAME

IP=$(sudo ignite vm ls | grep faas | cut -f9 -d\        )
waitport $IP 22

ssh -o "StrictHostKeyChecking no" root@$IP mkdir -p /var/lib/faasd/secrets
ssh root@$IP "echo $(pass faas.ralsina.me) > /var/lib/faasd/secrets/basic-auth-password"
scp setup.sh root@$IP:
ssh root@$IP sh setup.sh

# Login
export OPENFAAS_URL=http://localhost:8082
ssh root@$IP cat /var/lib/faasd/secrets/basic-auth-password | faas-cli login --password-stdin

# Setup test function
faas-cli store deploy figlet

echo 'Success!' | faas-cli invoke figlet
[ralsina@pinky faas]$ cat setup.sh
#!/bin/sh -x

set -e
apt update
apt upgrade -y
apt install -y git

git clone https://github.com/openfaas/faasd
cd faasd
./hack/install.sh

If you run build.sh it will create a ubuntu-based VM with Faasd installed, start it, map a port to it, setup SSH keys so you can ssh into it, and configure authentication for Faasd so you can log into that too.

Does it work?

In­deed it does!

Are there any problems?

There is one and it's pret­ty bad.

If the server closes badly (and that means: without explicitly shutting down the VM), the VM gets corrupted, every time. It either ends in a "Running" state in ignite while it's dead in containerd, or the network allocation is somehow duplicated and denied, or one of half a dozen other failure states at which point it's easier to remove everything in /var/lib/firecracker and recreate it.

Is it easy to deploy stuff?

You betcha! Here's an example from https://nombres.ralsina.me, if I run build.sh it builds it, deploy.sh deploys it, the actual code is in the busqueda/ and historico/ folders.

It's very sim­ple to write code, and it's very sim­ple to de­ploy.

If I found a bet­ter way to han­dle the VMs I would con­sid­er this fin­ished.

Lo que Ando Haciendo

Este post es una lista de "proyec­tos" en los que es­toy me­tien­do mano en es­tos tiem­pos. En otras épocas hu­biera si­do una lista de proyec­tos open source pero hoy en día es al­go bas­tante más di­ver­so.

NINGU­NA de las cosas que van a ver a con­tin­uación es un proyec­to "se­ri­o" o us­able para al­gún ser hu­mano que no sea yo (y a ve­ces ni es­o).

Compu Artesanal

Con­vertí una rasp­ber­ry pi 3 (o 4, aho­ra que sé que an­da) en una com­pu al­l-in-one, con una pan­talla de 8.8 pul­gadas con res­olu­cion 1920x480 (sí, es to­do una com­bi­nación bas­tante ridícu­la)

¿Para qué?

  • Porque quiero apren­der a dis­eñar ob­je­tos fun­cionales.
  • Porque quiero ten­er una com­pu low-end para pro­bar si soft­ware que es­cri­bo fun­ciona con "poco" hard­ware.
  • Porque quiero una com­pu para no mul­ti­taskear. Quiero sen­tarme a es­cribir y es­cribir, o a pro­gra­mar y pro­gra­mar, y no saltar de una cosa a otra.
  • Es el primer es­calón ha­cia hac­erme una note­book casera

¿Que tal viene?

¡Está bási­ca­mente ter­mi­nada! Po­dría de­jar­la co­mo es­tá y de­cir "lis­to", ex­cep­to que al­gu­nas de las partes de la car­caza no son ide­ales, y otras es­tán hechas de dos o tres partes pe­gadas cuan­do de­berían ser una so­la.

¿Fun­ciona? Oh sí.

Features

  • Lin­da pan­talla que les ju­ro es us­able siem­pre y cuan­do la pon­gas jus­to mas al­lá del tecla­do.
  • Un so­lo ca­ble (que se vea des­de el frente) ... in­clu­so tiene una batería, se ban­ca un par de ho­ras des­ench­u­fa­da.
  • Soft­ware con­fig­u­ra­do a me­di­da para el form fac­tor inusu­al.

Lo que me ll­e­va al se­gun­do proyec­to ...

Software configurado para pantallas raras/malas

De­spués de var­ios meses de NO ten­er com­pu en casa me rendí y ha­bil­ité una Thinkpad T430, que es un fier­ro, pero ...

La pan­talla es muy mala. 1384x768. ¡Tiene casi la mis­ma can­ti­dad de pix­els que la pan­talla ridícu­la de mi com­pu arte­sanal!

Así que con DOS com­puta­do­ras con pan­tallas lim­i­tadas de­cidí hac­er al­go al re­spec­to: ele­gir y us­ar soft­ware que no des­perdi­cia tan­to es­pa­cio en pan­talla.

Es­tas son al­gu­nas de las elec­ciones, de­spués de pro­bar lit­eral­mente do­ce­nas de al­ter­na­ti­vas para ca­da cosa.

  • Desk­top: Qtile (con al­gu­na con­fig­u­ración enci­ma)
  • Ter­mi­nal: st (con var­ios parch­es para scroll­back, clip­board y otras cosas)
  • Browser: Qute­brows­er (chrome an­da igual pero des­perdi­cia MUCHA PAN­TALLA)

A su vez tratar de no usar Chrome implica ... donde están mis passwords? Así que estoy migrando a pass ... parece estar andando bien, pero todavía no traté de usarlo en el celular.

A su vez eso me llevó a ...

Software que creo que nadie usa, pero debieran!

Sabés cuan­tas cosas salen si buscás "ter­mi­nal" en Arch Lin­ux? In­cluyen­do los pa­que­tes del AU­R? CIEN­TOS. Y probé una frac­ción grande de el­las.

En par­tic­u­lar me en­con­tré con al­gunos pro­gra­mas que son joy­i­tas que nun­ca había oí­do nom­brar.

  • tab-rs un mul­ti­­plex­er con un so­­lo short­­­cut! de he­­cho ar­mé un set­up bas­­tante ex­­traño usán­­do­­lo pero que me gus­­ta mu­­cho, que merece su propia de­scrip­­ción.

  • slides ... slides! He­­chos con Mark­­down! En una ter­mi­­nal!

  • kiro ... mejor que nano.

Un mouse-joystick

Cuan­do ha­ga mi note­book, voy a nece­si­tar al­go así. Tal vez. Quien sabe.

Y eso me llevó a ...

Programar Raspberry Pi Pico

Mu­cho mas lin­do que pro­gra­mar Ar­duino, y cues­tan lo mis­mo.

Y las posi­bil­i­dades! Es posi­ble hac­er una conex­ión USB a mi mouse-joy­stick y con­fig­u­rar el firmware us­an­do una in­ter­faz de ter­mi­nal!

Quiero un tecla­do que se remapee con una ter­mi­nal se­rie US­B!

No quiero HAC­ER­LO porque no quiero sol­dar to­do eso pero ... y si lo ha­go con un Mod­e­lo M?

Y aparte ...

Y laburo full time. Y leo bas­tante (acá salen los li­bros que voy ter­mi­nan­do)

Así que an­do ocu­pa­do.

Booting a Raspberry Pi Zero without a SD card

I have been work­ing on a many-rasp­ber­ries clus­ter, and one of the parts I want­ed to get right is set­ting up rasp­ber­ry pi ze­ros to boot with­out any stor­age.

So, I doc­u­ment­ed it. It's all here: http­s://github.­com/ralsi­na/ze­ro-n­f­s­root


Contents © 2000-2023 Roberto Alsina