mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-17 23:19:26 +00:00
Productionize the cockroachdb example a little more
Includes: * A service for clients to use * Readiness/liveness probes * An extended graceful termination period * Easy clean-up of all created resources
This commit is contained in:
@@ -67,6 +67,25 @@ steps.
|
||||
|
||||
Follow the steps in [minikube.sh](minikube.sh) (or simply run that file).
|
||||
|
||||
## Accessing the database
|
||||
|
||||
Along with our PetSet configuration, we expose a standard Kubernetes service
|
||||
that offers a load-balanced virtual IP for clients to access the database
|
||||
with. In our example, we've called this service `cockroachdb-public`.
|
||||
|
||||
Start up a client pod and open up an interactive, (mostly) Postgres-flavor
|
||||
SQL shell using:
|
||||
|
||||
```console
|
||||
$ kubectl run -it cockroach-client --image=cockroachdb/cockroach --restart=Never --command -- bash
|
||||
root@cockroach-client # ./cockroach sql --host cockroachdb-public
|
||||
```
|
||||
|
||||
You can see example SQL statements for inserting and querying data in the
|
||||
included [demo script](demo.sh), but can use almost any Postgres-style SQL
|
||||
commands. Some more basic examples can be found within
|
||||
[CockroachDB's documentation](https://www.cockroachlabs.com/docs/learn-cockroachdb-sql.html).
|
||||
|
||||
## Simulating failures
|
||||
|
||||
When all (or enough) nodes are up, simulate a failure like this:
|
||||
@@ -75,14 +94,15 @@ When all (or enough) nodes are up, simulate a failure like this:
|
||||
kubectl exec cockroachdb-0 -- /bin/bash -c "while true; do kill 1; done"
|
||||
```
|
||||
|
||||
On one of the other pods, run `./cockroach sql --host $(hostname)` and use
|
||||
(mostly) Postgres-flavor SQL. The example runs with three-fold replication,
|
||||
so it can tolerate one failure of any given node at a time.
|
||||
Note also that there is a brief period of time immediately after the creation
|
||||
of the cluster during which the three-fold replication is established, and
|
||||
during which killing a node may lead to unavailability.
|
||||
You can then reconnect to the database as demonstrated above and verify
|
||||
that no data was lost. The example runs with three-fold replication, so
|
||||
it can tolerate one failure of any given node at a time. Note also that
|
||||
there is a brief period of time immediately after the creation of the
|
||||
cluster during which the three-fold replication is established, and during
|
||||
which killing a node may lead to unavailability.
|
||||
|
||||
There is also a [demo script](demo.sh).
|
||||
The [demo script](demo.sh) gives an example of killing one instance of the
|
||||
database and ensuring the other replicas have all data that was written.
|
||||
|
||||
## Scaling up or down
|
||||
|
||||
@@ -91,6 +111,15 @@ volume claim first). If you ran `minikube.sh`, there's a spare volume so you
|
||||
can immediately scale up by one. Convince yourself that the new node
|
||||
immediately serves reads and writes.
|
||||
|
||||
## Cleaning up when you're done
|
||||
|
||||
Because all of the resources in this example have been tagged with the label `app=cockroachdb`,
|
||||
we can clean up everything that we created in one quick command using a selector on that label:
|
||||
|
||||
```shell
|
||||
kubectl delete petsets,pods,persistentvolumes,persistentvolumeclaims,services -l app=cockroachdb
|
||||
```
|
||||
|
||||
|
||||
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||||
[]()
|
||||
|
Reference in New Issue
Block a user