diff --git a/docs/server/source/cloud-deployment-templates/node-on-kubernetes.rst b/docs/server/source/cloud-deployment-templates/node-on-kubernetes.rst index 1a8e5deb..e1ed43e7 100644 --- a/docs/server/source/cloud-deployment-templates/node-on-kubernetes.rst +++ b/docs/server/source/cloud-deployment-templates/node-on-kubernetes.rst @@ -32,18 +32,34 @@ then you can get the ``~/.kube/config`` file using: --name -Step 3: Create a StorageClass ------------------------------ +Step 3: Create Storage Classes +------------------------------ MongoDB needs somewhere to store its data persistently, outside the container where MongoDB is running. + +The official MongoDB Docker container exports two volume mounts with correct +permissions from inside the container: + + +* The directory where the mongod instance stores its data - ``/data/db``, + described at `storage.dbpath `_. + +* The directory where mongodb instance stores the metadata for a sharded + cluster - ``/data/configdb/``, described at + `sharding.configDB `_. + + Explaining how Kubernetes handles persistent volumes, and the associated terminology, is beyond the scope of this documentation; see `the Kubernetes docs about persistent volumes `_. -The first thing to do is create a Kubernetes StorageClass. +The first thing to do is create the Kubernetes storage classes. +We will accordingly create two storage classes and persistent volume claims in +Kubernetes. + **Azure.** First, you need an Azure storage account. If you deployed your Kubernetes cluster on Azure @@ -67,25 +83,26 @@ the PersistentVolumeClaim would get stuck in a "Pending" state. For future reference, the command to create a storage account is `az storage account create `_. -Create a Kubernetes Storage Class named ``slow`` -by writing a file named ``azureStorageClass.yml`` containing: -.. code:: yaml - - kind: StorageClass - apiVersion: storage.k8s.io/v1beta1 - metadata: - name: slow - provisioner: kubernetes.io/azure-disk - parameters: - skuName: Standard_LRS - location: - -and then: +Get the files ``mongo-data-db-sc.yaml`` and ``mongo-data-configdb-sc.yaml`` +from GitHub using: .. code:: bash - $ kubectl apply -f azureStorageClass.yml + $ wget https://raw.githubusercontent.com/bigchaindb/bigchaindb/master/k8s/mongodb/mongo-data-db-sc.yaml + $ wget https://raw.githubusercontent.com/bigchaindb/bigchaindb/master/k8s/mongodb/mongo-data-configdb-sc.yaml + +You may want to update the ``parameters.location`` field in both the files to +specify the location you are using in Azure. + + +Create the required StorageClass using + +.. code:: bash + + $ kubectl apply -f mongo-data-db-sc.yaml + $ kubectl apply -f mongo-data-configdb-sc.yaml + You can check if it worked using ``kubectl get storageclasses``. @@ -99,27 +116,19 @@ Kubernetes just looks for a storageAccount with the specified skuName and location. -Step 4: Create a PersistentVolumeClaim --------------------------------------- +Step 4: Create Persistent Volume Claims +--------------------------------------- -Next, you'll create a PersistentVolumeClaim named ``mongoclaim``. -Create a file named ``mongoclaim.yml`` -with the following contents: +Next, we'll create two PersistentVolumeClaim objects ``mongo-db-claim`` and +``mongo-configdb-claim``. -.. code:: yaml +Get the files ``mongo-data-db-sc.yaml`` and ``mongo-data-configdb-sc.yaml`` +from GitHub using: - kind: PersistentVolumeClaim - apiVersion: v1 - metadata: - name: mongoclaim - annotations: - volume.beta.kubernetes.io/storage-class: slow - spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 20Gi +.. code:: bash + + $ wget https://raw.githubusercontent.com/bigchaindb/bigchaindb/master/k8s/mongodb/mongo-data-db-pvc.yaml + $ wget https://raw.githubusercontent.com/bigchaindb/bigchaindb/master/k8s/mongodb/mongo-data-configdb-pvc.yaml Note how there's no explicit mention of Azure, AWS or whatever. ``ReadWriteOnce`` (RWO) means the volume can be mounted as @@ -128,67 +137,144 @@ read-write by a single Kubernetes node. by AzureDisk.) ``storage: 20Gi`` means the volume has a size of 20 `gibibytes `_. -(You can change that if you like.) -Create ``mongoclaim`` in your Kubernetes cluster: +You may want to update the ``spec.resources.requests.storage`` field in both +the files to specify a different disk size. + +Create the required PersistentVolumeClaim using: .. code:: bash - $ kubectl apply -f mongoclaim.yml + $ kubectl apply -f mongo-data-db-pvc.yaml + $ kubectl apply -f mongo-data-configdb-pvc.yaml -You can check its status using: -.. code:: bash +You can check its status using: ``kubectl get pvc -w`` - $ kubectl get pvc - -Initially, the status of ``mongoclaim`` might be "Pending" +Initially, the status of persistent volume claims might be "Pending" but it should become "Bound" fairly quickly. -.. code:: bash - $ kubectl describe pvc - Name: mongoclaim - Namespace: default - StorageClass: slow - Status: Bound - Volume: pvc-ebed81f1-fdca-11e6-abf0-000d3a27ab21 - Labels: - Capacity: 20Gi - Access Modes: RWO - No events. +Now we are ready to run MongoDB and BigchainDB on our Kubernetes cluster. +Step 5: Run MongoDB as a StatefulSet +------------------------------------ -Step 5: Deploy MongoDB & BigchainDB ------------------------------------ - -Now you can deploy MongoDB and BigchainDB to your Kubernetes cluster. -Currently, the way we do that is we create a StatefulSet with two -containers: BigchainDB and MongoDB. (In the future, we'll put them -in separate pods, and we'll ensure those pods are in different nodes.) -We expose BigchainDB's port 9984 (the HTTP API port) -and MongoDB's port 27017 using a Kubernetes Service. - -Get the file ``node-mdb-ss.yaml`` from GitHub using: +Get the file ``mongo-ss.yaml`` from GitHub using: .. code:: bash - $ wget https://raw.githubusercontent.com/bigchaindb/bigchaindb/master/k8s/node-mdb-ss.yaml + $ wget https://raw.githubusercontent.com/bigchaindb/bigchaindb/master/k8s/mongodb/mongo-ss.yaml -Take a look inside that file to see how it defines the Service -and the StatefulSet. -Note how the MongoDB container uses the ``mongoclaim`` PersistentVolumeClaim -for its ``/data`` diretory (mount path). -Create the StatefulSet and Service in your cluster using: +Note how the MongoDB container uses the ``mongo-db-claim`` and the +``mongo-configdb-claim`` PersistentVolumeClaims for its ``/data/db`` and +``/data/configdb`` diretories (mount path). Note also that we use the pod's +``securityContext.capabilities.add`` specification to add the ``FOWNER`` +capability to the container. + +That is because MongoDB container has the user ``mongodb``, with uid ``999`` +and group ``mongodb``, with gid ``999``. +When this container runs on a host with a mounted disk, the writes fail when +there is no user with uid ``999``. + +To avoid this, we use the Docker feature of ``--cap-add=FOWNER``. +This bypasses the uid and gid permission checks during writes and allows data +to be persisted to disk. +Refer to the +`Docker doc `_ +for details. + +As we gain more experience running MongoDB in testing and production, we will +tweak the ``resources.limits.cpu`` and ``resources.limits.memory``. +We will also stop exposing port ``27017`` globally and/or allow only certain +hosts to connect to the MongoDB instance in the future. + +Create the required StatefulSet using: .. code:: bash - $ kubectl apply -f node-mdb-ss.yaml + $ kubectl apply -f mongo-ss.yaml -You can check that they're working using: +You can check its status using the commands ``kubectl get statefulsets -w`` +and ``kubectl get svc -w`` + + +Step 6: Run BigchainDB as a Deployment +-------------------------------------- + +Get the file ``bigchaindb-dep.yaml`` from GitHub using: .. code:: bash - $ kubectl get services - $ kubectl get statefulsets + $ wget https://raw.githubusercontent.com/bigchaindb/bigchaindb/master/k8s/bigchaindb/bigchaindb-dep.yaml + +Note that we set the ``BIGCHAINDB_DATABASE_HOST`` to ``mdb`` which is the name +of the MongoDB service defined earlier. + +We also hardcode the ``BIGCHAINDB_KEYPAIR_PUBLIC``, +``BIGCHAINDB_KEYPAIR_PRIVATE`` and ``BIGCHAINDB_KEYRING`` for now. + +As we gain more experience running BigchainDB in testing and production, we +will tweak the ``resources.limits`` values for CPU and memory, and as richer +monitoring and probing becomes available in BigchainDB, we will tweak the +``livenessProbe`` and ``readinessProbe`` parameters. + +We also plan to specify scheduling policies for the BigchainDB deployment so +that we ensure that BigchainDB and MongoDB are running in separate nodes, and +build security around the globally exposed port ``9984``. + +Create the required Deployment using: + +.. code:: bash + + $ kubectl apply -f bigchaindb-dep.yaml + +You can check its status using the command ``kubectl get deploy -w`` + + +Step 7: Verify the BigchainDB Node Setup +---------------------------------------- + +Step 7.1: Testing Externally +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Try to access the ``:9984`` on your +browser. You must receive a json output that shows the BigchainDB server +version among other things. + +Try to access the ``:27017`` on your +browser. You must receive a message from MongoDB stating that it doesn't allow +HTTP connections to the port anymore. + + +Step 7.2: Testing Internally +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Run a container that provides utilities like ``nslookup``, ``curl`` and ``dig`` +on the cluster and query the internal DNS and IP endpoints. + +.. code:: bash + + $ kubectl run -it toolbox -- image --restart=Never --rm + +It will drop you to the shell prompt. +Now we can query for the ``mdb`` and ``bdb`` service details. + +.. code:: bash + + $ nslookup mdb + $ dig +noall +answer _mdb_port._tcp.mdb.default.svc.cluster.local SRV + $ curl -X GET http://mdb:27017 + $ curl -X GET http://bdb:9984 + +There is a generic image based on alpine:3.5 with the required utilities +hosted at Docker Hub under ``bigchaindb/toolbox``. +The corresponding Dockerfile is `here +`_. +You can use it as below to get started immediately: + +.. code:: bash + + $ kubectl run -it toolbox --image bigchaindb/toolbox --restart=Never --rm + diff --git a/docs/server/source/cloud-deployment-templates/template-kubernetes-azure.rst b/docs/server/source/cloud-deployment-templates/template-kubernetes-azure.rst index 0fe8c378..93cf1e08 100644 --- a/docs/server/source/cloud-deployment-templates/template-kubernetes-azure.rst +++ b/docs/server/source/cloud-deployment-templates/template-kubernetes-azure.rst @@ -94,7 +94,9 @@ Finally, you can deploy an ACS using something like: $ az acs create --name \ --resource-group \ + --master-count 3 \ --agent-count 3 \ + --admin-username ubuntu \ --agent-vm-size Standard_D2_v2 \ --dns-prefix \ --ssh-key-value ~/.ssh/.pub \ @@ -113,9 +115,6 @@ go to **Resource groups** (with the blue cube icon) and click on the one you created to see all the resources in it. -Next, you can :doc:`run a BigchainDB node on your new -Kubernetes cluster `. - Optional: SSH to Your New Kubernetes Cluster Nodes -------------------------------------------------- @@ -125,21 +124,78 @@ You can SSH to one of the just-deployed Kubernetes "master" nodes .. code:: bash - $ ssh -i ~/.ssh/.pub azureuser@ + $ ssh -i ~/.ssh/.pub ubuntu@ where you can get the IP address or hostname -of a master node from the Azure Portal. -Note how the default username is ``azureuser``. +of a master node from the Azure Portal. For example: -The "agent" nodes don't get public IP addresses or hostnames, +.. code:: bash + + $ ssh -i ~/.ssh/mykey123.pub ubuntu@mydnsprefix.westeurope.cloudapp.azure.com + +.. note:: + + All the master nodes should have the *same* IP address and hostname + (also called the Master FQDN). + +The "agent" nodes shouldn't get public IP addresses or hostnames, so you can't SSH to them *directly*, but you can first SSH to the master -and then SSH to an agent from there -(using the *private* IP address or hostname of the agent node). -To do that, you either need to copy your SSH key pair to -the master (a bad idea), -or use something like -`SSH agent forwarding `_ (better). +and then SSH to an agent from there. +To do that, you could +copy your SSH key pair to the master (a bad idea), +or use SSH agent forwarding (better). +To do the latter, do the following on the machine you used +to SSH to the master: + +.. code:: bash + + $ echo -e "Host \n ForwardAgent yes" >> ~/.ssh/config + +To verify that SSH agent forwarding works properly, +SSH to the one of the master nodes and do: + +.. code:: bash + + $ echo "$SSH_AUTH_SOCK" + +If you get an empty response, +then SSH agent forwarding hasn't been set up correctly. +If you get a non-empty response, +then SSH agent forwarding should work fine +and you can SSH to one of the agent nodes (from a master) +using something like: + +.. code:: bash + + $ ssh ssh ubuntu@k8s-agent-4AC80E97-0 + +where ``k8s-agent-4AC80E97-0`` is the name +of a Kubernetes agent node in your Kubernetes cluster. +You will have to replace it by the name +of an agent node in your cluster. + + +Optional: Delete the Kubernetes Cluster +--------------------------------------- + +.. code:: bash + + $ az acs delete \ + --name \ + --resource-group + + +Optional: Delete the Resource Group +----------------------------------- + +CAUTION: You might end up deleting resources other than the ACS cluster. + +.. code:: bash + + $ az group delete \ + --name + Next, you can :doc:`run a BigchainDB node on your new Kubernetes cluster `. diff --git a/k8s/bigchaindb/bigchaindb-dep.yaml b/k8s/bigchaindb/bigchaindb-dep.yaml new file mode 100644 index 00000000..7bf68f06 --- /dev/null +++ b/k8s/bigchaindb/bigchaindb-dep.yaml @@ -0,0 +1,83 @@ +############################################################### +# This config file runs bigchaindb:master as a k8s Deployment # +# and it connects to the mongodb backend on a separate pod # +############################################################### + +apiVersion: v1 +kind: Service +metadata: + name: bdb + namespace: default + labels: + name: bdb +spec: + selector: + app: bdb + ports: + - port: 9984 + targetPort: 9984 + name: bdb-port + type: LoadBalancer +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: bdb +spec: + replicas: 1 + template: + metadata: + labels: + app: bdb + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: bigchaindb + image: bigchaindb/bigchaindb:master + args: + - start + env: + - name: BIGCHAINDB_DATABASE_HOST + value: mdb + - name: BIGCHAINDB_DATABASE_PORT + # TODO(Krish): remove hardcoded port + value: "27017" + - name: BIGCHAINDB_DATABASE_REPLICASET + value: bigchain-rs + - name: BIGCHAINDB_DATABASE_BACKEND + value: mongodb + - name: BIGCHAINDB_DATABASE_NAME + value: bigchain + - name: BIGCHAINDB_SERVER_BIND + value: 0.0.0.0:9984 + - name: BIGCHAINDB_KEYPAIR_PUBLIC + value: EEWUAhsk94ZUHhVw7qx9oZiXYDAWc9cRz93eMrsTG4kZ + - name: BIGCHAINDB_KEYPAIR_PRIVATE + value: 3CjmRhu718gT1Wkba3LfdqX5pfYuBdaMPLd7ENUga5dm + - name: BIGCHAINDB_BACKLOG_REASSIGN_DELAY + value: "120" + - name: BIGCHAINDB_KEYRING + value: "" + imagePullPolicy: IfNotPresent + ports: + - containerPort: 9984 + hostPort: 9984 + name: bdb-port + protocol: TCP + resources: + limits: + cpu: 200m + memory: 768Mi + livenessProbe: + httpGet: + path: / + port: 9984 + initialDelaySeconds: 15 + timeoutSeconds: 10 + readinessProbe: + httpGet: + path: / + port: 9984 + initialDelaySeconds: 15 + timeoutSeconds: 10 + restartPolicy: Always diff --git a/k8s/deprecated.to.del/bdb-mdb-dep.yaml b/k8s/deprecated.to.del/bdb-mdb-dep.yaml new file mode 100644 index 00000000..c985b285 --- /dev/null +++ b/k8s/deprecated.to.del/bdb-mdb-dep.yaml @@ -0,0 +1,89 @@ +############################################################### +# This config file runs bigchaindb:latest and connects to the # +# mongodb backend as a service # +############################################################### + +apiVersion: v1 +kind: Service +metadata: + name: bdb-mdb-service + namespace: default + labels: + name: bdb-mdb-service +spec: + selector: + app: bdb-mdb + ports: + - port: 9984 + targetPort: 9984 + name: bdb-api + type: LoadBalancer +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: bdb-mdb +spec: + replicas: 1 + template: + metadata: + labels: + app: bdb-mdb + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: bdb-mdb + image: bigchaindb/bigchaindb:latest + args: + - start + env: + - name: BIGCHAINDB_DATABASE_HOST + value: mdb-service + - name: BIGCHAINDB_DATABASE_PORT + value: "27017" + - name: BIGCHAINDB_DATABASE_REPLICASET + value: bigchain-rs + - name: BIGCHIANDB_DATABASE_BACKEND + value: mongodb + - name: BIGCHAINDB_DATABASE_NAME + value: bigchain + - name: BIGCHAINDB_SERVER_BIND + value: 0.0.0.0:9984 + - name: BIGCHAINDB_KEYPAIR_PUBLIC + value: EEWUAhsk94ZUHhVw7qx9oZiXYDAWc9cRz93eMrsTG4kZ + - name: BIGCHAINDB_KEYPAIR_PRIVATE + value: 3CjmRhu718gT1Wkba3LfdqX5pfYuBdaMPLd7ENUga5dm + - name: BIGCHAINDB_BACKLOG_REASSIGN_DELAY + value: "120" + - name: BIGCHAINDB_KEYRING + value: "" + imagePullPolicy: IfNotPresent + ports: + - containerPort: 9984 + hostPort: 9984 + name: bdb-port + protocol: TCP + volumeMounts: + - name: bigchaindb-data + mountPath: /data + resources: + limits: + cpu: 200m + memory: 768Mi + livenessProbe: + httpGet: + path: / + port: 9984 + initialDelaySeconds: 15 + timeoutSeconds: 10 + readinessProbe: + httpGet: + path: / + port: 9984 + initialDelaySeconds: 15 + timeoutSeconds: 10 + restartPolicy: Always + volumes: + - name: bigchaindb-data + hostPath: + path: /disk/bigchaindb-data diff --git a/k8s/deprecated.to.del/bdb-rdb-dep.yaml b/k8s/deprecated.to.del/bdb-rdb-dep.yaml new file mode 100644 index 00000000..06daca43 --- /dev/null +++ b/k8s/deprecated.to.del/bdb-rdb-dep.yaml @@ -0,0 +1,87 @@ +############################################################### +# This config file runs bigchaindb:latest and connects to the # +# rethinkdb backend as a service # +############################################################### + +apiVersion: v1 +kind: Service +metadata: + name: bdb-rdb-service + namespace: default + labels: + name: bdb-rdb-service +spec: + selector: + app: bdb-rdb + ports: + - port: 9984 + targetPort: 9984 + name: bdb-rdb-api + type: LoadBalancer +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: bdb-rdb +spec: + replicas: 1 + template: + metadata: + labels: + app: bdb-rdb + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: bdb-rdb + image: bigchaindb/bigchaindb:latest + args: + - start + env: + - name: BIGCHAINDB_DATABASE_HOST + value: rdb-service + - name: BIGCHAINDB_DATABASE_PORT + value: "28015" + - name: BIGCHIANDB_DATABASE_BACKEND + value: rethinkdb + - name: BIGCHAINDB_DATABASE_NAME + value: bigchain + - name: BIGCHAINDB_SERVER_BIND + value: 0.0.0.0:9984 + - name: BIGCHAINDB_KEYPAIR_PUBLIC + value: EEWUAhsk94ZUHhVw7qx9oZiXYDAWc9cRz93eMrsTG4kZ + - name: BIGCHAINDB_KEYPAIR_PRIVATE + value: 3CjmRhu718gT1Wkba3LfdqX5pfYuBdaMPLd7ENUga5dm + - name: BIGCHAINDB_BACKLOG_REASSIGN_DELAY + value: "120" + - name: BIGCHAINDB_KEYRING + value: "" + imagePullPolicy: IfNotPresent + ports: + - containerPort: 9984 + hostPort: 9984 + name: bdb-port + protocol: TCP + volumeMounts: + - name: bigchaindb-data + mountPath: /data + resources: + limits: + cpu: 200m + memory: 768Mi + livenessProbe: + httpGet: + path: / + port: 9984 + initialDelaySeconds: 15 + timeoutSeconds: 10 + readinessProbe: + httpGet: + path: / + port: 9984 + initialDelaySeconds: 15 + timeoutSeconds: 10 + restartPolicy: Always + volumes: + - name: bigchaindb-data + hostPath: + path: /disk/bigchaindb-data diff --git a/k8s/node-mdb-ss.yaml b/k8s/deprecated.to.del/node-mdb-ss.yaml similarity index 97% rename from k8s/node-mdb-ss.yaml rename to k8s/deprecated.to.del/node-mdb-ss.yaml index 304750c2..3c126d2d 100644 --- a/k8s/node-mdb-ss.yaml +++ b/k8s/deprecated.to.del/node-mdb-ss.yaml @@ -42,8 +42,8 @@ spec: spec: terminationGracePeriodSeconds: 10 containers: - - name: bdb-server - image: bigchaindb/bigchaindb:latest + - name: bigchaindb + image: bigchaindb/bigchaindb:master args: - start env: diff --git a/k8s/node-rdb-ss.yaml b/k8s/deprecated.to.del/node-rdb-ss.yaml similarity index 100% rename from k8s/node-rdb-ss.yaml rename to k8s/deprecated.to.del/node-rdb-ss.yaml diff --git a/k8s/deprecated.to.del/node-ss.yaml b/k8s/deprecated.to.del/node-ss.yaml new file mode 100644 index 00000000..9580daf6 --- /dev/null +++ b/k8s/deprecated.to.del/node-ss.yaml @@ -0,0 +1,89 @@ +##################################################### +# This config file uses bdb v0.9.1 with bundled rdb # +##################################################### + +apiVersion: v1 +kind: Service +metadata: + name: bdb-service + namespace: default + labels: + name: bdb-service +spec: + selector: + app: bdb + ports: + - port: 9984 + targetPort: 9984 + name: bdb-http-api + - port: 8080 + targetPort: 8080 + name: bdb-rethinkdb-api + type: LoadBalancer +--- +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + name: bdb + namespace: default +spec: + serviceName: bdb + replicas: 1 + template: + metadata: + name: bdb + labels: + app: bdb + annotations: + pod.beta.kubernetes.io/init-containers: '[ + { + "name": "bdb091-configure", + "image": "bigchaindb/bigchaindb:0.9.1", + "command": ["bigchaindb", "-y", "configure", "rethinkdb"], + "volumeMounts": [ + { + "name": "bigchaindb-data", + "mountPath": "/data" + } + ] + } + ]' + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: bdb091-server + image: bigchaindb/bigchaindb:0.9.1 + args: + - -c + - /data/.bigchaindb + - start + imagePullPolicy: IfNotPresent + ports: + - containerPort: 9984 + hostPort: 9984 + name: bdb-port + protocol: TCP + volumeMounts: + - name: bigchaindb-data + mountPath: /data + resources: + limits: + cpu: 200m + memory: 768Mi + livenessProbe: + httpGet: + path: / + port: 9984 + initialDelaySeconds: 15 + timeoutSeconds: 10 + readinessProbe: + httpGet: + path: / + port: 9984 + initialDelaySeconds: 15 + timeoutSeconds: 10 + restartPolicy: Always + volumes: + - name: bigchaindb-data + hostPath: + path: /disk/bigchaindb-data diff --git a/k8s/deprecated.to.del/rethinkdb-ss.yaml b/k8s/deprecated.to.del/rethinkdb-ss.yaml new file mode 100644 index 00000000..081a5f6c --- /dev/null +++ b/k8s/deprecated.to.del/rethinkdb-ss.yaml @@ -0,0 +1,75 @@ +#################################################### +# This config file runs rethinkdb:2.3 as a service # +#################################################### + +apiVersion: v1 +kind: Service +metadata: + name: rdb-service + namespace: default + labels: + name: rdb-service +spec: + selector: + app: rdb + ports: + - port: 8080 + targetPort: 8080 + name: rethinkdb-http-port + - port: 28015 + targetPort: 28015 + name: rethinkdb-driver-port + type: LoadBalancer +--- +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + name: rdb + namespace: default +spec: + serviceName: rdb + replicas: 1 + template: + metadata: + name: rdb + labels: + app: rdb + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: rethinkdb + image: rethinkdb:2.3 + imagePullPolicy: IfNotPresent + ports: + - containerPort: 8080 + hostPort: 8080 + name: rdb-http-port + protocol: TCP + - containerPort: 28015 + hostPort: 28015 + name: rdb-client-port + protocol: TCP + volumeMounts: + - name: rdb-data + mountPath: /data + resources: + limits: + cpu: 200m + memory: 768Mi + livenessProbe: + httpGet: + path: / + port: 8080 + initialDelaySeconds: 15 + timeoutSeconds: 10 + readinessProbe: + httpGet: + path: / + port: 8080 + initialDelaySeconds: 15 + timeoutSeconds: 10 + restartPolicy: Always + volumes: + - name: rdb-data + hostPath: + path: /disk/rdb-data diff --git a/k8s/mongodb/mongo-data-configdb-pvc.yaml b/k8s/mongodb/mongo-data-configdb-pvc.yaml new file mode 100644 index 00000000..7d3dc8a3 --- /dev/null +++ b/k8s/mongodb/mongo-data-configdb-pvc.yaml @@ -0,0 +1,18 @@ +########################################################## +# This YAML file desribes a k8s pvc for mongodb configDB # +########################################################## + +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: mongo-configdb-claim + annotations: + volume.beta.kubernetes.io/storage-class: slow-configdb +spec: + accessModes: + - ReadWriteOnce + # FIXME(Uncomment when ACS supports this!) + # persistentVolumeReclaimPolicy: Retain + resources: + requests: + storage: 20Gi diff --git a/k8s/mongodb/mongo-data-configdb-sc.yaml b/k8s/mongodb/mongo-data-configdb-sc.yaml new file mode 100644 index 00000000..b431db67 --- /dev/null +++ b/k8s/mongodb/mongo-data-configdb-sc.yaml @@ -0,0 +1,12 @@ +################################################################### +# This YAML file desribes a StorageClass for the mongodb configDB # +################################################################### + +kind: StorageClass +apiVersion: storage.k8s.io/v1beta1 +metadata: + name: slow-configdb +provisioner: kubernetes.io/azure-disk +parameters: + skuName: Standard_LRS + location: westeurope diff --git a/k8s/mongodb/mongo-data-db-pvc.yaml b/k8s/mongodb/mongo-data-db-pvc.yaml new file mode 100644 index 00000000..e9689346 --- /dev/null +++ b/k8s/mongodb/mongo-data-db-pvc.yaml @@ -0,0 +1,18 @@ +######################################################## +# This YAML file desribes a k8s pvc for mongodb dbPath # +######################################################## + +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: mongo-db-claim + annotations: + volume.beta.kubernetes.io/storage-class: slow-db +spec: + accessModes: + - ReadWriteOnce + # FIXME(Uncomment when ACS supports this!) + # persistentVolumeReclaimPolicy: Retain + resources: + requests: + storage: 20Gi diff --git a/k8s/mongodb/mongo-data-db-sc.yaml b/k8s/mongodb/mongo-data-db-sc.yaml new file mode 100644 index 00000000..f700223d --- /dev/null +++ b/k8s/mongodb/mongo-data-db-sc.yaml @@ -0,0 +1,12 @@ +################################################################# +# This YAML file desribes a StorageClass for the mongodb dbPath # +################################################################# + +kind: StorageClass +apiVersion: storage.k8s.io/v1beta1 +metadata: + name: slow-db +provisioner: kubernetes.io/azure-disk +parameters: + skuName: Standard_LRS + location: westeurope diff --git a/k8s/mongodb/mongo-ss.yaml b/k8s/mongodb/mongo-ss.yaml new file mode 100644 index 00000000..63c7d27d --- /dev/null +++ b/k8s/mongodb/mongo-ss.yaml @@ -0,0 +1,76 @@ +######################################################################## +# This YAML file desribes a StatefulSet with a service for running and # +# exposing a MongoDB service. # +# It depends on the configdb and db k8s pvc. # +######################################################################## + +apiVersion: v1 +kind: Service +metadata: + name: mdb + namespace: default + labels: + name: mdb +spec: + selector: + app: mdb + ports: + - port: 27017 + targetPort: 27017 + name: mdb-port + type: LoadBalancer +--- +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + name: mdb + namespace: default +spec: + serviceName: mdb + replicas: 1 + template: + metadata: + name: mdb + labels: + app: mdb + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: mongodb + image: mongo:3.4.1 + args: + - --replSet=bigchain-rs + securityContext: + capabilities: + add: + - FOWNER + imagePullPolicy: IfNotPresent + ports: + - containerPort: 27017 + hostPort: 27017 + name: mdb-port + protocol: TCP + volumeMounts: + - name: mdb-db + mountPath: /data/db + - name: mdb-configdb + mountPath: /data/configdb + resources: + limits: + cpu: 200m + memory: 768Mi + livenessProbe: + tcpSocket: + port: mdb-port + successThreshold: 1 + failureThreshold: 3 + periodSeconds: 15 + timeoutSeconds: 1 + restartPolicy: Always + volumes: + - name: mdb-db + persistentVolumeClaim: + claimName: mongo-db-claim + - name: mdb-configdb + persistentVolumeClaim: + claimName: mongo-configdb-claim diff --git a/k8s/toolbox/Dockerfile b/k8s/toolbox/Dockerfile new file mode 100644 index 00000000..6bcb1298 --- /dev/null +++ b/k8s/toolbox/Dockerfile @@ -0,0 +1,12 @@ +# Toolbox container for debugging +# Run as: +# docker run -it --rm --entrypoint sh krish7919/toolbox +# kubectl run -it toolbox --image krish7919/toolbox --restart=Never --rm + +FROM alpine:3.5 +MAINTAINER github.com/krish7919 +WORKDIR / + +RUN apk add --no-cache curl bind-tools + +ENTRYPOINT ["/bin/sh"] diff --git a/k8s/toolbox/README.md b/k8s/toolbox/README.md new file mode 100644 index 00000000..b9000ab1 --- /dev/null +++ b/k8s/toolbox/README.md @@ -0,0 +1,12 @@ +## Docker container with debugging tools + +* curl +* bind-utils - provides nslookup, dig + +## Build + +`docker build -t bigchaindb/toolbox .` + +## Push + +`docker push bigchaindb/toolbox` diff --git a/tests/backend/mongodb/test_connection.py b/tests/backend/mongodb/test_connection.py index 786b7d7b..6350a7c5 100644 --- a/tests/backend/mongodb/test_connection.py +++ b/tests/backend/mongodb/test_connection.py @@ -32,15 +32,15 @@ def mongodb_connection(): port=bigchaindb.config['database']['port']) -def test_get_connection_returns_the_correct_instance(): +def test_get_connection_returns_the_correct_instance(db_host, db_port): from bigchaindb.backend import connect from bigchaindb.backend.connection import Connection from bigchaindb.backend.mongodb.connection import MongoDBConnection config = { 'backend': 'mongodb', - 'host': 'localhost', - 'port': 27017, + 'host': db_host, + 'port': db_port, 'name': 'test', 'replicaset': 'bigchain-rs' }