Skip to content

Instantly share code, notes, and snippets.

@antweiss
Last active May 1, 2019 09:13
Show Gist options
  • Save antweiss/2193967b43684a0cf94c1000e5d2ce69 to your computer and use it in GitHub Desktop.
Save antweiss/2193967b43684a0cf94c1000e5d2ce69 to your computer and use it in GitHub Desktop.
An epehemeral StatefulSet to run a MongoDB replicaset on Kubernetes - use for tests that require a temporary replicaset
# a headless service to make mongo pods available at mongo-0.mongo, mongo-1.mongo, mongo-2.mongo
# to connect to the replicaset use: mongo -server rs0/mongo-0.mongo,mongo-1.mongo,mongo-2.mongo
apiVersion: v1
kind: Service
metadata:
name: mongo
labels:
role: mongo
environment: test
spec:
ports:
- port: 2717
name: default
clusterIP: None
selector:
role: mongo
environment: test
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongo
labels:
role: mongo
environment: test
spec:
selector:
matchLabels:
role: mongo
environment: test
serviceName: "mongo"
replicas: 3
template:
metadata:
labels:
role: mongo
environment: test
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mongo
image: mongo
ports:
- containerPort: 27017
name: default
args:
- "--replSet"
- rs0
- "--smallfiles"
- "--noprealloc"
- "--bind_ip"
- 0.0.0.0
- name: mongo-sidecar
image: cvallance/mongo-k8s-sidecar
env:
- name: MONGO_SIDECAR_POD_LABELS
value: "role=mongo,environment=test"
@antweiss
Copy link
Author

antweiss commented Apr 30, 2019

Deploy by running kubectl create -f https://gist.githubusercontent.com/antweiss/2193967b43684a0cf94c1000e5d2ce69/raw/89683e3d68c250b9be484f43527c5ce689ef8c33/mongo-replicaset-on-k8s-for-tests.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment