|
| 1 | +# CRUD base ready-to-use application |
| 2 | + |
| 3 | +## Deploy |
| 4 | + |
| 5 | +Run `helm install`: |
| 6 | + |
| 7 | +```shell |
| 8 | +$ helm install crud-app ./charts/crud/ --namespace tarantool --create-namespace |
| 9 | +--- |
| 10 | +NAME: crud-app |
| 11 | +LAST DEPLOYED: Wed Dec 2 15:58:11 2020 |
| 12 | +NAMESPACE: tarantool |
| 13 | +STATUS: deployed |
| 14 | +REVISION: 1 |
| 15 | +``` |
| 16 | + |
| 17 | +Check pods: |
| 18 | + |
| 19 | +```shell |
| 20 | +$ kubectl -n tarantool get pods |
| 21 | +--- |
| 22 | +NAME READY STATUS RESTARTS AGE |
| 23 | +crud-0-0 1/1 Running 0 2m28s |
| 24 | +crud-0-1 1/1 Running 0 119s |
| 25 | +crud-1-0 1/1 Running 0 2m28s |
| 26 | +crud-1-1 1/1 Running 0 2m10s |
| 27 | +tarantool-operator-644f487f87-4cqlv 1/1 Running 0 2m31s |
| 28 | +``` |
| 29 | + |
| 30 | +## Schema creation |
| 31 | + |
| 32 | +Go to Cartridge webUI |
| 33 | + |
| 34 | +```shell |
| 35 | +$ kubectl -n tarantool port-forward crud-0-0 8081:8081 |
| 36 | +``` |
| 37 | + |
| 38 | +Add new migration file `migrations/source/000_bootstrap.lua` on code page and apply configuration: |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +```lua |
| 43 | +return { |
| 44 | + up = function() |
| 45 | + local utils = require('migrator.utils') |
| 46 | + local s = box.schema.create_space('customer', { |
| 47 | + format = { |
| 48 | + { name = 'id', type = 'number' }, |
| 49 | + { name = 'name', type = 'string' }, |
| 50 | + { name = 'age', type = 'number' }, |
| 51 | + { name = 'bucket_id', type = 'unsigned' }, |
| 52 | + }, |
| 53 | + if_not_exists = true, |
| 54 | + }) |
| 55 | + s:create_index('primary', { |
| 56 | + parts = { 'key' }, |
| 57 | + if_not_exists = true, |
| 58 | + }) |
| 59 | + s:create_index('bucket_id', { |
| 60 | + parts = { 'bucket_id' }, |
| 61 | + if_not_exists = true, |
| 62 | + unique = false |
| 63 | + }) |
| 64 | + utils.register_sharding_key('customer', {'bucket_id'}) |
| 65 | + return true |
| 66 | + end |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +And apply migration: |
| 71 | +```shell |
| 72 | +$ curl --header "Content-Type: application/json" \ |
| 73 | + --request POST \ |
| 74 | + --data '{}' \ |
| 75 | + http://localhost:8081/migrations/up |
| 76 | +--- |
| 77 | +{"applied":["000_bootstrap.lua"]} |
| 78 | +``` |
| 79 | + |
| 80 | +## Using |
| 81 | + |
| 82 | +Connect to any instance: |
| 83 | + |
| 84 | +```shell |
| 85 | +$ kubectl -n tarantool exec -it crud-0-0 -- /bin/bash |
| 86 | +``` |
| 87 | +```shell |
| 88 | +bash-4.4$ tarantoolctl connect admin:crud-app-cluster-cookie@localhost:3301 |
| 89 | +connected to localhost:3301 |
| 90 | +``` |
| 91 | + |
| 92 | +Try insert objects: |
| 93 | + |
| 94 | +```shell |
| 95 | +localhost:3301> crud.insert('customer', {0, "Ivan", 22, box.NULL}) |
| 96 | +--- |
| 97 | +- metadata: [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'}, |
| 98 | + {'name': 'age', 'type': 'number'}, {'name': 'bucket_id', 'type': 'unsigned'}] |
| 99 | + rows: |
| 100 | + - [0, 'Ivan', 22, 18560] |
| 101 | +... |
| 102 | + |
| 103 | +localhost:3301> crud.insert('customer', {1, "Artem", 21, box.NULL}) |
| 104 | +--- |
| 105 | +- metadata: [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'}, |
| 106 | + {'name': 'age', 'type': 'number'}, {'name': 'bucket_id', 'type': 'unsigned'}] |
| 107 | + rows: |
| 108 | + - [1, 'Artem', 21, 12477] |
| 109 | +... |
| 110 | + |
| 111 | +localhost:3301> crud.insert('customer', {2, "Denis", 20, box.NULL}) |
| 112 | +--- |
| 113 | +- metadata: [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'}, |
| 114 | + {'name': 'age', 'type': 'number'}, {'name': 'bucket_id', 'type': 'unsigned'}] |
| 115 | + rows: |
| 116 | + - [2, 'Denis', 20, 21401] |
| 117 | +... |
| 118 | +``` |
| 119 | + |
| 120 | +And execute simple select: |
| 121 | + |
| 122 | +```shell |
| 123 | +localhost:3301> crud.select('customer', {{'>=', 'age', 21}}) |
| 124 | +--- |
| 125 | +- metadata: [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'}, |
| 126 | + {'name': 'age', 'type': 'number'}, {'name': 'bucket_id', 'type': 'unsigned'}] |
| 127 | + rows: |
| 128 | + - [0, 'Ivan', 22, 18560] |
| 129 | + - [1, 'Artem', 21, 12477] |
| 130 | +... |
| 131 | +``` |
| 132 | + |
| 133 | +## Customization |
| 134 | + |
| 135 | +By default the cluster contains two replicasets of two nodes (master - replica). If you want to change this configuration, you must describe it in the file `crud_values.yaml` |
| 136 | + |
| 137 | +For example: |
| 138 | +```yaml |
| 139 | +cartridge: |
| 140 | + RoleConfig: |
| 141 | + - RoleName: crud |
| 142 | + ReplicaCount: 2 |
| 143 | + ReplicaSetCount: 5 |
| 144 | + DiskSize: 1Gi |
| 145 | + CPUallocation: 0.25 |
| 146 | + MemtxMemoryMB: 256 |
| 147 | + RolesToAssign: |
| 148 | + - crud-storage |
| 149 | + - crud-router |
| 150 | + - migrator |
| 151 | + - metrics |
| 152 | +``` |
| 153 | +And pass this values to `helm install`: |
| 154 | + |
| 155 | +```shell |
| 156 | +$ helm install crud-app -f crud_values.yaml ./charts/crud/ --namespace tarantool --create-namespace |
| 157 | +``` |
| 158 | + |
| 159 | +**NOTE** - all specified fields are required. Look at [this](https://github.com/tarantool/tarantool-operator/issues/44) ticket. |
0 commit comments