How to scale a webapp in GCP using Kubernetes

12/12/2019

I recently started to look at GKE. Lets assume we have a basic web application (back-end and front end)

The front end connects to the back-end trough a NGINX LB, so if you need more power you scale the PODs and the LB distributes the load between the nodes and its works perfectly, so my question is, what happens if you inside your container have the DB ? when you scale the Kubernetes cluster it will create a db for each of the nodes, correct ? In that case it will be a problem ? so that being said how it is used in the market these days, I would assume you put in a container only the backend and use another service from the cloud provider to store the data so in that way the service can get requests from all the containers and there wont be data discrepancy .

-- André De La O Campos
google-cloud-platform
google-cloud-storage
google-kubernetes-engine
kubernetes

2 Answers

12/12/2019

You answered yourself already. Most people run frontends and backends in containers and use (for google for example) Cloud SQL, Datastore or BigQuery to store the data.

-- tclass
Source: StackOverflow

12/12/2019

Most backend applications rely on the DB to save the state. So the code is stateless and can be scaled without further considerations on the state or the data.

You can run the DB on kubernetes. There is a big 'however' though. It is necessary to follow some rules because pods are mortal and this requires further management.

The data from the DB in kubernetes will have to be always backed by a persistent disk to which the pods will connect to.

Moreover, not all DB are kubernetes-friendly (E.g.: MySQL, PostgreSQL) and it is necessary to use a Kubernetes Operators to wrap the DB in those cases.

What happens if you put a DB container inside a POD? Each node in the cluster will have many different pods running at the same time. When you go for the Kubernetes DB solution it is necessary to put a DB container on a pod. Having a pod with the backend container and the DB container is not a good approach.

When you scale the Kubernetes cluster it will create a db for each of the nodes? The scaling unit in Kubernetes is the pod, not the container. When the load increases, the number of nodes in the clusters, and total number of deployed pods increases for that service.

More information about this topic is covered in the Google Kubernetes Engine documentation. A guide to deploy a DB on Kubernetes can be found here.

-- Juancki
Source: StackOverflow