Name: deploy-graph-db-container
Owner: International Business Machines
Description: Host a graph database such as OrientDB on IBM Container Service using Kubernetes APIs
Created: 2017-08-16 14:05:02.0
Updated: 2018-04-17 10:28:00.0
Pushed: 2017-12-05 15:09:25.0
Homepage: https://developer.ibm.com/code/patterns/cloud-host-graph-database-using-kubernetes
Size: 4077
Language: null
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Read this in other languages: ???.
Graph databases, such as OrientDB, store data in a graph structure consisting of nodes, edges and properties. Graph databases, by design, allow simple and fast retrieval of complex hierarchical structures in a much more efficient manner than relational databases. Gremlin is a standardised graph traversal language for retrieving data from graph databases (the way SQL is for RDBMS).
In this journey we show you how to quickly deploy OrientDB on Bluemix Container Service, so that you can leverage it for your team's development and test purposes.
IBM Bluemix Container Service combines Docker and Kubernetes to deliver powerful tools to automate the deployment, operation, scaling, and monitoring of containerized apps over a cluster of independent compute hosts by using the Kubernetes APIs.
This journey gives you step by step instructions for:
Set up Bluemix and Kubernetes CLI as per instructions in https://console.bluemix.net/docs/containers/cs_tutorials.html#cs_cluster_tutorial. The steps are repeated here for quick reference.
Download and Install Bluemix CLI as per instructions in https://clis.ng.bluemix.net/ui/home.html. Bluemix CLI provides the command line interface to manage applications, containers, infrastructures, services and other resources in Bluemix. The prefix for running commands by using the Bluemix CLI is bx
.
Install the IBM Bluemix Container Service plug-in, which allows you to create Kubernetes clusters and manage worker nodes. The prefix for running commands by using the IBM Bluemix Container Service plug-in is bx cs
.
plugin install container-service -r Bluemix
Install Kubernetes CLI. This allows you to deploy apps into your Kubernetes clusters and to view a local version of the Kubernetes dashboard. The prefix for running commands by using the Kubernetes CLI is kubectl
.
Instructions for installing Kubernetes CLI on macOS are given below. Please see https://kubernetes.io/docs/tasks/tools/install-kubectl/ for other methods to install kubectl
and for instructions to install Kubernetes CLI on other platforms.
rl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl
mod +x kubectl
do mv ./kubectl /usr/local/bin/
Log in to the Bluemix CLI. Enter your Bluemix credentials when prompted.
login -a api.ng.bluemix.net
target --cf
The API endpoint for various Bluemix regions is given below. If you have private Docker images that are stored in the container registry of a specific Bluemix region, or Bluemix services instances that you have already created, log in to this region to access your images and Bluemix services. The Bluemix region that you log in to also determines the region where you can create your Kubernetes clusters, including the available datacenters.
login -a api.ng.bluemix.net
login -a api.eu-gb.bluemix.net
login -a api.eu-de.bluemix.net
login -a api.au-syd.bluemix.net
Initialize the IBM Bluemix Container Service plugin
cs init
If you want to create a Kubernetes cluster in a region other than the Bluemix region that you selected earlier, specify this region.
cs init --host https://us-south.containers.bluemix.net
cs init --host https://uk-south.containers.bluemix.net
cs init --host https://eu-central.containers.bluemix.net
cs init --host https://ap-south.containers.bluemix.net
Bluemix allows you to create a free cluster that comes with 2 CPUs, 4 GB memory, and 1 worker node. This is called lite cluster and allows you to get familiar with and test Kubernetes capabilities. However they lack capabilities like persistent NFS file-based storage with volumes.
To setup your cluster for maximum availability and capacity, Bluemix allows you to create a fully customizable, production-ready cluster called standard cluster. Standard clusters allow highly available cluster configurations such as a setup with two clusters that run in different regions, each with multiple worker nodes. Please see https://console.bluemix.net/docs/containers/cs_planning.html#cs_planning_cluster_config to review other options for highly available cluster configurations.
A detailed comparison of capabilities of lite and standard clusters is given in https://console.bluemix.net/docs/containers/cs_planning.html#cs_planning.
Create your lite Kubernetes cluster.
cs cluster-create --name mycluster
ting cluster...
machine-type flag was not specified. So a free cluster will be created
er of workers was not specified, using default: 1.
Note: It can take up to 15 minutes for the worker node machine to be ordered and for the cluster to be set up and provisioned.
In case you want to setup a standard cluster, then you can find the setup instructions in https://console.bluemix.net/docs/containers/cs_cluster.html#cs_cluster_cli.
Verify that the deployment of your worker node is complete.
cs clusters
ID State Created Workers Datacenter Version
uster 8xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5 normal 34 minutes ago 1 hou02 1.7.4_1503
cs workers mycluster
Public IP Private IP Machine Type State Status Version
-hou02-pxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-w1 17x.xxx.xx.xxx 10.47.64.200 free normal Ready 1.7.4_1503
Configure your Kubernetes CLI environment to point to your Bluemix Kubernetes cluster as below.
Download the Kubernetes configuration files and get the command to set the environment variable
cs cluster-config mycluster
configuration for mycluster was downloaded successfully. Export environment variables to start using Kubernetes.
rt KUBECONFIG=/Users/zzzzz/.bluemix/plugins/container-service/clusters/mycluster/kube-config-hou02-mycluster.yml
Set the KUBECONFIG environment variable as per output from above command
port KUBECONFIG=~/.bluemix/plugins/container-service/clusters/mycluster/kube-config-hou02-mycluster.yml
ho $KUBECONFIG
Verify that the kubectl commands run properly with your cluster by checking the Kubernetes CLI server version.
bectl version --short
nt Version: v1.7.4
er Version: v1.7.4-1+1540c973d4ff9d
Clone or download the OrientDB Kubernetes configuration scripts to your user home directory.
t clone https://github.com/IBM/deploy-graph-db-container.git
Navigate to the source directory
deploy-graph-db-container
Create a new file called password.txt in the same directory and put your desired OrientDB password inside password.txt (Could be any string with ASCII characters).
We need to make sure password.txt does not have any trailing newline. Use the following command to remove possible newlines.
-d '\n' <password.txt >.strippedpassword.txt && mv .strippedpassword.txt password.txt
Put OrientDB password in Kubernetes secret
bectl create secret generic orientdb-pass --from-file=password.txt
et "orientdb-pass" created
OrientDB docker image requires following directories to be volume mounted so as to persist data across container delete/relaunch.
entdb/databases
entdb/backup
If you are using Bluemix standard Kubernetes cluster, then you can leverage dynamic volume provisioning which allows storage volumes to be created on-demand. To use this feature, update the value of volume.beta.kubernetes.io/storage-class
annotation in orientdb.yaml
to one of the NFS file-based storage classes supported in Bluemix: ibmc-file-bronze
or ibmc-file-silver
or ibmc-file-gold
. Also change accessModes
to ReadWriteMany
and increase storage request to say 20GB.
: PersistentVolumeClaim
ersion: v1
data:
me: orientdb-pv-claim
bels:
service: orientdb
type: pv-claim
notations:
volume.beta.kubernetes.io/storage-class: "ibmc-file-gold"
:
cessModes:
ReadWriteMany
sources:
requests:
storage: 20Gi
notations:
In case you are using Bluemix lite Kubernetes cluster, where NFS file storage is not supported, you can instead use hostPath PersistentVolume. A hostPath PersistentVolume uses a file or directory on the Node to emulate network-attached storage. To create a hostPath PersistentVolume, review local-volumes.yaml and run kubectl apply
command.
t local-volumes.yaml
ersion: v1
: PersistentVolume
data:
me: "pv-volume"
bels:
type: local
:
pacity:
storage: "5Gi"
cessModes:
- "ReadWriteOnce"
stPath:
path: /tmp
rsistentVolumeReclaimPolicy: Recycle
Create hostPath persistent volume
bectl apply -f local-volumes.yaml
istentvolume "pv-volume" created
Run the OrientDB Kubernetes configuration script in the cluster. When the deployment and the service are created, OrientDB is available as a service for users.
bectl apply -f orientdb.yaml
istentvolumeclaim "orientdb-pv-claim" created
oyment "orientdbservice" created
ice "orientdbservice" created
The orientdb.yaml script creates a Kubernetes deployment for OrientDB container. The OrientDB password is fetched from the Kubernetes secret created in Step 1.2 above. Similarly the persistent volumes configured in Step 1.3 above are used as the persistent storage for OrientDB volumes. The corresponding snippet from orientdb.yaml script is shown below.
: Deployment
ersion: extensions/v1beta1
data:
me: orientdbservice
bels:
service: orientdb
:
plicas: 1
mplate:
metadata:
name: orientdbservice
labels:
service: orientdb
type: container-deployment
spec:
containers:
- name: orientdbservice
image: orientdb:2.2.26
env:
- name: ORIENTDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: orientdb-pass
key: password.txt
ports:
- containerPort: 2424
name: port-binary
- containerPort: 2480
name: port-http
volumeMounts:
- mountPath: /orientdb/databases
name: orientdb-data
subPath: databases
- mountPath: /orientdb/backup
name: orientdb-data
subPath: backup
volumes:
- name: orientdb-data
persistentVolumeClaim:
claimName: orientdb-pv-claim
The orientdb.yaml script also exposes OrientDB ports (HTTP: 2480 and binary: 2424) to the internet by creating a Kubernetes service of type NodePort as shown in the snippet below.
: Service
ersion: v1
data:
me: orientdbservice
bels:
service: orientdb
type: nodeport-service
:
pe: NodePort
lector:
service: orientdb
type: container-deployment
rts:
protocol: TCP
port: 2424
name: binary
protocol: TCP
port: 2480
name: http
Launch your Kubernetes dashboard with the default port 8001.
bectl proxy
Open the following URL in a web browser to see the Kubernetes dashboard. http://localhost:8001/ui
In the Workloads tab, you can see the resources that you created. When you are done exploring the Kubernetes dashboard, use CTRL+C to exit the proxy command.
Get information about the deployed OrientDB service to see which NodePort was assigned for OrientDB's HTTP port 2480.
bectl describe service orientdbservice
: orientdbservice
space: default
ls: service=orientdb
type=nodeport-service
tations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"service":"orientdb","type":"nodeport-service"},"name":"orientdbservice","na...
ctor: service=orientdb,type=container-deployment
: NodePort
10.10.10.177
: binary 2424/TCP
Port: binary 32039/TCP
oints: 172.xx.xxx.xx:2424
: http 2480/TCP
Port: http 31420/TCP
oints: 172.xx.xxx.xx:2480
ion Affinity: None
ts: <none>
Get the public IP address for the worker node in the cluster.
cs workers mycluster
Public IP Private IP Machine Type State Status Version
-hou02-pa85736d86a8f24324806f9b83d24960e5-w1 173.xxx.xx.xxx 10.47.64.200 free normal Ready 1.7.4_1502
Open a browser and check out the OrientDB dashboard with the following URL.
://<Public_IP_address>:<HTTP_NodePort>/studio/index.html#/
In the OrientDB dashboard, click on the cloud import button (next to New DB).
Specify username (root) and password (same as the value specified in password.txt).
Scroll down to MovieRatings database and click on download button.
This will import a database containing Movies classified by Genre and Ratings by Users, created by MovieLens (movielens.org).
Once import is successful, you will be taken back to login screen.
Movies, Users, Genres, Occupation
rated, hasGenera, hasOccupation
ct from Movies
The first 10 vertices of Movies class (ordered by id) will be shown along with its properties and, incoming and outgoing edges.Run following query:
ct from users where id = 1
Click on the User vertex at the center. In the ring that pops up, hover over outgoing edges, and click on rated as shown in the snapshot below.
All the movies rated by this user will be shown.
Click on any of the movie vertices. Under Settings, next to Display, select title.
This will show the movie title below each of the Movie vertices as shown in the snapshot below.
Kubernetes allows us to get a shell to a running container. We can use this feature to open OrientDB's Gremlin console as shown below.
bectl get pods
READY STATUS RESTARTS AGE
ntdbservice-2043245721-81524 1/1 Running 0 2d
bectl exec -it orientdbservice-2043245721-81524 -- /orientdb/bin/gremlin.sh
\,,,/
(o o)
-oOOo-(_)-oOOo-----
lin>
Note: Replace the name after kubectl exec -it
with the name of the pod on which OrientDB is running as obtained by kubectl get pods
command.
As an illustration, from within Gremlin console, we will connect to MovieRatings database and display the movies rated by a particular user (say with record id #16:0
)
lin> g = new OrientGraph("remote:localhost/MovieRatings");
rientgraph[remote:localhost/MovieRatings]
lin> g.v('#16:0').outE('rated').inV().title
ne Flew Over the Cuckoo's Nest (1975)
ames and the Giant Peach (1996)
y Fair Lady (1964)
rin Brockovich (2000)
ug's Life, A (1998)
rincess Bride, The (1987)
en-Hur (1959)
hristmas Story, A (1983)
lin> exit
We can similarly open OrientDB console and run OrientDB commands as shown below.
bectl exec -it orientdbservice-2043245721-81524 -- /orientdb/bin/console.sh
ntDB console v.2.2.26 (build ae9fcb9c075e1d74560a336a96b57d3661234c7b) https://www.orientdb.com
'help' to display all the supported commands.
alling extensions for GREMLIN language v.2.6.0
ntdb> CONNECT remote:localhost/MovieRatings root
r password:
ecting to database [remote:localhost/MovieRatings] with user 'root'...OK
ntdb {db=MovieRatings}> select OUT("rated").title as MovieRated from Users where id = 1 UNWIND MovieRated;
-+--------------------------------------+
|MovieRated |
-+--------------------------------------+
|One Flew Over the Cuckoo's Nest (1975)|
|James and the Giant Peach (1996) |
|My Fair Lady (1964) |
|Erin Brockovich (2000) |
|Bug's Life, A (1998) |
|Princess Bride, The (1987) |
|Ben-Hur (1959) |
|Christmas Story, A (1983) |
|Snow White and the Seven Dwarfs (1937)|
|Wizard of Oz, The (1939) |
|Beauty and the Beast (1991) |
|Gigi (1958) |
|Miracle on 34th Street (1947) |
|Ferris Bueller's Day Off (1986) |
|Sound of Music, The (1965) |
|Airplane! (1980) |
|Tarzan (1999) |
|Bambi (1942) |
|Awakenings (1990) |
|Big (1988) |
-+--------------------------------------+
T EXCEEDED: resultset contains more items not displayed (limit=20)
tem(s) found. Query executed in 0.013 sec(s).
ntdb {db=MovieRatings}> quit
Note: Replace the name after kubectl exec -it
with the name of the pod on which OrientDB is running as obtained by kubectl get pods
command.
The OrientDB select query that was run above displays the movies rated by a specified user (with id = 1).
bectl delete -f orientdb.yaml
ORbectl delete deployment,services,pvc -l service=orientdb
oyment "orientdbservice" deleted
ice "orientdbservice" deleted
istentvolumeclaim "orientdb-pv-claim" deleted
bectl delete -f local-volumes.yaml
ORbectl delete pv -l type=local
istentvolume "pv-volume" deleted
bectl delete secret orientdb-pass
et "orientdb-pass" deleted
bectl get pods # Get the name of the OrientDB pod
bectl logs [OrientDB pod name]
cs cluster-rm mycluster
ve the cluster? [mycluster] (Y/N)> Y
ving cluster mycluster...