简体   繁体   中英

How kubernetes service work in case of Database (mysql)?

I'm new to k8 and i would like to create a mysql k8 service.

So my question is, if i create a k8 service with multiple pods which has mysql database, how the data will be inserted and also how fetch request processed?

  • will all the records will be synchronized to all pods?
  • while fetching will it collect records from all pods?

after little bit of googling i came to know that some load balancing kinda thing is happening in background...so suppose if a record is saved to mysql database which is in pod1 and for the http get request will to go for pod2 for get the record?

so how something like this will workout?

在此处输入图像描述

You should use a StatefulSet for this purpose. Statefulsets include the ability to specify a pod to reach through the service using the internal DNS. An example of this using a statefulset called mysql being exposed using a service called mysql in the default namesapce, you can reach a specific pod (such as the master for writes) using mysql-0.mysql.default.svc.cluster.local

There is actually a statefulset example that uses mysql specifically on kubernetes.io. This example leverages the properties of the statefulset to ensure that pod-0 will be your master so you can reliably send writes to it and send read requests to one of the read-only servers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM