简体   繁体   English

kubernetes 服务在数据库(mysql)的情况下如何工作?

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

I'm new to k8 and i would like to create a mysql k8 service.我是 k8 新手,我想创建一个 mysql k8 服务。

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?所以我的问题是,如果我创建一个具有多个 Pod 的 k8 服务,该 Pod 具有 mysql 数据库,数据将如何插入以及如何处理获取请求?

  • will all the records will be synchronized to all pods?所有记录都会同步到所有 pod 吗?
  • while fetching will it collect records from all pods?在获取时它会从所有 pod 中收集记录吗?

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?经过一点谷歌搜索后,我才知道在后台发生了一些负载平衡......所以假设如果记录保存到 pod1 中的mysql数据库中,对于http获取请求将发送到 Z34D1F91FB2E514B9Apod6B76记录?

so how something like this will workout?那么这样的事情将如何锻炼呢?

在此处输入图像描述

You should use a StatefulSet for this purpose.为此,您应该使用StatefulSet Statefulsets include the ability to specify a pod to reach through the service using the internal DNS.状态集包括使用内部 DNS 指定要通过服务访问的 pod 的能力。 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使用名为 mysql 的 statefulset 的示例在默认命名空间中使用名为 mysql 的服务公开,您可以使用 mysql-0.Z81C3B080Ds987AD534DE27EZAFE 访问特定的 pod(例如用于写入的主节点)。

There is actually a statefulset example that uses mysql specifically on kubernetes.io.实际上有一个statefulset 示例,它专门在 kubernetes.io 上使用 mysql。 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.此示例利用 statefulset 的属性来确保 pod-0 将成为您的主服务器,因此您可以可靠地向它发送写入并将读取请求发送到其中一个只读服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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