Tom Nolan
Tom Nolan

Reputation: 1

Flask, Google Kubernete Cluster + Docker

I have an issue right now where I'm really not sure what's going on. On Google Cloud I have a cluster that contains two instances. Using Kubernetes I have 2 pods running, one on each machine. When I go to log into the application (using the ExternalIP of the LoadBalancer service) with a persisted user sometimes it just straight up fails to do so and redirects to my homepage. Other times it will log me in.

If however, I scale my application down to a single VM and one pod it works okay and will sign me in every time. Because of this I don't think it's an issue with Flask i.e my application, but something else. It's like when I try to sign in I'm on one machine and when I execute the request the load-balancer picks the other machine and it fails to sign me in, then sometimes it lucks out and gets the same one twice in a row. I don't really even know if that's something that's really even possible, it just what it seems like to me, but then again I'm quite new to all this.

https://github.com/tnolan8/CA674-Cloud-Architecture -> this is the repo which contains my application + my deployment scripts.

This is my actual deployment script: deployment.yml

I'm at a loss as to what might actually be causing this. Any thoughts?

Upvotes: 0

Views: 271

Answers (1)

iamnat
iamnat

Reputation: 4166

TL;DR It seems like you're using sqlalchemy to store your 'database' state on disk.

You should create a database deployment and change your config to use that database instead.

Details:

  1. When you're using containers that you want to scale up and down you shouldn't use the disk because different containers will have different state (container1 thinks you're logged in, container2 thinks you're not because it's disk does not have that data)
  2. Containers should be resilient to frequent restarts. This means that you should not store anything on disk that you'll need after you restart. If you really need to, you should look at persistent volumes for your containers. However, PVs need to be used carefully when you need to change the number replicas that your containers are using frequently.

Upvotes: 1

Related Questions