Lusheng Ji | bd11574 | 2017-10-13 19:18:52 +0000 | [diff] [blame] | 1 | PostgreSQL as a Service |
| 2 | ============ |
Tony Hansen | 30c453e | 2017-10-13 14:34:46 +0000 | [diff] [blame] | 3 | |
| 4 | PostgreSQL as a Service comes in two flavors: all-in-one blueprint, and |
| 5 | separate disk/cluster/database blueprints to separate the management of |
| 6 | the lifetime of those constituent parts. Both are provided for use. |
| 7 | |
Lusheng Ji | bd11574 | 2017-10-13 19:18:52 +0000 | [diff] [blame] | 8 | Why Two Flavors? |
| 9 | ------------ |
Tony Hansen | 30c453e | 2017-10-13 14:34:46 +0000 | [diff] [blame] | 10 | |
| 11 | The reason there are two flavors of blueprints lays in the difference in |
| 12 | lifetime management of the constituent parts. |
| 13 | |
| 14 | For example, a database usually needs to have persistent storage, which |
| 15 | in these blueprints comes from Cinder storage volumes. The primitives |
| 16 | used in these blueprints assume that the lifetime of the Cinder storage |
| 17 | volumes matches the lifetime of the blueprint deployment. So when the |
| 18 | blueprint goes away, any Cinder storage volume allocated in the |
| 19 | blueprint also goes away. |
| 20 | |
Tony Hansen | 8c55897 | 2017-10-17 18:14:52 +0000 | [diff] [blame] | 21 | Similarly, a database's lifetime may be the same time as an application's |
| 22 | lifetime. When the application is undeployed, the associated database should |
| 23 | be deployed too. OR, the database should have a lifetime beyond the scope |
| 24 | of the applications that are writing to it or reading from it. |
Tony Hansen | 30c453e | 2017-10-13 14:34:46 +0000 | [diff] [blame] | 25 | |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 26 | Blueprint Files |
Tony Hansen | 8c55897 | 2017-10-17 18:14:52 +0000 | [diff] [blame] | 27 | ------------ |
Tony Hansen | 30c453e | 2017-10-13 14:34:46 +0000 | [diff] [blame] | 28 | |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 29 | The Blueprints for PG Services and Cinder |
| 30 | ^^^^^^^^^^^ |
| 31 | |
Tony Hansen | 8c55897 | 2017-10-17 18:14:52 +0000 | [diff] [blame] | 32 | The all-in-one blueprint PGaaS.yaml assumes that the PG servers and Cinder volumes can be allocated and |
| 33 | deallocated together. This PGaaS.yaml blueprint creates a cluster named "pstg" by default. |
| 34 | |
| 35 | Alternatively, you can split them apart into separate steps, using PGaaS-disk.yaml to allocate the |
| 36 | Cinder volume, and PGaaS-cluster.yaml to allocate a PG cluster. Create the Cinder volume first using |
| 37 | PGaaS-disk.yaml, and then use PGaaS-cluster.yaml to create the cluster. The PG cluster can be |
| 38 | redeployed without affecting the data on the Cinder volumes. |
| 39 | |
| 40 | The Blueprints for Databases |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 41 | ^^^^^^^^^^^ |
Tony Hansen | 8c55897 | 2017-10-17 18:14:52 +0000 | [diff] [blame] | 42 | |
| 43 | The PGaaS-database.yaml blueprint shows how a database can be created separately from any application |
| 44 | that uses it. That database will remain present until the PGaaS-database.yaml blueprint is |
| 45 | undeployed. The PGaaS-getdbinfo.yaml file demonstrates how an application would access the credentials |
| 46 | needed to access a given database on a given PostgreSQL cluster. |
| 47 | |
| 48 | If the lifetime of your database is tied to the lifetime of your application, use a block similar to what |
| 49 | is in PGaaS-database.yaml to allocate the database, and use the attributes as shown in PGaaS-getdbinfo.yaml |
| 50 | to access the credentials. |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 51 | |
| 52 | |
| 53 | What is Created by the Blueprints |
| 54 | ^^^^^^^^^^^^ |
| 55 | |
| 56 | Each PostgreSQL cluster has a name, represented below as ``${CLUSTER}`` or ``CLNAME``. Each cluster is created |
| 57 | with two VMs, one VM used for the writable master and the other as a cascaded read-only secondary. |
| 58 | |
| 59 | |
| 60 | There are two DNS A records added, ``${LOCATIONPREFIX}${CLUSTER}00.${LOCATIONDOMAIN}`` and |
| 61 | ``${LOCATIONPREFIX}${CLUSTER}01.${LOCATIONDOMAIN}``. In addition, |
| 62 | there are two CNAME entries added: |
| 63 | ``${LOCATIONPREFIX}-${CLUSTER}-write.${LOCATIONDOMAIN} `` |
| 64 | and |
| 65 | ``${LOCATIONPREFIX}-${CLUSTER}.${LOCATIONDOMAIN}``. The CNAME |
| 66 | ``${LOCATIONPREFIX}-${CLUSTER}-write.${LOCATIONDOMAIN}`` will be used by further |
| 67 | blueprints to create and attach to databases. |
| 68 | |
| 69 | |
| 70 | Parameters |
| 71 | ------------ |
| 72 | |
| 73 | The blueprints are designed to run using the standard inputs file used for all of the blueprints, |
| 74 | plus several additional parameters that are given reasonable defaults. |
| 75 | |
| 76 | How to Run |
| 77 | ------------ |
| 78 | |
| 79 | |
| 80 | |
| 81 | To install the PostgreSQL as a Service |
| 82 | ^^^^^^^^^^^^ |
| 83 | |
| 84 | Installing the all-in-one blueprint is straightforward: |
| 85 | |
| 86 | :: |
| 87 | |
| 88 | cfy install -p pgaas.yaml -i inputs.yaml |
| 89 | |
| 90 | By default, the all-in-one blueprint creates a cluster by the name ``pstg``. |
| 91 | |
| 92 | You can override that name using another ``-i`` option. |
| 93 | (When overriding the defaults, it is also best to explicitly |
| 94 | set the -b and -d names.) |
| 95 | |
| 96 | :: |
Tony Hansen | 09c6a76 | 2017-10-30 18:52:57 +0000 | [diff] [blame^] | 97 | |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 98 | cfy install -p pgaas.yaml -b pgaas-CLNAME -d pgaas-CLNAME -i inputs.yaml -i pgaas_cluster_name=CLNAME |
| 99 | |
| 100 | |
| 101 | Separating out the disk allocation from the service creation requires using two blueprints: |
| 102 | |
| 103 | :: |
Tony Hansen | 09c6a76 | 2017-10-30 18:52:57 +0000 | [diff] [blame^] | 104 | |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 105 | cfy install -p pgaas-disk.yaml -i inputs.yaml |
| 106 | cfy install -p pgaas-cluster.yaml -i inputs.yaml |
| 107 | |
| 108 | By default, these blueprints create a cluster named ``pgcl``, which can be overridden the same |
| 109 | way as shown above: |
| 110 | |
| 111 | :: |
Tony Hansen | 09c6a76 | 2017-10-30 18:52:57 +0000 | [diff] [blame^] | 112 | |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 113 | cfy install -p pgaas-disk.yaml -b pgaas-disk-CLNAME -d pgaas-disk-CLNAME -i inputs.yaml -i pgaas_cluster_name=CLNAME |
| 114 | cfy install -p pgaas-cluster.yaml -b pgaas-disk-CLNAME -d pgaas-disk-CLNAME -i inputs.yaml -i pgaas_cluster_name=CLNAME |
| 115 | |
| 116 | |
| 117 | You must use the same pgaas_cluster_name for the two blueprints to work together. |
| 118 | |
| 119 | For the disk, you can also specify a ``cinder_volume_size``, as in ``-i cinder_volume_size=1000`` |
| 120 | for 1TiB volume. (There is no need to override the ``-b`` and ``-d`` names when changing the |
| 121 | volume size.) |
| 122 | |
| 123 | |
| 124 | You can verify that the cluster is up and running by connecting to the PostgreSQL service |
Tony Hansen | b32a0b6 | 2017-10-25 11:53:09 +0000 | [diff] [blame] | 125 | on port 5432. To verify that all of the DNS names were created properly and that PostgreSQL is |
| 126 | answering on port 5432, you can use something like this: |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 127 | |
| 128 | :: |
Tony Hansen | 09c6a76 | 2017-10-30 18:52:57 +0000 | [diff] [blame^] | 129 | |
Tony Hansen | b32a0b6 | 2017-10-25 11:53:09 +0000 | [diff] [blame] | 130 | sleep 1 | nc -v ${LOCATIONPREFIX}${CLUSTER}00.${LOCATIONDOMAIN} 5432 |
| 131 | sleep 1 | nc -v ${LOCATIONPREFIX}${CLUSTER}01.${LOCATIONDOMAIN} 5432 |
| 132 | sleep 1 | nc -v ${LOCATIONPREFIX}-${CLUSTER}-write.${LOCATIONDOMAIN} 5432 |
| 133 | sleep 1 | nc -v ${LOCATIONPREFIX}-${CLUSTER}.${LOCATIONDOMAIN} 5432 |
| 134 | |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 135 | |
| 136 | Once you have the cluster created, you can then allocate databases. An application that |
| 137 | wants a persistent database not tied to the lifetime of the application blueprint can |
| 138 | use the ``pgaas-database.yaml`` blueprint to create the database; |
| 139 | |
| 140 | :: |
Tony Hansen | 09c6a76 | 2017-10-30 18:52:57 +0000 | [diff] [blame^] | 141 | |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 142 | cfy install -p pgaas-database.yaml -i inputs.yaml |
| 143 | |
| 144 | By default, the ``pgaas-database.yaml`` blueprint creates a database with the name ``sample``, which |
| 145 | can be overridden using ``database_name``. |
| 146 | |
| 147 | |
| 148 | :: |
Tony Hansen | 09c6a76 | 2017-10-30 18:52:57 +0000 | [diff] [blame^] | 149 | |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 150 | cfy install -p pgaas-database.yaml -b pgaas-database-DBNAME -d pgaas-database-DBNAME -i inputs.yaml -i database_name=DBNAME |
| 151 | cfy install -p pgaas-database.yaml -b pgaas-database-CLNAME-DBNAME -d pgaas-database-CLNAME-DBNAME -i inputs.yaml -i pgaas_cluster_name=CLNAME -i database_name=DBNAME |
| 152 | |
| 153 | |
| 154 | The ``pgaas-getdbinfo.yaml`` blueprint shows how an application can attach to an existing |
| 155 | database and access its attributes: |
| 156 | |
| 157 | :: |
Tony Hansen | 09c6a76 | 2017-10-30 18:52:57 +0000 | [diff] [blame^] | 158 | |
Tony Hansen | 1c0b82f | 2017-10-17 19:09:16 +0000 | [diff] [blame] | 159 | cfy install -p pgaas-getdbinfo.yaml -d pgaas-getdbinfo -b pgaas-getdbinfo -i inputs.yaml |
| 160 | cfy deployments outputs -d pgaas-getdbinfo |
| 161 | cfy uninstall -d pgaas-getdbinfo |