If you find yourself having to emulate different CPU architectures in a Kubernetes environment you'll probably end up running some version of binfmt as an init container or maybe manually run it once.
That would probably be ok in most cases, but wouldn't work if, for example, you're running multiple pod replicas on the same node concurrently (say, when you setup a CI that spawns pods for every job in your pipeline) or when nodes are autoscaled.
There're probably ways to make sure only one pod sets up binfmt, but when running the pods concurrently, it's very difficult to orchestrate.
But there's light at the end of the tunnel. There's the DaemonSet which we can use to run binfmt once on any newly created node.
You just need to create a simple config with:
And apply it:
kubectl apply -f ./daemonset.yaml
That's it. binfmt should now be setup on your cluster.
NOTE: If later on you decide on a different approach, you can delete the daemonset and any resources associated with it:
kubectl delete daemonset binfmt --namespace=default