{"id":5976,"date":"2019-07-12T11:25:47","date_gmt":"2019-07-12T04:25:47","guid":{"rendered":"http:\/\/gcloudvn.wam.vn\/co-nen-chay-co-so-du-lieu-tren-kubernetes-hay-khongcan-xem-xet-nhung-diem-gi\/"},"modified":"2023-05-10T13:23:33","modified_gmt":"2023-05-10T06:23:33","slug":"co-nen-chay-co-so-du-lieu-tren-kubernetes-hay-khongcan-xem-xet-nhung-diem-gi","status":"publish","type":"post","link":"https:\/\/gcloudvn.com\/en\/kienthuc\/co-nen-chay-co-so-du-lieu-tren-kubernetes-hay-khongcan-xem-xet-nhung-diem-gi\/","title":{"rendered":"Whether to run a database on Kubernetes: what to consider"},"content":{"rendered":"<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-14423 size-full\" src=\"https:\/\/gcloudvn.com\/wp-content\/uploads\/2019\/07\/BlogHeader_Kubernetes_A.max-2200x2200.jpg\" alt=\"Whether to run a database on Kubernetes: what to consider 1\" width=\"2200\" height=\"917\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">More and more applications are deployed in the above containers <a href=\"https:\/\/gcloudvn.com\/en\/google-kubernetes-engine-gke\/\">Kubernetes<\/a> \u2014 so much so that we have heard that Kubernetes is called the Linux of the cloud. Although with such growth on the application layer, the data layer is not affected much by containerization. This is not surprising, as containerized workloads must be self-healing for restart, scaling, virtualization, and other constraints. So controlling things like state (database), availability for other layers of the application, and redundancy for a database can have a lot of specific requirements. These create challenges to run the database on a distributed environment.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">However, the data layer is getting more attention because many developers want to treat the data infrastructure as similar to the application stack. Operators want to use the same tools for databases and applications, and get the same benefits as application-layer at data-layer: rapid and repeatable volume growth between environments. In this article, Google will explore when and how this type of database can run efficiently on Kubernetes.<\/span><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/gcloudvn.com\/en\/kienthuc\/co-nen-chay-co-so-du-lieu-tren-kubernetes-hay-khongcan-xem-xet-nhung-diem-gi\/#Lua_chon_co_the_chay_co_so_du_lieu_tren_Google_Cloud_Platform\" >Option to be able to run the database on Google Cloud Platform<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/gcloudvn.com\/en\/kienthuc\/co-nen-chay-co-so-du-lieu-tren-kubernetes-hay-khongcan-xem-xet-nhung-diem-gi\/#Meo_de_chay_co_so_du_lieu_cua_ban_tren_Kubernetes\" >Tips for running your database on Kubernetes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/gcloudvn.com\/en\/kienthuc\/co-nen-chay-co-so-du-lieu-tren-kubernetes-hay-khongcan-xem-xet-nhung-diem-gi\/#Cach_trien_khai_co_so_du_lieu_tren_Kubernetes_bang_StatefulSets\" >How to Deploy Database on Kubernetes Using StatefulSets<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Lua_chon_co_the_chay_co_so_du_lieu_tren_Google_Cloud_Platform\"><\/span><strong>Option to be able to run the database on Google Cloud Platform<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Before we dig into the considerations for running a database on Kubernetes, let&#039;s take a look at the options we can run the database on. <\/span><a href=\"https:\/\/gcloudvn.com\/en\/google-cloud-platform\/\"><span style=\"font-weight: 400;\">Google Cloud Platform<\/span><\/a><span style=\"font-weight: 400;\"> (GCP) and what it uses best.<\/span><\/p>\n<ul style=\"text-align: justify;\">\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Fully managed databases: Including <\/span><span style=\"font-weight: 400;\">Cloud Spanner<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">Cloud Bigtable<\/span><span style=\"font-weight: 400;\"> and <\/span><a href=\"https:\/\/gcloudvn.com\/en\/cloud-sql\/\"><span style=\"font-weight: 400;\">Cloud SQL<\/span><\/a><span style=\"font-weight: 400;\">, among <\/span><span style=\"font-weight: 400;\">different things<\/span><span style=\"font-weight: 400;\">. This is a low autonomy option for you, as Google Cloud already controls all operational tasks, such as backups, upgrades, and expansions. As a developer or operator, you don&#039;t have to bother with them. You simply create your database, build your application, and let Google Cloud scale for you. This also means that you may not have access to the exact version of the database, the extension, or the exact control of the database that you want.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Do-it-yourself on a virtual machine: This can best be described as a fully self-hosted option where you will take full responsibility for building your database, scaling it, managing reliability trust, set up backups, and more. All of that can be a lot of work, but you have all the features and control of the database at your disposal.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Run the database on Kubernetes. Running a database on Kubernetes is closer to being self-sustaining, but you get some of the automation benefits that Kubernetes provides for maintaining database applications. That said, it&#039;s important to remember that pods (containers containing database applications) are transient, so the chances of a database application restart or failure are higher. Additionally, some of the other database-specific administrative tasks\u2014backup, scaling, tuning, etc.\u2014are different because of the added virtual layers that come with the container.<\/span><\/li>\n<\/ul>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Meo_de_chay_co_so_du_lieu_cua_ban_tren_Kubernetes\"><\/span><strong>Tips for running your database on Kubernetes<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">When choosing to go down the Kubernetes route, think about what database you&#039;ll be running, and how well it will perform given the trade-offs beforehand. Because pods are critical, the likelihood of failover events is higher than a traditionally fully managed or hosted database. It would be easier to run a database on Kubernetes if it included concepts like protection, self-selection, and replication built into its DNA (e.g. ElasticSearch, Cassandra or MongoDB). Some of the open source projects provide <\/span><span style=\"font-weight: 400;\">optional resources<\/span><span style=\"font-weight: 400;\"> and <\/span><span style=\"font-weight: 400;\">operators<\/span><span style=\"font-weight: 400;\"> to help with database management.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Next, consider the functionality the database is performing in the context of your application and business. The database is caching multiple layers of temporary and caching is more suitable for Kubernetes. Data layers of that type often have more resilience built into applications, which results in a better overall experience.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Finally, make sure you understand the replication modes available in the database. Asynchronous replication modes leave room for data loss, as transactions can be committed to the primary database but not to the secondary database(s). So be sure to understand whether you can tolerate data loss and how much is acceptable in the context of your application.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">After evaluating all of those considerations, you&#039;ll end up with a decision tree that looks something like this:<\/span><\/p>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-14429 size-full\" src=\"https:\/\/gcloudvn.com\/wp-content\/uploads\/2019\/07\/Tech_Diag_K8s_Database_Bl.0734067713421317.max-1500x1500.png\" alt=\"Whether to run a database on Kubernetes: what to consider\" width=\"1500\" height=\"1472\" \/><\/p>\n<p style=\"text-align: center;\"><em><span style=\"font-weight: 400;\">How to deploy a database on Kubernetes<\/span><\/em><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cach_trien_khai_co_so_du_lieu_tren_Kubernetes_bang_StatefulSets\"><\/span><strong>How to Deploy Database on Kubernetes Using StatefulSets<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Now, let&#039;s dig into more detail on how to deploy a database on Kubernetes using StatefulSets. With StatefulSet, your data can be stored on permanent blocks, separating the database application from the permanent storage, so when a pod (like a database application) is recreated , all the data is still there. Also, when a pod is recreated in a Statefulset, it will keep the same name, so you need a consistent endpoint to connect to. Persistent data and consistent naming are two of the biggest benefits of StatefulSets. You can check the <\/span><a href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/statefulset\/\" target=\"_blank\" rel=\"nofollow noopener\"><span style=\"font-weight: 400;\">detailed documentation about Kubernetes<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">If you need to run a database that doesn&#039;t fit the model of a Kubernetes-friendly database (like MySQL or PostgreSQL), consider using the Kubernetes driver or the projects that wrap the databases whether it by extra features. <\/span><span style=\"font-weight: 400;\">Drivers<\/span><span style=\"font-weight: 400;\"> will help you create those databases and perform database maintenance tasks such as backups and replication. For MySQL in particular, see Oracle MySQL Driver and Crunchy Data for PostgreSQL. .<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Drivers use the <\/span><span style=\"font-weight: 400;\">resources<\/span><span style=\"font-weight: 400;\"> and a custom controller to expose application-specific activities via the Kubernetes API. For example, to perform a backup using Crunchy Data, simply do <\/span><span style=\"font-weight: 400;\">pgo backup [cluster_name].<\/span><span style=\"font-weight: 400;\">To add a Postgres copy, use <\/span><span style=\"font-weight: 400;\">pgo scale cluster [cluster_name].<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">There are some other projects out there that you can explore such as <\/span><span style=\"font-weight: 400;\">Patroni<\/span><span style=\"font-weight: 400;\"> for PostgreSQL. These projects use drivers, but go a step further. They have built many tools around their respective databases to support their control operation inside Kubernetes. These may include additional features such as protection, leader election, and failover functionality required to successfully deploy MySQL or PostgreSQL in Kubernetes.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Although running a database in Kubernetes is making strides, it is still far from an exact science. There is a lot of work being done in this area, so watch out as technologies and tools evolve towards making it much more normal to run databases in Kubernetes.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">When you&#039;re ready to get started, watch <\/span><a href=\"https:\/\/console.cloud.google.com\/marketplace\/browse?filter=category%3Adatabase&amp;utm_source=blog&amp;utm_medium=k8sdatabase\" target=\"_blank\" rel=\"nofollow noopener\"><span style=\"font-weight: 400;\">GCP Marketplace<\/span><\/a><span style=\"font-weight: 400;\"> for easy deployment of SaaS, virtual machines, and driver and containerized database solutions that can be deployed on GCP or Kubernetes clusters anywhere.<\/span><\/p>\n<p style=\"text-align: right;\"><strong>Source: <a href=\"https:\/\/gcloudvn.com\/en\/\">Gimasys<\/a><\/strong><\/p>","protected":false},"excerpt":{"rendered":"<p>More and more applications are deployed in containers on Kubernetes \u2014 so much so that we&#039;ve heard Kubernetes is called the Linux of the cloud. Despite the growth on\u2026<\/p>","protected":false},"author":1,"featured_media":5977,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5976","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kienthuc","entry","has-media"],"_links":{"self":[{"href":"https:\/\/gcloudvn.com\/en\/wp-json\/wp\/v2\/posts\/5976","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gcloudvn.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gcloudvn.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gcloudvn.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gcloudvn.com\/en\/wp-json\/wp\/v2\/comments?post=5976"}],"version-history":[{"count":0,"href":"https:\/\/gcloudvn.com\/en\/wp-json\/wp\/v2\/posts\/5976\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gcloudvn.com\/en\/wp-json\/wp\/v2\/media\/5977"}],"wp:attachment":[{"href":"https:\/\/gcloudvn.com\/en\/wp-json\/wp\/v2\/media?parent=5976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gcloudvn.com\/en\/wp-json\/wp\/v2\/categories?post=5976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gcloudvn.com\/en\/wp-json\/wp\/v2\/tags?post=5976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}