Building Pull Request based ephemeral Preview environments on Kubernetes
Chinmay Naik
Founder and CEO at One2N | Building Cloud Native Solutions | Is your business scaling faster than tech can handle? DM me.
A CTO of a company calls you. They just migrated from Heroku to AWS on EKS. He's happy with the migration but wants you to build Heroku's "Ephemeral Preview Apps" on Kubernetes.
You know you can use ArgoCD for this, but you're in for some surprises and complications!
He wants to build ephemeral preview apps for both frontend and backend repos.
He lists down some more asks, which complicate things a bit.
He wants you to handle:
All this while using existing tools as much as possible.
Your Documentation-driven approach
You sign up for this work and start creating a doc listing all requirements and identifying the unknowns. You've built preview environments before. However, handling dependency management, database migrations, seed data, etc., often requires custom solutions as it is contextual. Couple with that, some constraints to use existing tools, and now you have some interesting engineering work!
You list down existing tools and processes. They are:
The next step is to try out some POCs to convert the "known unknowns" into "knowns". You know that the preview envs can easily be created for the frontend repos. For backend apps, you'll need to find out answers to some questions.
You'll need to design the system based on answers to these and other questions.
So you do the grunt work, write down all questions, discuss the trade-offs with the CTO and other engineering leads, and finally, you come up with a solution that handles all these cases. Getting to this solution requires some POCs, trial and error, but it's part of the process.
Ephemeral PR based Preview environment workflow
Here's how you design the workflow.
领英推荐
This flow works well for both frontend and backend repos.
Challenges
Here are three main challenges you handle along the way:
Let's expand on the challenges further.
You create a custom PostgreSQL image already loaded with seed data. This seed data is version-controlled in Git. That way, devs can easily update the PostgreSQL image when some new data needs to be loaded.
You run the database containers in the same preview namespace for each PR. Thus, they are isolated from other PRs. By default, service A's PR will point to service B's staging env (if service A depends on service B) but can be easily overridden by devs by a config change.
To keep Preview env costs in check, you suggest running it on Spot instances. Obviously, you're also deleting all resources of the preview environment if it's not actively being used. This concludes your work. The CTO is super happy and wants to work with you further.
Are you such a CTO or engineering leader looking to supercharge developer productivity?
If you're looking for a reliable engineering partner for all things Infra, DevOps, Observability, and Reliability, DM me.
We do Pragmatic Software Engineering - on Production. That's it!
I write such stories on software engineering.
There's no specific frequency, as I don't make up these.
If you liked this one, you might love - https://www.dhirubhai.net/pulse/taming-gcp-networking-cloud-costs-chinmay-naik/
Follow me - Chinmay Naik for more such stuff, straight from the production oven!
Manager, Software Engineering @ Disney Ad Platform ?? | Founding Member of Latinx in Tech ERG @ Disney ????
1 年Heroku straight to k8s sounds like a headache waiting to happen! ??
Software Engineer | MS CS @ UC San Diego | GSoC '24 @ SPCL | ICPC Regionalist | Ex SDE-2 @ Trilogy | AWS, Go, Python, Kubernetes, Distributed Systems, Cloud, Serverless, GenAI
1 年For Keeping costs low for the Preview environments: One could consider using KEDA or Knative for Event driven autoscaling but that goes against the CTO's requirement stated in the article: "using existing tools as much as possible." For spot instances: The developers might get frustrated if a preview pod goes down when they're testing it
Infrastructure Magician at TrueFoundry | CK{A,SS} | Ex-Kutumb/Crafto, Ex-smallcase
1 年Excellent Execution Chinmay Naik ?? ?? ?? you've made a very complex thing easy to understand. thanks for sharing your journey