168 points · by plaur782 · 5y ago · 85 comments
If we need to increase storage this can be achieved in minutes, if we need to take one node down we basically can do it anytime during the day..
Every now and then we discuss moving DBs to AWS RDS (or equivalent) however for our transaction volume RDS costs are prohibitive.
How can I know that this isn't one of those cases? I know some folks in fintech and while obviously they're not _you_, they're definitely not the sort to be wishy washy with data, if anything they're quite conservative when it comes to how the databases are managed.
Any incidental complexity is incredibly discouraged.
a) run your stateful services (such as Postgres) on the same orchestration system
b) choose a second orchestration system (often a more "traditional" infrastructure provisioning system like Chef/Puppet/Ansible/SaltStack) that will only manage your stateful services, and deal with the care & feeding & mental overhead of having two things that do fairly similar jobs and need to interact with each other (because of course your k8s-hosted stateless services need to be able to look up Postgres in DNS)
(option C would be to use a managed service like RDS...but options A and B assume you've already made a decision, for whatever reason, to run the stateful services yourself)
The main force that's pushing us to move our storage into K8s isn't simplifying our node configuration, but to keep parity between our prod and more dynamic staging environments. For the latter k8s storage operators are great because we don't generally care about data durability or performance.
Not quite true if you use a managed K8S offering - and it seems a self-managed cluster is something to be avoided until absolutely necessary. Even with a managed cluster like GKE there's plenty of operational overhead to keep everything up-to-date and working properly.
I'll be downvoted to hell for this.
What does Kubernetes offer in this scenario?
I'm still hesitant to run things like DB's on K8's but have absolutely no problems running cloud native apps on K8's which can run ephemerally, be bin packed and only needing compute as all state is external to where the app is being executed.
A kubernetes node can advertise those local block devices as persistent volumes. Your StatefulSet can request that class of local storage and the kubernetes scheduler will then find a volume for the pods on a node that the pod can fit on.
You then get all the features of kubernetes operators plus the performance of dedicated nodes and local storage. When a local storage node disappears, your pod gets a new volume on a new node and can replicate from its peers, or start from a backup.
Kubernetes then offers metrics, certificate management, secret storage and management, load balancing, healthchecks, debugging tools, rich firewalling, RBAC, and a huge ecosystem of plugins. It gives you a unified API for all your workloads. Requesting a database then is as simple as a single API call to kubernetes with a spec for your database (ex: creating a MysqlCluster object).
The company I work for runs MySQL, ZooKeeper, memcached, hbase, hadoop, kafka, elasticsearch, and more in kubernetes with great success. Scale here in one prod region is ~10,000 pods on a clusters of ~600 nodes. There are about 900 separate MySQL clusters consisting of 3 replicas each, 150 separate zk clusters of 5 replicas each, etc.
- StatefulSets mean that K8s scheduling is aware that the workload is stateful and the auto-attach of drives works fantastically in my experience.
- NodeTaints/Tolerances and workload anti-affinities between workloads mean that you can very easily say “this workload runs on nodes with these features/labels” and “don’t run workload replicas on the same node” and “don’t run other workloads on the same node as this workload. Node groups on things like AWS EKS also make it really easy to get autoscaling groups of nodes with specific hardware.
What you want to run, and how, where, under what conditions, etc. is all specified in declarative files. Like I said, stateful services are not a problem anymore. K8S can deploy a database service as instances exclusive to specific nodes with the appropriate storage and networking config.
It's like an invisible assistant to automate what you would be doing yourself, or using several other tools to do anyway. A well-tested way to handle most of the common infrastructure issues for any deployed software in a single platform.
EDIT: I'll add that running K8S itself can be challenging, but that's because complexity can't be erased but only abstracted. I recommend using managed K8S to offload this.
They give you raw access to storage without redundancy. Which is great if your workload on top (like https://k8ssandra.io) already is redundant. Whilst making sure workloads stick to where their data is stored
I've faced so many issues with the CSI driver which doesn't attach/deattach properly when you modify anything on the Statetfulset.
Additionally, you need to pin your DBs ("statefulset workloads") to certain Nodes based on the AZs since a block storage like an EBS cannot really be attached from Zone 1 to Zone 2 automatically.
Based on these limitations, I dont really see any utility/usefulness in running a DB on K8s. I get all of the other niceties that K8s offers, but here it makes the Ops work more complex than desired.
For example, use a storage service (like Rook/openEBS/portworx/etc) that uses node-attached disks to create a data layer. Then you can assign volumes to your individual workloads created and managed by the storage service.
This provides reliable and portable storage for your other services without having to tying them to lower-level details.
Having Postgres replicate the data across AZs or run Ceph on top of EBS to do it at the storage level are options. The complexity of setup is made simpler by running their respective operators.
There used to be bugs with this years ago but all storage providers now get this right.
I’ve not had issues with EBS/AWS, and affinity configs meant it was really easy to spread nodes throughout AZ’s.
On Azure though, volume mounts/unmounts were an absolute dumpster fire.
People say this but my first reaction to "let's put our DB in the Kubernetes cluster" is still to take two steps backwards and prepare to run in the other direction. It really goes against all of my better instincts (and unfortunately hands-on experiences).
Now almost all databases are run on VMs
In this case, you should be asking “will we all be running databases in clustered mode in the future?”
I think that answer still up for debate.
Sure, and containers are just plain processes on a VM. The exact code that controls processes in a VM, also controls processes inside a container.
As long as the underlying data volume is reliable, it really doesn't matter whether you're running it outside of a container or not. Volumes for K8s have a come a long way since its early days.
and the answer is we will definitely be running DBs in clustered mode in the future. its not really a debate its an eventuality.
without clusters you lose on reliability and maintenance QOL improvements. without clusters its very hard to upgrade systems effectively leaving systems to stagnate and decay both in performance (Hard/Software improvements aka kernel updates or inbternal DB improvements) and reliability.
And now almost all databases (meaning running instances, not software artifacts) are way slower than necessary and lie about durability.
now, that's a bit of a stretch, no?
I think this is a good ops team mantra. PostgreSQL unless you have a very good reason otherwise, and k8s unless you have a very good reason otherwise.
Decisions like this allow for economies of scale with tooling, monitoring/observability, etc.
Saying no to snowflakes is an important part of having a good ops team.
https://cloud.google.com/config-connector/docs/reference/res...
https://aws-controllers-k8s.github.io/community/reference/rd...
A small database might be just $5 per month if its a thin slice of a big shared Kubernetes pie.
Or it could be $500K per month if it's a huge set of replicated server storing petabytes, replicated for dev, test, and prod.
I still think it's best to allow K8s to coordinate ephermeral containers with little to no persistent storage and let the DBs be run more traditionally.
Shameless plug: if you want to start running your own PostgreSQL with SSL, SELinux, automatic system updates, attached storage, and more... I have a simple demo as part of https://deploymentfromscratch.com/.
If I understand how it works, allocating memory to a container does not allocate memory for caching of data, and any IO done by any container can eject data from the cache, which means any IO intensive process will step on any other.
Zalando seems to fit the Zalando use case (not surprisingly), which is having multiple teams self-service their postgres clusters. They have a nice Web ui that is good for people who are not familiar with k8 to provision databases. However a lot of those features are a bit intrusive when you want to start a small project. The "teams" attributes are required in the clusters, for example, although you're not using them.
I ended up using Cruncy for my personal project because its a bit simpler, looked like having a bit more activity on Github, and slightly better documentation from my perspective.
Usually if it's a stateless app then the solution is using a global load balancer or other networking at the edge to steer traffic to the responsive regions. Databases also tend to have their own replication and distribution strategies handled internally that should be used, along with the above mentioned networking.
these manifests can be targeted with a Service.
However my preferred solution for databases inside k8s is still zalando-operator with spilo and local storage. it's rock solid. I once used kubedb and lost the database because of bugs, so I'm staying away from them. Crunchy looks solid aswell but it looks like it's a little bit more polished but harder to configure than zalando's solution which is more built to their needs.
You're suggesting that next time they should demonstrate Postgres on Kubernetes without the distracting Kubernetes part?