Hello everyone! Currently, I have a Kubernetes Cluster with a pool containing 3 nodes. (The default option when creating a cluster). A total cluster capacity of 150GB of disk and 6GB of memory.
I’ve installed kubectl on my machine and pushed an image to it… (A .net Core API with a mySql database)… The .NET Api is working, but right now it can’t connect to a mysql database yet, because I need to make it works… And here comes my questions:
1- I can replicate this .net API, but I obviously can’t create “copies” of the database, it must be one, being accessed by all .net copies. How can I achieve that? Do I need to create a “Volume” to this .mysql database?
2- I will need to store the uploaded files of my .net project (are basically images and .pdf, nothing else). Can I store them on this 150GB of disk in my pool, or do I need to create a separate volume to store these uploaded images and PDF?
Thank you in advance!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
The problem with volumes is that you can only attach a volume to one pod at a time. So if you have two or three instances of your .net app, they’ll have to have separate copies of your data.
Object store can be Digital ocean spaces, but it could also be S3 or Azure Blob Storage.
I spent a good 45 minutes answering this question yesterday, but the system marked it as spam :-(
But to summarise:
Hello,
you need:
some ideas:
Secrets
MySQL volume
My App Volume
MySQL Deployment
MySQL ClusterIP Service
My App Service
This manifest could give you an idea. I hope you find this information useful.
The arrangement you are probably looking for is for your multiple .net API instances to connect to the same database
Normally in Kuberentes, you create a service that maps to your MySQL cluster. Then, in .net, you can use the service name as the hostname to connect to. Basically what happens is that hostname resolves to the IP address of your MySQL server.
There is one thing I’m not super familiar with in a MySQL setup. Normally, if you have three MySQL servers, one is the master and the other two are read-only duplicates. I’m not sure how to handle this scenario in Kubernetes.
I would recommend considering the following alternatives to running your own MySQL service in Kubernetes:
Mounted volumes don’t sound like a good solution for what you’re trying to do. The problem is that you can only mount a volume to one pod at a time, so you’d have to implement replicating data to all volumes when you have multiple instances of your .net app.
I recommend looking into object stores such as Digital Ocean’s “Spaces”, or Amazon S3 or Azure Blob Storage. All of these are great solutions if you need a large amount of “disk” space to be shared by your different service instances. They’re also cheaper than volumes.