Yuav ua li cas los tsim ib tug hybrid huab siv Kubernetes uas tuaj yeem hloov DBaaS

Kuv lub npe yog Petr Zaitsev, Kuv yog CEO, tus tsim percona thiab kuv xav qhia rau koj:

  • yuav ua li cas peb tuaj ntawm qhib qhov kev daws teeb meem rau Database raws li Kev Pabcuam;
  • dab tsi mus kom ze muaj nyob rau deploying databases nyob rau hauv huab;
  • Yuav ua li cas Kubernetes tuaj yeem hloov DBaaS, tshem tawm cov neeg muag khoom kev vam khom thiab tswj qhov yooj yim ntawm DBMS raws li kev pabcuam.

Tsab ntawv tau npaj los ntawm tsab ntawv ceeb toom ntawm @Databases Meetup los ntawm Mail.ru Huab Solutions & Tarantool. Yog tias koj tsis xav nyeem, koj tuaj yeem saib:


Yuav ua li cas peb tuaj ntawm qhib qhov chaw rau Database raws li Kev Pabcuam hauv huab

Kuv tau ua haujlwm hauv qhov chaw qhib txij li xyoo 90s lig. Nees nkaum xyoo dhau los, siv qhov chaw qhib, xws li databases, tsis yooj yim li. Nws yog tsim nyog mus download tau qhov chaws code, patch nws, compile nws thiab tsuas yog ces siv nws.

Qhib qhov chaw ces mus los ntawm ib tug series ntawm simplifications:

  • Tar.gz thiab INSTALL qhov chaw uas yuav tsum tau muab tso ua ke;
  • tej pob khoom nrog dependencies zoo li .deb thiab .rpm, qhov twg koj tsuas yog yuav tsum tau nruab ib txheej ntawm pob khoom;
  • pob repositories zoo li APT thiab YUM, nrog rau qhov kev teeb tsa tsis siv neeg;
  • cov kev daws teeb meem xws li Docker thiab Snap, uas tso cai rau koj kom tau txais cov pob khoom los ntawm kev teeb tsa yam tsis muaj kev cuam tshuam sab nraud.

Yog li ntawd, nws yooj yim dua los siv qhib qhov software thiab tseem txo qis qhov cuam tshuam rau kev nkag mus rau hauv kev tsim cov ntawv thov.

Tib lub sijhawm, tsis zoo li qhov xwm txheej 20 xyoo dhau los, thaum txhua tus yog tus kws tshaj lij kev sib dhos, tam sim no cov neeg tsim khoom feem ntau tsis tuaj yeem tsim cov cuab yeej uas lawv siv los ntawm qhov chaw.

Qhov tseeb, qhov no tsis yog qhov phem, vim tias:

  1. Peb tuaj yeem siv ntau qhov nyuaj tab sis ntau tus neeg siv-phooj ywg software. Piv txwv li, lub browser yooj yim siv, tab sis nws suav nrog ntau qhov chaw qhib thiab tsis yooj yim los tsim los ntawm kos.
  2. Ntau tus neeg tuaj yeem dhau los ua tus tsim tawm ntawm qhov qhib thiab lwm yam software, ntau software yog siv los ntawm cov lag luam, thiab kev xav tau ntau dua.

Lub downside yog tias cov kauj ruam tom ntej hauv kev yooj yim yog txuam nrog kev siv huab kev daws teeb meem, thiab qhov no ua rau qee tus neeg muag khoom kaw-hauv, uas yog, khi rau ib tus neeg muag khoom. Peb siv cov kev daws teeb meem yooj yim thiab cov neeg muab kev pabcuam siv cov khoom siv qhib, tab sis qhov tseeb lawv raug ntsia rau ib qho ntawm cov huab loj. Ntawd yog, txoj hauv kev yooj yim tshaj plaws thiab ceev tshaj plaws los siv qhib qhov chaw (thiab software sib xws nrog nws) yog nyob rau hauv huab, siv tus tswv API.

Thaum nws los txog rau databases hauv huab, muaj ob txoj hauv kev:

  1. Sib sau cov database infrastructure, xws li nyob rau hauv ib tug niaj hnub data center. Ntawd yog, coj cov qauv tsev thaiv: suav, khaws cia, thiab lwm yam, nruab Linux thiab database rau lawv, thiab teeb tsa lawv.
  2. Siv Database ua Kev Pabcuam, qhov twg tus kws kho mob muab cov ntaub ntawv npaj ua tiav hauv huab.

DBaaS yog kev lag luam loj hlob sai tam sim no vim nws tso cai rau cov neeg tsim khoom ua haujlwm ncaj qha nrog cov ntaub ntawv thiab txo qis kev ua haujlwm niaj hnub. Tus kws zov me nyuam tau ua los xyuas kom ntseeg tau tias muaj peev xwm txaus thiab yooj yim me me, database posting, thaub qab, thiab kho kom zoo.

Ob hom Database ua Kev Pabcuam raws li qhib qhov chaw thiab lwm txoj hauv kev ntawm Kubernetes

Muaj ob hom Database ua Kev Pabcuam rau qhib databases:

  1. Tus qauv qhib qhov khoom ntim rau hauv kev tswj hwm backend kom yooj yim xa mus thiab tswj.
  2. Kev lag luam zoo tshaj plaws nrog ntau yam add-ons, sib xws nrog qhib qhov chaw.

Ob qho kev xaiv txo qhov muaj peev xwm ntawm kev tsiv teb tsaws ntawm huab thiab txo qhov kev txav ntawm cov ntaub ntawv thiab kev siv. Piv txwv li, txawm hais tias muaj ntau hom huab txhawb qhov tseem ceeb ntawm tib tus qauv MySQL, muaj qhov sib txawv tseem ceeb ntawm lawv: hauv kev ua haujlwm, kev ua haujlwm, thaub qab, thiab lwm yam. Kev tsiv teb tsaws ntawm ib huab mus rau lwm qhov tuaj yeem nyuaj, tshwj xeeb tshaj yog rau cov ntawv thov nyuaj.

Thiab ntawm no cov lus nug tshwm sim - nws puas tuaj yeem tau txais kev yooj yim ntawm Database raws li Kev Pabcuam, tab sis raws li qhov yooj yim qhib qhov kev daws teeb meem?

Cov xov xwm phem yog tias, hmoov tsis, tsis muaj cov kev daws teeb meem zoo li no hauv kev ua lag luam. Qhov xwm zoo yog tias muaj Kubernetes, uas tso cai rau koj los siv cov kev daws teeb meem zoo li no.

Kubernetes yog ib qho kev khiav hauj lwm rau huab lossis cov chaw zov me nyuam uas tso cai rau koj siv thiab tswj cov ntawv thov thoob plaws ntau lub servers hauv pawg ntau dua li ntawm ib tus tswv tsev.

Tam sim no Kubernetes yog tus thawj coj hauv qeb ntawm cov software zoo li no. Muaj ntau ntau yam kev daws teeb meem rau cov teeb meem zoo li no, tab sis nws tau dhau los ua tus qauv. Ntau lub tuam txhab uas siv los tsom rau lwm txoj kev daws teeb meem tam sim no tsom rau kev hloov kho lawv cov khoom los txhawb Kubernetes.

Tsis tas li ntawd, Kubernetes yog ib qho kev daws teeb meem thoob ntiaj teb uas tau txais kev txhawb nqa hauv cov huab ntiag tug, pej xeem thiab huab cua sib xyaw ntawm ntau tus neeg muag khoom, piv txwv li: AWS, Google Huab, Microsoft Azure, Mail.ru Huab Solutions.

Kubernetes ua haujlwm li cas nrog databases

Kubernetes yog tsim los rau cov ntawv thov tsis muaj lub xeev uas ua cov ntaub ntawv tab sis tsis khaws ib yam dab tsi, xws li microservices lossis web applications. Databases yog nyob rau lwm qhov kawg ntawm lub spectrum, uas yog, lawv yog cov ntaub ntawv siv tau. Thiab Kubernetes tsis yog thawj zaug npaj rau cov ntawv thov no.

Txawm li cas los xij, muaj cov yam ntxwv uas tau tshwm sim hauv Kubernetes tsis ntev los no uas tso cai rau siv cov ntaub ntawv thiab lwm yam kev siv hauv xeev:

  1. Lub tswv yim StatefulSet yog tag nrho cov txheej txheem tseem ceeb rau kev ua cov txheej xwm hais txog kev txwv kev ua haujlwm ntawm cov pods thiab siv Graceful Shutdown (kwv yees kaw ntawm daim ntawv thov).
  2. Persistent Volumes yog cov ntaub ntawv khaws cia uas cuam tshuam nrog cov pods, Kubernetes tswj cov khoom.
  3. Operator Framework - uas yog, muaj peev xwm los tsim cov khoom siv rau kev tswj hwm cov ntaub ntawv thiab lwm yam kev siv hauv xeev tau muab faib thoob plaws ntau qhov.

Tam sim no nyob rau hauv pej xeem huab muaj cov Databases loj raws li Kev Pabcuam, cov backend uas yog Kubernetes, piv txwv li: CockroachCloud, InfluxDB, PlanetScale. Ntawd yog, lub chaw khaws ntaub ntawv ntawm Kubernetes tsis yog tsuas yog qee yam uas muaj peev xwm ua tau, tab sis kuj yog qee yam uas ua haujlwm hauv kev xyaum.

Percona muaj ob qhov kev daws teeb meem qhib rau Kubernetes:

  1. Kubernetes Operator rau Percona Server rau MongoDB.
  2. Kubernetes Operator rau XtraDB CLUSTER yog ib qho kev pabcuam uas sib xws nrog MySQL thiab muab cov khoom muaj thiab sib xws. Koj tuaj yeem siv ib qho ntawm ib qho yog tias tsis xav tau muaj ntau, piv txwv li rau dev database.

Cov neeg siv Kubernetes tuaj yeem muab faib ua ob pawg. Qee cov neeg siv Kubernetes Cov Neeg Ua Haujlwm ncaj qha - cov no yog cov neeg siv siab heev uas muaj kev nkag siab zoo txog kev siv tshuab ua haujlwm li cas. Lwm tus khiav nws ntawm lub backend - xws li cov neeg siv txaus siab rau ib yam dab tsi zoo li Database li Kev Pabcuam, lawv tsis xav delve rau hauv cov nuances ntawm Kubernetes. Rau pab pawg thib ob ntawm cov neeg siv, peb muaj lwm qhov kev daws teeb meem qhib - Percona DBaaS CLI Tool. Qhov no yog kev sim tshuaj rau cov neeg uas xav kom tau txais qhov qhib DBaaS raws li Kubernetes yam tsis muaj kev nkag siab tob txog kev siv tshuab.

Yuav ua li cas khiav Percona's DBaaS ntawm Google Kubernetes Cav

Google Kubernetes Cav, hauv kuv lub tswv yim, yog ib qho kev ua haujlwm zoo tshaj plaws ntawm Kubernetes thev naus laus zis. Nws muaj nyob rau hauv ntau thaj tsam ntawm lub ntiaj teb no thiab muaj qhov yooj yim thiab yooj yim rau Command Line Tool (SDK), uas tso cai rau koj los tsim cov ntawv sau ntau dua li kev tswj hwm lub platform.

Txhawm rau kom peb DBaaS ua haujlwm, peb xav tau cov hauv qab no:

  1. Kubectl.
  2. Google Cloud SDK.
  3. Percona DBaaS CLI.

Install kubectl

Peb nruab lub pob rau koj lub operating system, peb yuav saib cov piv txwv ntawm Ubuntu. Paub meej ntxiv S, SΡ“S,.

sudo apt-get update && sudo apt-get install -y apt-transport-https gnupg2
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl

Txhim kho Google Cloud SDK

Peb nruab lub software pob nyob rau hauv tib txoj kev. Paub meej ntxiv S, SΡ“S,.

# Add the Cloud SDK distribution URI as a package source
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] 
http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

# Import the Google Cloud Platform public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -

# Update the package list and install the Cloud SDK
sudo apt-get update && sudo apt-get install google-cloud-sdk

Txhim kho Percona DBaaS CLI

Nruab los ntawm Percona repositories. Percona DBaaS CLI Tool tseem yog ib qho kev sim khoom, yog li nws nyob hauv qhov chaw sim, uas yuav tsum tau qhib nyias, txawm tias koj twb muaj Percona repositories ntsia.

Nyeem ntxiv S, SΡ“S,.

Installation algorithm:

  1. Teeb tsa Percona repositories siv lub cuab yeej percona-tso. Ua ntej koj yuav tsum rub tawm thiab nruab lub official percona-tso pob los ntawm Percona:
    wget https://repo.percona.com/apt/percona-release_latest.generic_all.deb
    sudo dpkg -i percona-release_latest.generic_all.deb
  2. Ua kom qhov kev sim cov cuab yeej repository tivthaiv raws li hauv qab no:
    sudo percona-release enable tools experimental
    
  3. Nruab percona-dbaas-cli pob:
    sudo apt-get update
    sudo apt-get install percona-dbaas-cli

Teeb tsa kev ua haujlwm ntawm cov khoom siv

Xav paub ntxiv txog kev teeb tsa S, SΡ“S,.

Ua ntej koj yuav tsum nkag mus rau hauv koj tus account Google. Tsis tas li ntawd, Google Cloud tso cai rau ib tus neeg siv kom muaj ntau txoj haujlwm ywj pheej, yog li koj yuav tsum tau qhia txog kev ua haujlwm uas siv cov cai rau txoj haujlwm no:

gcloud auth login
gcloud config set project hidden-brace-236921

Tom ntej no, peb tsim ib pawg. Rau qhov demo, kuv tsim Kubernetes pawg ntawm tsuas yog peb lub nodes - qhov no yog qhov tsawg kawg nkaus uas yuav tsum tau muaj rau siab:

gcloud container clusters create --zone us-central1-a your-cluster-name --cluster-version 1.15 --num-nodes=3

Cov lus txib kubectl hauv qab no muab cov cai xav tau rau peb cov neeg siv tam sim no:

kubectl create clusterrolebinding cluster-admin-binding-$USER 
--clusterrole=cluster-admin --user=$(gcloud config get-value core/account)

Tom qab ntawd peb tsim lub namespace thiab ua kom nws nquag. Namespace yog, kwv yees hais lus, kuj zoo li qhov project lossis ib puag ncig, tab sis twb nyob hauv Kubernetes pawg. Nws yog ywj siab los ntawm Google Cloud tej yaam num:

kubectl create namespace my-namespace
kubectl config set-context --current --namespace=my-namespace

Pib lub pawg

Thaum peb tau dhau los ntawm ob peb kauj ruam no, peb tuaj yeem pib peb-node pawg nrog cov lus txib yooj yim no:

# percona-dbaas mysql create-db example
Starting ......................................... [done]
Database started successfully, connection details are below:
Provider:          k8s
Engine:            pxc
Resource Name:     example
Resource Endpoint: example-proxysql.my-namespace.pxc.svc.local
Port:              3306
User:              root
Pass:              Nt9YZquajW7nfVXTTrP
Status:            ready

Yuav ua li cas txuas mus rau ib pawg

Los ntawm lub neej ntawd, nws tsuas yog muaj nyob hauv Kubernetes. Ntawd yog, nws tsis tuaj yeem siv tau los ntawm cov neeg rau zaub mov no uas koj tau khiav "Tsim" hais kom ua. Txhawm rau ua kom muaj, piv txwv li, rau kev sim nrog tus neeg siv khoom, koj yuav tsum xa mus rau qhov chaw nres nkoj los ntawm Chaw Nres Nkoj:

kubectl port-forward svc/example-proxysql 3306:3306 $

Tom qab ntawd peb txuas koj tus neeg siv MySQL:

mysql -h 127.0.0.1 -P 3306 -uroot -pNt9YZquajW7nfVXTTrP

Advanced cluster tswj commands

Database ntawm pej xeem IP

Yog tias koj xav tau kev daws teeb meem ntau dua rau kev muaj nyob hauv pawg, koj tuaj yeem tau txais qhov chaw nyob IP sab nraud. Hauv qhov no, lub database yuav nkag tau los ntawm txhua qhov chaw. Qhov no tsis tshua muaj kev ruaj ntseg, tab sis feem ntau yooj yim dua. Rau sab nraud IP peb siv cov lus txib hauv qab no:

# percona-dbaas mysql create-db exposed 
--options="proxysql.serviceType=LoadBalancer"
Starting ......................................... [done]
Database started successfully, connection details are below:
Provider:          k8s
Engine:            pxc
Resource Name:     exposed
Resource Endpoint: 104.154.133.197
Port:              3306
User:              root
Pass:              k0QVxTr8EVfgyCLYse
Status:            ready

To access database please run the following command:
mysql -h 104.154.133.197 -P 3306 -uroot -pk0QVxTr8EVfgyCLYse

Qhia meej tus password

Es tsis txhob lub kaw lus random tsim tus password, koj tuaj yeem teeb tus password kom meej:

# percona-dbaas mysql create-db withpw --password=mypassword
Starting ......................................... [done]
Database started successfully, connection details are below:
Provider:          k8s
Engine:            pxc
Resource Name:     withpw
Resource Endpoint: withpw-proxysql.my-namespace.pxc.svc.local
Port:              3306
User:              root
Pass:              mypassword
Status:            ready

Kuv tabtom qhia cov ntawv tso tawm ntawm cov ntawv sau rau tib neeg nyeem tau, tab sis JSON hom kuj tau txais kev txhawb nqa.

Tig tawm qhov muaj txaus

Nrog rau cov lus txib hauv qab no koj tuaj yeem lov tes taw siab kom xa mus rau ib qho ntawm:

# percona-dbaas mysql create-db singlenode 
--options="proxysql.enabled=false, allowUnsafeConfigurations=true,pxc.size=1"
Starting ......................................... [done]
Database started successfully, connection details are below:
Provider:          k8s
Engine:            pxc
Resource Name:     singlenode
Resource Endpoint: singlenode-pxc.my-namespace.pxc.svc.local
Port:              3306
User:              root
Pass:              22VqFD96mvRnmPMGg
Status:            ready

Qhov no yog kev daws teeb meem rau kev sim ua haujlwm kom tau txais MySQL nce thiab khiav sai thiab yooj yim li sai tau, sim nws, thiab tom qab ntawd quav nws lossis siv nws rau kev txhim kho.

Cov cuab yeej Percona DBaaS CLI pab koj ua tiav DBaaS zoo li kev daws teeb meem ntawm Kubernetes. Nyob rau tib lub sijhawm, peb txuas ntxiv ua haujlwm ntawm nws txoj haujlwm thiab kev siv tau.

Daim ntawv tshaj tawm no tau nthuav tawm thawj zaug ntawm @Databases Meetup los ntawm Mail.ru Huab Solutions & Tarantool. Saib video lwm yam kev ua yeeb yam thiab sau npe rau cov lus tshaj tawm ntawm Telegram Nyob ib ncig ntawm Kubernetes ntawm Mail.ru Group.

Lwm yam uas yuav tsum tau nyeem ntawm lub ncauj lus:

  1. Databases nyob rau hauv ib tug niaj hnub IIoT platform.
  2. Yuav ua li cas xaiv ib lub database rau ib qhov project yog li koj tsis tas yuav xaiv dua.

Tau qhov twg los: www.hab.com

Ntxiv ib saib