“It Works on My Machine” is a $200k Problem – A Guide to Containerisation & Kubernetes Services
You’ve spent days trying to deploy your solution and it’s failed. You’ve tested your code on your local machine, it’s passed all tests in staging and you’re deploying to production and it’s crashing because a library isn’t found. Or the pod keeps getting evicted at 3am because no one put a memory limit. Or the Cluster Autoscaler won’t spin new nodes because the pod requests aren’t correct. Your team will then waste 18 hours trying to fix these issues. No one will charge you for this, however you’re paying for it in your engineering salaries, delayed releases and the damage to your product team and platform team relationship.
The aim of containerisation and orchestration services is to prevent this issue. Yes, Docker and Kubernetes are the cool thing, but if you have to manually configure your servers, deployments and discover you’re having issues with environments in production, it’ll cost you. This guide will help you understand what a container and orchestration solution really is, what a specialist can help you achieve that you wouldn’t be able to with a full-time employee and what the actual work would look like.
A Beginners Explanation
The two main things people mix up:
Containerisation is the act of packaging. All the components you need to run your application will be packaged into an image. This includes your application, libraries, system tools and configuration files. These images will be identical when running on your laptops, test servers and production nodes in the cloud. This means “It Works on My Machine” no longer matters.
Orchestration is managing your scheduling. Deploying a single container on your laptop is easy. But when you’re deploying 300 containers to 12 servers. With spikes in traffic, rolling deployments and auto-restarts if something fails. You need something to manage your pods, deciding which pods go onto which nodes. This is where Kubernetes comes into play. It will decide where to run your containers, restart any failing ones, route traffic and scale the number of replicas.
The most common commercial versions are the managed products offered by the big cloud providers. These include Amazon EKS, Google Kubernetes Engine and Azure Kubernetes Service. Whilst these will manage your control plane they won’t design your architecture, secure your cluster, optimise cost or design a deployment pipeline. This is where specialist freelancers come in.
Why do companies hire specialist freelancers?
The obvious answer is cost (which is partly true). However, the real reason is time.
If you’re looking to containerise a 10 year old monolith you’ll need to dedicate a short amount of time (3-6 months) to solving a very specific, high skill issue. Once you’ve containerised your application you’ll need to maintain it and improve it gradually. This is where you can utilise a generalist platform engineer. Hiring a senior Kubernetes architect for 6 months will cost you too much or you’ll lose your specialist as soon as the interesting work is done.
Freelance engineers have specific experience. If they’ve containerised 40 applications within finance, healthcare and e-commerce they’ll know what can go wrong. They’ll know what storage solutions will persist with node failures, what network policies will be blocking legitimate traffic and what autoscaling settings will result in you getting a bill that looks like a typo.
Knowledge transfer. A good specialist will not just create your cluster, they’ll provide documentation, training and runbooks. The best engagements will result in your team being confident to run your cluster.
What Will the Work Involve?
A good containerisation and orchestration engagement will involve 5 areas of work. Most projects will cover all 5 areas but the emphasis may vary depending on where you’re starting.
Containerisation
This seems simple but it’s not. A naive Dockerfile will result in an image that’s hundreds of megabytes too large, runs as root, contains build tools that shouldn’t be there (they’re part of the compiler!) and will take minutes to start. A professional Dockerfile will use multi-stage builds to separate the build environment, run as a non-root user, pin the base image versions and ensure the layers are ordered in the correct order to utilise caching.
An image that can start in 3 seconds vs 45 seconds will make a huge difference to how quickly your cluster can scale and how quickly you can roll back deployments.
Cluster Design
Your cluster is a piece of architecture. This will decide if your platform will survive its first real incident.
High Availability. No single points of failure within your control plane and worker nodes. Whilst the control plane will be managed by your provider, the architecture of your worker nodes, availability zones and pod disruption budgets will be designed by your architect.
Networking & Policies. Many deployments are insecure. A Container Network Interface plugin (most commonly Calico & Cilium in production) will be used to provide networking to your pods. This will also provide a policy engine to act as a firewall between services. Most initial deployments don’t have any networking policies so any compromised pods can talk to all other pods in your cluster. Networking policies can be difficult to implement retrospectively.
Stateful Applications. Stateful applications are what will differentiate your demo from your production. Stateless applications are easy to orchestrate. Any databases, message queues or other stateful applications will require StatefulSets, persistent volume claims and storage classes with backing from cloud block storage or something like Longhorn. If you design this poorly you’ll get data loss.
Deployment Pipeline
Manual deployments won’t scale. A professional deployment pipeline will allow you to build, test, scan and deploy your application.
A typical deployment pipeline (using GitHub Actions, GitLab CI or Jenkins) will build an image, run your test suite, scan for known vulnerabilities, push your image to a registry and deploy to your target cluster. How you deploy your application will depend on your requirements. Rolling updates for regular changes, canary releases for risky changes and blue/green for instant rollbacks.
This area will have the biggest impact on your day-to-day. If you’re going from monthly releases to daily releases your team will notice the difference. Usually this will be the reason your team refer you to another company.
Security
A default Kubernetes install isn’t secure. A professional will harden your cluster.
Ensure your control plane and nodes are compliant with the CIS Kubernetes Benchmark. This will provide you with a prioritised list of issues.
Security contexts and Pod Security Standards (replacing the deprecated Pod Security Policy). RunAsNonRoot, ReadOnlyRootFilesystem and Linux Capabilities removed will reduce the blast radius if a container is compromised.
Secrets Management. This is where amateur deployments fall down. Storing your database passwords in environment variables within a Kubernetes Secret object means anyone with read access to your namespace can see your credentials. A professional deployment will use an external Secret Manager (HashiCorp Vault, AWS Secrets Manager, Azure Key Vault or GCP Secret Manager). The cluster will sync the secrets.
Image Scanning & Runtime Monitoring. Scanning your image will find any known vulnerabilities. Using tools like Falco will monitor your runtime for any suspicious activity. This is where container specific attacks usually occur.
Cost Optimisation
Kubernetes clusters are one of the most common places to have mysterious costs in your cloud. This is due to incorrect resource requests, autoscaling not working, development namespaces running at full capacity 24/7 and incorrect node pool sizes.
A professional will:
Ensure resources are requested and limited correctly. You can use your metrics to see what your CPU and Memory usage is. Over requesting will waste resources whilst under requesting will cause evictions. Both are common.
Ensure proper autoscaling. Horizontal Pod Autoscaler will scale your replicas. Cluster Autoscaler or Karpenter will scale your nodes. Poorly implemented autoscaling will be worse than nothing.
Use spot/preemptible instances for fault tolerant applications. This can give you massive savings (commonly 60-90% off eligible workloads) but only applies to workloads that can handle interruption. Using spot instances for stateful databases will cause you incidents.
Use tools like Kubecost or OpenCost to understand what your costs are. Without this no one will own your costs and no one will reduce them.
Examples
These examples are anonymised but typical of the engagements a specialist freelancer would undertake.
Monolith Migration. A Financial Services company had a Java application running on old VMs. We containerised the application, planned a data migration with acceptable rollback and deployed to a hardened managed cluster with restricted egress. This resulted in a meaningful cost saving on infrastructure and no downtime during deployment.
Greenfield Platform. A growing SaaS company required a new platform for their microservices. We helped them design their cluster on a managed service, provided a full CI/CD pipeline and documented our deployment process. This meant that they could now deploy multiple times per day without a platform engineer in the room.
Performance Improvement. An e-commerce company were experiencing random latency issues and pod evictions during high traffic. The issue was due to incorrect resource limits and a slow autoscaler. We improved the configuration. This is a common issue. Your cluster is fundamentally fine but no one has tuned it.
How to Find a Good Specialist
The market can be a bit hit and miss. There are good specialists that have experience running production clusters. There are also people that have done a certification and created a demo cluster. Ask them:
Can they give a specific example of something going wrong? A good specialist will have fixed an eviction storm, CNI issues or storage class issues. They will be able to give a technical example.
How do they document? They should be able to talk about runbooks, architecture diagrams and handover. If they can’t document they’re a specialist that will become a long term dependency.
Can they talk about cost? If they can’t explain how they’d reduce your cluster costs and by how much they haven’t run a cluster at scale.
Can they provide a reference from a client of a similar size and stage? Don’t ask for the biggest logo on their site, ask for someone with a similar engagement.
Getting Started
The hardest decisions to change once you’ve made them are the ones you make in your first month. The architecture of your cluster, networking policies, storage and pipeline. To ensure you get these right you’ll need experience. Most internal teams will learn from making the mistakes.
This is why you should bring a specialist in early. Whilst they won’t build everything for you they will provide the design so your team can run it. Usually your first conversation will be scoping. We’ll talk about what you currently have, what the pain points are and if it’s a rebuild, migration or tuning project. This will be free. If you do have a bad first attempt and then have to rebuild it will cost you significantly more.
Comments
Post a Comment