Live data from Hacker News

Self-hosting a high-availability Postgres cluster on Kubernetes

ryan-schachte.com

51–60 of 92 posts

Re: Self-hosting a high-availability Postgres cluster on Kubernetes

#51

dumb question - where is the storage kept?

OP here. Currently I am using Longhorn on this cluster which does data replication on SSDs attached directly to the nodes. My backlog item is to run an external NAS with RAID. In this post specifically, the replication is handled by Zalando and not Longhorn, but the storage itself is on each node (specified by the node selector).

Re: Self-hosting a high-availability Postgres cluster on Kubernetes

#52

dumb question - where is the storage kept?

Me who have never used kubernetes, what if node crash ? Will I lost everything ?

I think people over think how hard this actually is. Data replication isn't a new concept. You can use RAID with a NAS or setup async replication with operators for things like Postgres/SQL.

Obviously it's worth doing simulated disaster recovery to ensure you would recover if there is hardware failure. The larger the scale and throughput with parallel writes against the same keys, etc then the more complicated the setup will be. I hope to write more on this topic, but setting up a persistent volume with a NAS is a great way to ensure high durability.

Re: Self-hosting a high-availability Postgres cluster on Kubernetes

#53
post #28

dumb question - where is the storage kept?

The author mentions Longhorn, a storage solution from the people behind the k3s distribution, so I’m assuming the data is stored in pvc provisioned through longhorn.

OP here. In general, yes! That is correct. I am using Longhorn with K3s, it's very slick and easy to get started with. In this case, I'm using multi-replica cluster with Zalando _only_.

Re: Self-hosting a high-availability Postgres cluster on Kubernetes

#54

Earlier quoted context omitted.

I've never been a fan of deploying DBs, either traditional RDBMS or distributed, under containerization/orchestration other than quickly spinning up dev and test environments. Certainly not for production. Databases have been built for high availability for many decades. Sure, maybe RDBMS doesn't scale quite as easily as a node API application, but it's still not really rocket science and you usually have some leeway…

Wouldn't most data driven, disk-IO intensive workloads be a bad fit for k8s? Especially when its not purely read-only.. That seems the crux of it.

This seems to be the common advise given, but I don't fully agree. There have been many times in my career where a DB was on a VM with the storage attached via a cloud providers block storage. When asked if we should move it to k8s, people are quick to mention k8s doesn't do well with persistent storage. However all of the big cloud providers offer the ability to easily create a persistent volume in k8s that then just creates a block device, attaches it to the k8s host and makes it available to the pod.

So in both situations you have the same IO limits of block storage. The question is does k8s persistent volume api add enough of an IO bottleneck to cause issues, IME that isn't the case.

Now if you want direct attached NVMe drives for higher IO than a network attached block storage will give, then it might be easier with a VM vs k8s, but I can't speak to that much.

Re: Self-hosting a high-availability Postgres cluster on Kubernetes

#55
post #17

Just like with cloud providers, it seems to me like with kubernetes, it is not a matter of if but when orchestration problems will arise. Specially in this case of hosting databases, a composition of provisioning complexities (db operational complexities on top of k8s operational complexities) is really scary. Is there any way to overcome hidden complexity biting your hand other than studying k8s extensively?

In the case of running Postgres on K8s, the problem arises immediately when you try to resize a data volume and you can't because the API doesn't support it. K8s is not really for stateful systems, yet, and systems like Postgres that prefer to manage their own resources, you don't want another layer which doesn't cooperate to get in your way.

> ...the problem arises immediately when you try to resize a data volume and you can't because the API doesn't support it

What API doesn't support it? k8s has support for resizing PVs and has for a while now. AFAIK all 3 cloud providers (and more) support increasing the PV using their storage class.

> K8s is not really for stateful systems, yet

Is this written somewhere or is it just your opinion?

Re: Self-hosting a high-availability Postgres cluster on Kubernetes

#56

Earlier quoted context omitted.

Honestly no, it's mostly due to inexperience with operators and not really understanding what the "best" way to find operators is. I did also look at the Crunch Data one (I was having some issues setting that one up), but didn't even find Zalando during my search. OperatorHub is currently the main resource I use, but GitHub stars aren't exposed in the search so I have been looking at the "Capability Level" chart and…

A subtle advantage of cnpg is that it doesn't use statefulsets, instead the operator handles things like mapping storage volumes and stable identities. Regular kubernetes statefulsets have some tricky sharp edges for failure recovery. I don't know if all of these alternatives use statefulsets but I remember several doing so. I've personally found cnpg to be pretty robust, and supports everything you will eventually n…

What sharp edges are you referring to with statefulsets?

Re: Self-hosting a high-availability Postgres cluster on Kubernetes

#57
post #10

Is Kubernetes still hard in 2024?

IME yes, yes it is. I usually tell people running a k8s cluster is similar to running your own "cloud". If you want to just deploy an EC2 instance you just tell AWS you want an EC2 instance and you are done (mostly). You don't have to worry about if the hardware under the EC2 VM has enough resources, you do have to worry about that with k8s though. If you want to lock down the EC2 VM to have certain permissions you use AWS IAM, with k8s you have to use cluster roles and cluster role bindings. You can apply these 2 examples to many other things in k8s vs "cloud" provider, Ingress, persistent volumes, etc.

Re: Self-hosting a high-availability Postgres cluster on Kubernetes

#58

dumb question - where is the storage kept?

All the cloud providers offer a storage class for k8s. The storage class allows you to tell k8s that you want a persistent volume (PV) and it will make API calls to the cloud provider to get you a block storage device. You can tell k8s you want to use that PV in your pod and k8s will automatically mount the block storage to the worker node that your pod lives on and makes it available to the pod.

OP uses Longhorn which is a whole other thing that I've only read about.

For at home you can use other storage classes like ceph, NFS, etc.

Re: Self-hosting a high-availability Postgres cluster on Kubernetes

#59
post #10

Is Kubernetes still hard in 2024?

It really depends on the design of the workload. Kubernetes makes orchestration more simple, but it doesn't remove all of the complexity of orchestrating something.

If you don't need much orchestration (which is true for a lot of postgres users), the complexity from kubernetes is compounded on top of the complexity from postgres without generating much value.

Re: Self-hosting a high-availability Postgres cluster on Kubernetes

#60

Earlier quoted context omitted.

A subtle advantage of cnpg is that it doesn't use statefulsets, instead the operator handles things like mapping storage volumes and stable identities. Regular kubernetes statefulsets have some tricky sharp edges for failure recovery. I don't know if all of these alternatives use statefulsets but I remember several doing so. I've personally found cnpg to be pretty robust, and supports everything you will eventually n…

What sharp edges are you referring to with statefulsets?

Cnpg's docs articulate this better than I could: https://cloudnative-pg.io/documentation/1.16/controller/

Statefulsets have their place but are surprisingly inconvenient for database workloads.

Post reply on HN