Percona DBaaS CLI to Simplify Deployment in Kubernetes

栏目: IT技术 · 发布时间: 4年前

内容简介:We haveFirst of all, the tool assumes you have your Kubernetes cluster installed and running. For example, I will use Google Kubernetes Engine. For the local system, you will need to have Google Cloud SDK installed, and for the Ubuntu-based system (which I

Percona DBaaS CLI to Simplify Deployment in Kubernetes We recently released an experimental version of percona-dbaas command-line tool with the goal of significantly simplifying the deployment of database instances in Kubernetes.

We have Kubernetes Operators for Percona XtraDB Cluster and Percona Server for MongoDB , which provide great flexibility, but they also come with the complexity of managing configuration and deployment files, so we wanted to make it even simpler to deploy database instances. We found it hard enough to get a MySQL instance up and running in Kubernetes, and then a whole different process to get MongoDB up, and we thought it should be a unified set of commands. This is how the percona-dbaas CLI tool was born. You can get more information on installation of the percona-dbaas-cli tool and in this blog post, I wanted to review the basic functionality it provides.

1. Kubernetes Setup

First of all, the tool assumes you have your Kubernetes cluster installed and running. For example, I will use Google Kubernetes Engine. For the local system, you will need to have Google Cloud SDK installed, and for the Ubuntu-based system (which I used), the instructions are here .

After the initial setup, let’s make sure we have access to the cluster from kubectl and have enough nodes running:

kubectl get nodes
NAME                                       STATUS   ROLES    AGE    VERSION
gke-cluster-1-default-pool-43590ffc-4nbn   Ready    <none>   158m   v1.14.10-gke.24
gke-cluster-1-default-pool-43590ffc-9hd4   Ready    <none>   158m   v1.14.10-gke.24
gke-cluster-1-default-pool-43590ffc-n0tv   Ready    <none>   158m   v1.14.10-gke.24
gke-cluster-1-default-pool-43590ffc-qqdh   Ready    <none>   158m   v1.14.10-gke.24

And the extra permission grant step is needed for our Operators:

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

2. Basic Operations

As we have the Kubernetes cluster running, now there are basic operations to create database instances:

> percona-dbaas mysql create-db db-cluster1 
Starting.....................................[done]
Database started successfully, connection details are below:
Provider:          k8s
Engine:            pxc
Resource Name:     db-cluster1
Resource Endpoint: db-cluster1-proxysql.default.pxc.svc.local
Port:              3306
User:              root
Pass:              S4QN2Szz0f6oMML7
Status:            ready
 
To access database please run the following commands:
kubectl port-forward svc/db-cluster1-proxysql 3306:3306 &
mysql -h 127.0.0.1 -P 3306 -uroot -pS4QN2Szz0f6oMML7

The cluster was installed, and we can even access it with the mysql command line via kubectl port-forward.

Let’s see what was really deployed:

> kubectl get pods
NAME                                               READY   STATUS    RESTARTS   AGE
db-cluster1-proxysql-0                             3/3     Running   0          18m
db-cluster1-pxc-0                                  1/1     Running   0          18m
db-cluster1-pxc-1                                  1/1     Running   0          17m
db-cluster1-pxc-2                                  1/1     Running   0          16m
percona-xtradb-cluster-operator-7766bb49dc-x4zg7   1/1     Running   0          18m

So we can see we deployed three nodes of Percona XtraDB Cluster with ProxySQL running in front. And now if we access it from mysql command line:

> kubectl port-forward svc/db-cluster1-proxysql 3306:3306 &
> mysql -h 127.0.0.1 -P 3306 -uroot -pS4QN2Szz0f6oMML7
mysql: [Warning] Using a password on the command line interface can be insecure.
Handling connection for 3306
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 282
Server version: 5.7.28 (ProxySQL)
 
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> 

We see that we actually connected to the ProxySQL instances.

To destroy the cluster:

> percona-dbaas mysql delete-db db-cluster1 
ARE YOU SURE YOU WANT TO DELETE THE DATABASE 'db-cluster1'? Yes/No
ALL YOUR DATA WILL BE LOST. USE '--preserve-data' FLAG TO SAVE IT.
Yes
Deleting...............[done]

It’s a very similar step to create a MongoDB instance from the command line tool:

> percona-dbaas mongodb create-db db-cluster1 
Starting........................[done]
Database started successfully, connection details are below:
Provider:          k8s
Engine:            psmdb
Resource Name:     db-cluster1
Resource Endpoint: db-cluster1-rs0.default.psmdb.svc.local
Port:              27017
User:              clusterAdmin
Pass:              t3gzVf3KPt1Q5a27
Status:            ready
 
To access database please run the following commands:
kubectl port-forward svc/db-cluster1-rs0 27017:27017 &
mongo mongodb://clusterAdmin:t3gzVf3KPt1Q5a27@localhost:27017/admin?ssl=false

3. Extra Configuration

It is possible to customize the deployment with additional options .

Case 1:Deploy without ProxySQL:

> percona-dbaas mysql create-db db-cluster1  --options="proxysql.enabled=false"
Starting....................................[done]
Database started successfully, connection details are below:
Provider:          k8s
Engine:            pxc
Resource Name:     db-cluster1
Resource Endpoint: db-cluster1-pxc.default.pxc.svc.local
Port:              3306
User:              root
Pass:              XZLwgMxiaq3uHeqSouk
Status:            ready
 
To access database please run the following commands:
kubectl port-forward pod/db-cluster1-pxc-0 3306:3306 &
mysql -h 127.0.0.1 -P 3306 -uroot -pXZLwgMxiaq3uHeqSouk

You actually will have three pods running:

db-cluster1-pxc-0                                  1/1 Running 0 18m
 
db-cluster1-pxc-1                                  1/1 Running 0 17m
 
db-cluster1-pxc-2                                  1/1 Running 0 16m

You can choose which one you want to connect to. And if we connect to the instance:

> kubectl port-forward pod/db-cluster1-pxc-0 3306:3306 &
> mysql -h 127.0.0.1 -P 3306 -uroot -pXZLwgMxiaq3uHeqSouk
mysql: [Warning] Using a password on the command line interface can be insecure.
Handling connection for 3306
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.28-31-57 Percona XtraDB Cluster (GPL), Release rel31, Revision ef2fa88, WSREP version 31.41, wsrep_31.41
 
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql>  show global status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 3     |
+--------------------+-------+

We connected directly to a Percona XtraDB Cluster node, and there are three nodes are running.

Case 2:Create only a single node cluster without ProxySQL:

> percona-dbaas mysql create-db db-cluster1  --options="proxysql.enabled=false,allowUnsafeConfigurations=true,pxc.size=1"
Starting...........[done]
Database started successfully, connection details are below:
Provider:          k8s
Engine:            pxc
Resource Name:     db-cluster1
Resource Endpoint: db-cluster1-pxc.default.pxc.svc.local
Port:              3306
User:              root
Pass:              rBenwO6cL1aHZtaRK5
Status:            ready
 
To access database please run the following commands:
kubectl port-forward pod/db-cluster1-pxc-0 3306:3306 &
mysql -h 127.0.0.1 -P 3306 -uroot -prBenwO6cL1aHZtaRK5

To check that we have only one node running:

> kubectl get pods
NAME                                               READY   STATUS    RESTARTS   AGE
db-cluster1-pxc-0                                  1/1     Running   0          80s
percona-xtradb-cluster-operator-57cdc94964-scvf5   1/1     Running   0          5m6s

Case 3:Create a cluster which is accessible outside Kubernetes.

This particular case will work only with Google Kubernetes Engine and other providers that can assign a public IP to a LoadBalancer.

So you can run:

> percona-dbaas mysql create-db db-cluster1  --options="proxysql.serviceType=LoadBalancer"
Starting......................................[done]
Database started successfully, connection details are below:
Provider:          k8s
Engine:            pxc
Resource Name:     db-cluster1
Resource Endpoint: db-cluster1-proxysql.default.pxc.svc.local
Port:              3306
User:              root
Pass:              KtwBG3qzvVR9onQe6
Status:            ready
 
To access database please run the following commands:
kubectl port-forward svc/db-cluster1-proxysql 3306:3306 &
mysql -h 127.0.0.1 -P 3306 -uroot -pKtwBG3qzvVR9onQe6

Now there should be a public IP assigned to the cluster, and to find it, we run:

> kubectl get services
NAME                           TYPE           CLUSTER-IP   EXTERNAL-IP     PORT(S)             AGE
db-cluster1-proxysql           LoadBalancer   10.8.3.197   34.71.177.219   3306:30887/TCP      8m3s

So now we can connect to the cluster from anywhere:

mysql -h 34.71.177.219 -P 3306 -uroot -pKtwBG3qzvVR9onQe6

Just make sure you create users with secure passwords!

4. Customize my.cnf

This is not really a documented feature yet (so consider this is a hack), but sometimes we want to make some adjustments to my.cnf, for example, to increase buffer pool size if we know that nodes have enough memory to accommodate a bigger buffer pool.

For this we create our or my.cnf:

[mysqld]
innodb_buffer_pool_size=2G

Deploy it to a configmap:

kubectl create configmap mycluster1-pxc --from-file=my.cnf

And create the cluster after that:

percona-dbaas mysql create-db mycluster1

After we connect to to the cluster:

mysql> show global variables like 'innodb_buffer_pool_size%';
+-------------------------------------+----------------+
| Variable_name                       | Value          |
+-------------------------------------+----------------+
| innodb_buffer_pool_size             | 2147483648     |
+-------------------------------------+----------------+

We have nodes with 2GB buffer pool size.

In the command above, “mycluster1” specifies the configuration that will be applied to “mycluster1” cluster and “pxc” specifies you’re supplying MySQL/PXC configuration through my.cnf.

Conclusion

Our percona-dbaas tool is the next step in simplifying the deployment for Percona XtraDB Cluster and Percona Server for MongoDB . It is still in an experimental state, and we are asking for your feedback to see what we can improve before we get to the official release.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

计算机组成(第 6 版)

计算机组成(第 6 版)

Andrew S. Tanenbaum、Todd Austin / 刘卫东、宋佳兴 / 机械工业出版社 / 2014-8-19 / CNY 99.00

本书采用结构化方法来介绍计算机系统,书的内容完全建立在“计算机是由层次结构组成的,每层完成规定的功能”这一概念之上。作者对本版进行了彻底的更新,以反映当今最重要的计算机技术以及计算机组成和体系结构方面的最新进展。书中详细讨论了数字逻辑层、微体系结构层、指令系统层、操作系统层和汇编语言层,并涵盖了并行体系结构的内容,而且每一章结尾都配有丰富的习题。本书适合作为计算机专业本科生计算机组成与结构课程的教......一起来看看 《计算机组成(第 6 版)》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具