How is a managed databased accessed by a Kubernetes cluster?

1 comment
  • As a stateful program, we can deploy a database at Kubernetes. They normally have their own storage when we deploy pods, but that storage is ephemeral - if the container loses its storage, it’s gone with it.

    So we’ll have a Kubernetes object to tackle that scenario: we connect a pod with a corresponding persistent volume argument when we want our data to persist. Through doing it this way, it will be in the cluster if our container destroys our data, and the new pod will access the data accordingly.
    You can also go through this tutorial to understand in detail: https://www.loginradius.com/blog/async/understanding-kubernetes/

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.

×
Submit an Answer
1 answer

Hi there @robDolphin,

What I would usually do is store my database details like hostname, password, username, port and etc. in a Kubernetes secret. Then I would add those database details to my deployment yaml file as environment variables.

The exact environment variables would depend on what kind of application you have.

For example, if you are using Laravel, you could follow the steps on how to do that here:

https://www.digitalocean.com/community/tutorials/how-to-deploy-laravel-7-and-mysql-on-kubernetes-using-helm

Regards,
Bobby

by Karl Hughes
In this guide, you will create a Laravel PHP application, build your app into a Docker image, and deploy that image to a DigitalOcean Kubernetes cluster using the LAMP Helm chart. Next, you'll set up an Ingress controller to add SSL and a custom domain name to your app. When completed, you will have a working Laravel application connected to a MySQL database that is running on a Kubernetes cluster.