radian-software / riju

⚡ Extremely fast online playground for every programming language.
https://riju.codes
MIT License
1.6k stars 187 forks source link

Run Riju on Kubernetes #94

Open autolyticus opened 2 years ago

autolyticus commented 2 years ago

I see that the self-hosting instructions are extremely reliant on cloud-specific architectural considerations (mostly AWS stuff). Is there a way to abstract that out and create a Kubernetes deployment mode or perhaps a Helm chart?

I would be glad to take this task on if I had guidance.

Thanks

raxod502 commented 2 years ago

I'd be happy to advise you on this if you'd like to deploy on Kubernetes. The reason for the current architectural decisions is primarily cost minimization, as I don't have anywhere near what it would cost to run a k8s cluster.

You may want to start by reviewing the current architecture (i.e. Terraform and artifact registry usage) and think about how you'd set things up if you were instead deploying to k8s. I'm happy to answer any questions you may have about details that are unexplained. Here are my initial thoughts on components that will need thought:

Feel free to challenge any of my assumptions about how things have to be designed for the deployment system to be maintainable! I'm sure things could be improved.

autolyticus commented 2 years ago

Haha so I have a self-hosted k3s cluster with a couple of Raspberry Pi 4s and a couple of old laptops that I had lying around. I even have some fast SSD storage attached to them and the performance is surprisingly good. This seemed like a fun but complex enough project to really dig deep and learn how to build things the right way on Kubernetes, which is why opened the issue.

I do have some analogs to the current services (minio as an s3 compatible api, harbor for a docker registry), and the caching for debian packages, I'm sure it should be as simple as mounting a persistent volume.

Do you think there needs to be a complete rethinking of the infrastracture from the ground up if going into Kubernetes land in order to optimise things. For example, some of the things could be a lot more easy to enforce like the types of fine grained resource limits that it provides.

raxod502 commented 2 years ago

Do you think there needs to be a complete rethinking of the infrastracture from the ground up if going into Kubernetes land in order to optimise things

You tell me! I think I've already laid out all the necessary information about how things work currently, let me know if that's not the case. I think you would be the better judge of whether there's a way that things could be implemented using k8s primitives that would be simpler than what we're doing currently.

autolyticus commented 2 years ago

I'll take a look at stuff and get back :)

There's also a few other advantages I could see (using something like gVisor to harden the security a bit more).

I do think that could lead to you saving costs as well, if you decide to go the Kubernetes route. AWS is ridiculously priced. Charging for egress is just outrageous, and clearly designed to ensure vendor lock in.

raxod502 commented 2 years ago

I do think that could lead to you saving costs as well, if you decide to go the Kubernetes route

Would it? Kubernetes is just the control plane. You still have to have servers to run the actual thing, and wherever you're hosting is going to charge for network bandwidth. Where are they going to run, if not AWS?

autolyticus commented 2 years ago

Well, right now my Kubernetes stuff is part of my homelab. So I'm paying exactly 0$ extra on top of what I already pay to my ISP. Power costs are minuscule enough that I'm not even considering them.

Sure, it's not as reliable or as fast as an instance on AWS, but for personal projects I prefer doing it this way because you end up learning more.

However, even if you want to provide a service with more nines in the uptime, take a look at alternative services like say OVH or DigitalOcean. They come with a huge amount of bandwidth for free each month (DigitalOcean has 1TB of free egress bandwidth with the most basic 5$ per month server).

Bootstrapping something like k3s or k0s by yourself on these nodes gives you incredible value for money over using different AWS services, and above managed K8S like EKS as well (of course with the tradeoff of administering the cluster and ensuring that everything is working yourself).

raxod502 commented 2 years ago

Re cost implications of AWS, I've been able to start generating detailed billing breakdowns: https://github.com/raxod502/riju/blob/master/financials/2021-08/breakdown.txt

Could be helpful in evaluating the costs of AWS versus self-hosting versus other providers.

raxod502 commented 2 years ago

I also have a spreadsheet that (among other things)

raxod502 commented 2 years ago

I'm revisiting this. I think you've hit on an interesting idea to use k3s or k0s on bare metal. When I've thought about Kubernetes in the past I've been imagining the typical multi-node configuration. But there's no reason not to use the k8s API within a single, large node. And doing so might actually help reduce the amount of orchestration code I have to write, for things like lazy-pulling images and doing blue-green deployment cutover.

I'll investigate replacing the supervisor binary with single-node k8s at some point.