Skip to content

Commit

Permalink
docs: add example configs for kubernetes; resolves #327
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Apr 23, 2017
1 parent bd417cb commit c258c2d
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 7 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ Its goal is to be a part of the developer's toolbox where [Linked Data](http://l
* [GraphQL](./docs/GraphQL.md)-inspired\* query language.
* (simplified) [MQL](./docs/MQL.md), for [Freebase](https://en.wikipedia.org/wiki/Freebase) fans
* Plays well with multiple backend stores:
* [LevelDB](https://github.com/google/leveldb)
* [Bolt](https://github.com/boltdb/bolt)
* [PostgreSQL](http://www.postgresql.org)
* [MySQL](https://www.mysql.com)
* [MongoDB](https://www.mongodb.org) for distributed stores
* [CockroachDB](https://www.cockroachlabs.com)
* KVs: [Bolt](https://github.com/boltdb/bolt), [LevelDB](https://github.com/google/leveldb)
* NoSQL: [MongoDB](https://www.mongodb.org)
* SQL: [PostgreSQL](http://www.postgresql.org), [CockroachDB](https://www.cockroachlabs.com), [MySQL](https://www.mysql.com)
* In-memory, ephemeral
* Modular design; easy to extend with new languages and backends
* Good test coverage
Expand Down
5 changes: 4 additions & 1 deletion cmd/cayley/command/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/viper"

"github.com/cayleygraph/cayley/clog"
"github.com/cayleygraph/cayley/graph"
"github.com/cayleygraph/cayley/internal"
chttp "github.com/cayleygraph/cayley/internal/http"
"github.com/cayleygraph/cayley/quad"
Expand All @@ -27,7 +28,9 @@ func NewHttpCmd() *cobra.Command {
if init, err := cmd.Flags().GetBool("init"); err != nil {
return err
} else if init {
if err = initDatabase(); err != nil {
if err = initDatabase(); err == graph.ErrDatabaseExists {
clog.Infof("database already initialized, skipping init")
} else if err != nil {
return err
}
}
Expand Down
4 changes: 4 additions & 0 deletions docs/Container.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Running in Kubernetes

To run Cayley in K8S check [this docs section](./k8s/k8s.md).

# Running in a container

A container exposing the HTTP API of Cayley is available.
Expand Down
114 changes: 114 additions & 0 deletions docs/k8s/cayley-mongo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
kind: Namespace
apiVersion: v1
metadata:
name: cayley
---
apiVersion: v1
kind: Service
metadata:
name: mongo
namespace: cayley
labels:
name: mongo
spec:
ports:
- name: mgo
port: 27017
targetPort: mgo
clusterIP: None
selector:
role: mongo
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: mongo
namespace: cayley
spec:
serviceName: "mongo"
replicas: 3
template:
metadata:
namespace: cayley
labels:
role: mongo
environment: test
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mongo
image: mongo:3
command:
- mongod
- "--replSet"
- rs0
- "--smallfiles"
- "--noprealloc"
ports:
- name: mgo
containerPort: 27017
volumeMounts:
- name: mongo-pvc
mountPath: /data/db
- name: mongo-sidecar
image: cvallance/mongo-k8s-sidecar
env:
- name: MONGO_SIDECAR_POD_LABELS
value: "role=mongo,environment=test"
volumeClaimTemplates:
- metadata:
name: mongo-pvc
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: standard
resources:
requests:
storage: 20Gi
---
kind: Service
apiVersion: v1
metadata:
name: cayley
namespace: cayley
spec:
selector:
app: cayley
ports:
- protocol: TCP
port: 80
targetPort: http
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: cayley
namespace: cayley
spec:
replicas: 1
template:
metadata:
namespace: cayley
labels:
app: cayley
spec:
initContainers:
- name: cayley-init
image: quay.io/cayleygraph/cayley:v0.7.0-alpha
command:
- cayley
- init
- -d=mongo
- -a=mongo
containers:
- name: cayley
image: quay.io/cayleygraph/cayley:v0.7.0-alpha
command:
- cayley
- http
- --init # TODO: remove once initContainers works properly
- -d=mongo
- -a=mongo
- --host=:64210
ports:
- name: http
containerPort: 64210
73 changes: 73 additions & 0 deletions docs/k8s/cayley-single.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
kind: Namespace
apiVersion: v1
metadata:
name: cayley
---
kind: Service
apiVersion: v1
metadata:
name: cayley
namespace: cayley
spec:
selector:
app: cayley
ports:
- protocol: TCP
port: 80
targetPort: http
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: cayley-pvc
namespace: cayley
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
storageClassName: standard
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: cayley
namespace: cayley
spec:
replicas: 1 # cannot be really scaled because of local backend
template:
metadata:
namespace: cayley
labels:
app: cayley
spec:
initContainers:
- name: cayley-init
image: quay.io/cayleygraph/cayley:v0.7.0-alpha
command:
- cayley
- init
- -c=/etc/cayley.json
volumeMounts:
- mountPath: /data
name: database
containers:
- name: cayley
image: quay.io/cayleygraph/cayley:v0.7.0-alpha
command:
- cayley
- http
- --init # TODO: remove once initContainers is out of beta
- -c=/etc/cayley.json
- --host=:64210
ports:
- name: http
containerPort: 64210
volumeMounts:
- mountPath: /data
name: database
volumes:
- name: database
persistentVolumeClaim:
claimName: cayley-pvc
25 changes: 25 additions & 0 deletions docs/k8s/k8s.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Running in Kubernetes

Most examples requires Kubernetes 1.5+ and PersistentVolumes are configured.

After running scripts namespace `cayley` will be created and service with the same name will be available in cluster. Service is of type `ClusterIP` by default. If you want to expose it, consider changing type to `LoadBalancer`.

## Single instance (Bolt)

This is a simplest possible configuration: single Cayley instance with persistent storage, using Bolt as a backend.

```bash
kubectl create -f ./docs/k8s/cayley-single.yml
```

## Distributed (MongoDB cluster)

This example is based on [thesandlord/mongo-k8s-sidecar](https://github.com/thesandlord/mongo-k8s-sidecar) and runs Cayley on top of 3-node Mongo cluster.

```bash
kubectl create -f ./docs/k8s/cayley-mongo.yml
```

## Distributed

*TODO: PostgreSQL, CockroachDB*

0 comments on commit c258c2d

Please sign in to comment.