cdk8s-mongo-sts
Create a Replicated, Password protected MongoDB Statefulset on Kubernetes, powered by the cdk8s project 🚀
Disclaimer
This construct is under heavy development, and breaking changes will be introduced very often. Please don't forget to version lock your code if you are using this construct.
Overview
cdk8s-mongo-sts is a cdk8s library, and also uses cvallance/mongo-k8s-sidecar to manage the MongoDB replicaset.
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from constructs import Construct
from cdk8s import App, Chart, ChartProps
from cdk8s_mongo_sts import MyMongo
class MyChart(Chart):
def __init__(self, scope, id, *, namespace=None, labels=None):
super().__init__(scope, id, namespace=namespace, labels=labels)
MyMongo(self, "dev",
image="mongo",
namespace="databases",
default_replicas=3,
volume_size="10Gi",
create_storage_class=True,
volume_provisioner="kubernetes.io/aws-ebs",
storage_class_name="io1-slow",
storage_class_params={
"type": "io1",
"fs_type": "ext4",
"iops_per_gB": "10"
},
node_selector_params={
"database": "dev"
}
)
app = App()
MyChart(app, "asd")
app.synth()
Create a secret for your DB that starts with the same name as your Statefulset with the following keys :
username
password
See this for documentation on Kubernetes secrets.
Then the Kubernetes manifests created by cdk8s synth command will have Kubernetes resources such as Statefulset, Service, ClusterRole, ClusterRoleBinding, ServiceAccount, and StorageClass as follows.
manifest.k8s.yaml
allowVolumeExpansion: true
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: io1-slow
parameters:
fsType: ext4
type: io1
iopsPerGB: "10"
provisioner: kubernetes.io/aws-ebs
reclaimPolicy: Retain
---
apiVersion: v1
kind: Service
metadata:
name: dev
namespace: databases
spec:
clusterIP: None
ports:
- port: 27017
targetPort: 27017
selector:
db: dev
type: ClusterIP
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: get-pods-role
namespace: databases
rules:
- apiGroups:
- "*"
resources:
- pods
verbs:
- list
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: dev
namespace: databases
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: dev
namespace: databases
roleRef:
apiGroup: ""
kind: ClusterRole
name: get-pods-role
subjects:
- kind: ServiceAccount
name: dev
namespace: databases
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: dev
namespace: databases
spec:
replicas: 3
selector:
matchLabels:
db: dev
serviceName: dev
template:
metadata:
labels:
db: dev
spec:
containers:
- env:
- name: MONGO_SIDECAR_POD_LABELS
value: db=dev
- name: KUBE_NAMESPACE
value: databases
- name: MONGODB_DATABASE
value: admin
- name: MONGODB_USERNAME
valueFrom:
secretKeyRef:
key: username
name: dev
- name: MONGODB_PASSWORD
valueFrom:
secretKeyRef:
key: password
name: dev
image: cvallance/mongo-k8s-sidecar
name: mongo-sidecar
- args:
- --replSet
- rs0
- --bind_ip
- 0.0.0.0
- --dbpath
- /data/db
- --oplogSize
- "128"
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
key: username
name: dev
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
key: password
name: dev
image: mongo
name: dev
ports:
- containerPort: 27017
resources:
limits:
cpu: 400m
memory: 512Mi
requests:
cpu: 200m
memory: 256Mi
volumeMounts:
- mountPath: /data/db
name: dev
nodeSelector:
database: dev
securityContext:
fsGroup: 999
runAsGroup: 999
runAsUser: 999
serviceAccountName: dev
terminationGracePeriodSeconds: 10
volumeClaimTemplates:
- metadata:
name: dev
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: io1-slow
Installation
TypeScript
Use npm or yarn to install.
$ npm install -s cdk8s-mongo-sts
or
$ yarn add cdk8s-mongo-sts
Python
$ pip install cdk8s-mongo-sts
Contribution
-
Fork (https://github.com/Hunter-Thompson/cdk8s-mongo-sts/fork)
-
Bootstrap the repo:
npx projen # generates package.json yarn install # installs dependencies
-
Development scripts:
Command Description yarn compileCompiles typescript => javascript yarn watchWatch & compile yarn testRun unit test & linter through jest yarn test -uUpdate jest snapshots yarn run packageCreates a distwith packages for all languages.yarn buildCompile + test + package yarn bumpBump version (with changelog) based on [conventional commits] yarn releaseBump + push to master -
Create a feature branch
-
Commit your changes
-
Rebase your local changes against the master branch
-
Create a new Pull Request (use conventional commits for the title please)
Licence
Author
Metadata
Release files for cdk8s-mongo-sts 0.0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cdk8s-mongo-sts-0.0.11.tar.gz | 321.9 kB | Without provenance | Details for cdk8s-mongo-sts-0.0.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cdk8s_mongo_sts-0.0.11-py3-none-any.whl | Python 3 | none | any | Details for cdk8s_mongo_sts-0.0.11-py3-none-any.whl |
Total release size: 641.6 kB
Release files / cdk8s-mongo-sts-0.0.11.tar.gz
| Download URL | cdk8s-mongo-sts-0.0.11.tar.gz |
|---|---|
| Size | 321.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a551ce701a21a810ee3342add0d833702657da2ea0138b70b93061f91e65764
|
|
BLAKE2b-256 checksum How to use checksums |
5a1fe81477993979bdb2faa07052de93dce4c9bc1c5d73aa3da00d937d184c7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.9
|
Release files / cdk8s_mongo_sts-0.0.11-py3-none-any.whl
| Download URL | cdk8s_mongo_sts-0.0.11-py3-none-any.whl |
|---|---|
| Size | 319.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
436c29e882e0ee459a2328a1d61504fc92322fb0169ff3c817ff06241c503b4a
|
|
BLAKE2b-256 checksum How to use checksums |
06edc507776ab5fdda3523697fcce5360af0ef1a8b196c2c7bbc8dc5cb9e5254
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.9
|
Security for cdk8s-mongo-sts 0.0.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.