Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruanbekker/mongodb #8

Merged
merged 2 commits into from Oct 9, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -0,0 +1,71 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongodb-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: $VOLUME_SIZE
accessModes:
- ReadWriteOnce
hostPath:
path: "/data/db"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongodb-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: $VOLUME_SIZE
---
apiVersion: v1
kind: Service
metadata:
name: mongodb
spec:
ports:
- port: 27017
selector:
app: mongodb
clusterIP: None
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: mongodb
spec:
selector:
matchLabels:
app: mongodb
strategy:
type: Recreate
template:
metadata:
labels:
app: mongodb
spec:
containers:
- image: mongo:4.2.0
name: mongodb
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: $MONGODB_ROOT_USERNAME
- name: MONGO_INITDB_ROOT_PASSWORD
value: $MONGODB_ROOT_PASSWORD
ports:
- containerPort: 27017
name: mongodb
volumeMounts:
- name: mongodb-persistent-storage
mountPath: /data/db
volumes:
- name: mongodb-persistent-storage
persistentVolumeClaim:
claimName: mongodb-pv-claim
BIN +3.06 KB mongodb/logo.png
Binary file not shown.
@@ -0,0 +1,29 @@
---
name: MongoDB
version: 4.2.0
maintainer: hello@civo.com
description: MongoDB document databases provide high availability and easy scalability.
url: https://www.mongodb.com
category: database
dependencies:
- Longhorn
plans:
- label: "5GB"
configuration:
VOLUME_SIZE:
value: 5Gi
- label: "10GB"
configuration:
VOLUME_SIZE:
value: 10Gi
- label: "20GB"
configuration:
VOLUME_SIZE:
value: 20Gi
configuration:
MONGODB_ROOT_USERNAME:
label: "Root username"
value: "CIVO:ALPHANUMERIC(30)"
MONGODB_ROOT_PASSWORD:
label: "Root password"
value: "CIVO:ALPHANUMERIC(30)"
@@ -0,0 +1,48 @@
## MongoDB

### External access

By default external access to the MongoDB port isn't available. This is easily changed by applying the following YAML to your cluster with `kubectl apply -f mongodb-service.yaml` (or whatever you call the file containing the contents below):

```
apiVersion: v1
kind: Service
metadata:
name: mongodb-service
spec:
type: LoadBalancer
ports:
- port: 27017
targetPort: 27017
protocol: TCP
selector:
app: mongodb
```

This will open up YOUR_CLUSTER_ID.k8s.civo.com:27017 to the whole world. You should lock this down in the [firewall](https://www.civo.com/account/firewalls) automatically created in Civo for your Kubernetes cluster. Locking down the firewall will only affect access from OUTSIDE of your Kubernetes cluster, access from your applications within Kubernetes will not be affected.

### Usage instruction

You can use this application from within your cluster by just using the hostname `mongodb` and can create databases and users using the `root` access credentials above this message. For example, to create an application's database and user credentials and given that the `kubectx` and [Civo CLI](https://github.com/civo/cli) are installed, with a Civo Kubernetes cluster called `my-cluster-name`:

```
$ civo k3s config my-cluster-name --save
$ kubectx my-cluster-name
$ kubectl run tmp-shell --generator=run-pod/v1 --rm -i \
--tty --image alpine:3.9 -- /bin/sh
/ # apk update
/ # apk add mongodb
/ # mongo mongodb://root:password@mongodb:27017/test?authSource=admin
> use people
switched to db people
> db.collection1.insert({"name": "ruan", "surname": "bekker"})
WriteResult({ "nInserted" : 1 })
> db.collection1.find().pretty()
{
"_id" : ObjectId("5d9dc2bd8d1d65fd1e25f41b"),
"name" : "ruan",
"surname" : "bekker"
}
```
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.