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

fixed issues with new version of k8s/minikube #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions resources/mongodb-service.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
apiVersion: v1
kind: Service
metadata:
name: mongodb-service
name: mongo
labels:
name: mongo
app: mongo
spec:
ports:
- port: 27017
name: mongo
targetPort: 27017
clusterIP: None
selector:
role: mongo
app: mongo
---
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongod
name: mongo
spec:
serviceName: mongodb-service
selector:
matchLabels:
app: mongo
serviceName: mongo
replicas: 3
template:
metadata:
labels:
role: mongo
environment: test
replicaset: MainRepSet
app: mongo
spec:
affinity:
podAntiAffinity:
Expand All @@ -46,11 +48,8 @@ spec:
defaultMode: 256
containers:
- name: mongod-container
#image: pkdone/mongo-ent:3.4
image: mongo
image: docker.io/library/mongo:4.2.5
command:
- "numactl"
- "--interleave=all"
- "mongod"
- "--wiredTigerCacheSizeGB"
- "0.1"
Expand All @@ -65,10 +64,6 @@ spec:
- "/etc/secrets-volume/internal-auth-mongodb-keyfile"
- "--setParameter"
- "authenticationMechanisms=SCRAM-SHA-1"
resources:
requests:
cpu: 0.2
memory: 200Mi
ports:
- containerPort: 27017
volumeMounts:
Expand All @@ -87,4 +82,3 @@ spec:
resources:
requests:
storage: 1Gi

6 changes: 3 additions & 3 deletions scripts/configure_repset_auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ fi

# Initiate replica set configuration
echo "Configuring the MongoDB Replica Set"
kubectl exec mongod-0 -c mongod-container -- mongo --eval 'rs.initiate({_id: "MainRepSet", version: 1, members: [ {_id: 0, host: "mongod-0.mongodb-service.default.svc.cluster.local:27017"}, {_id: 1, host: "mongod-1.mongodb-service.default.svc.cluster.local:27017"}, {_id: 2, host: "mongod-2.mongodb-service.default.svc.cluster.local:27017"} ]});'
kubectl exec mongo-0 -c mongod-container -- mongo --eval 'rs.initiate({_id: "MainRepSet", version: 1, members: [ {_id: 0, host: "mongo-0.mongo.default.svc.cluster.local:27017"}, {_id: 1, host: "mongo-1.mongo.default.svc.cluster.local:27017"}, {_id: 2, host: "mongo-2.mongo.default.svc.cluster.local:27017"} ]});'

# Wait a bit until the replica set should have a primary ready
echo "Waiting for the Replica Set to initialise..."
sleep 30
kubectl exec mongod-0 -c mongod-container -- mongo --eval 'rs.status();'
kubectl exec mongo-0 -c mongod-container -- mongo --eval 'rs.status();'

# Create the admin user (this will automatically disable the localhost exception)
echo "Creating user: 'main_admin'"
kubectl exec mongod-0 -c mongod-container -- mongo --eval 'db.getSiblingDB("admin").createUser({user:"main_admin",pwd:"'"${1}"'",roles:[{role:"root",db:"admin"}]});'
kubectl exec mongo-0 -c mongod-container -- mongo --eval 'db.getSiblingDB("admin").createUser({user:"main_admin",pwd:"'"${1}"'",roles:[{role:"root",db:"admin"}]});'
echo

4 changes: 2 additions & 2 deletions scripts/delete_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
##

# Just delete mongod stateful set + mongodb service onlys (keep rest of k8s environment in place)
kubectl delete statefulsets mongod
kubectl delete services mongodb-service
kubectl delete statefulsets mongo
kubectl delete services mongo

# Show persistent volume claims are still reserved even though mongod stateful-set has been undeployed
kubectl get persistentvolumes
Expand Down
6 changes: 3 additions & 3 deletions scripts/teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
##

# Delete mongod stateful set + mongodb service + secrets + host vm configuer daemonset
kubectl delete statefulsets mongod
kubectl delete services mongodb-service
kubectl delete statefulsets mongo
kubectl delete services mongo
kubectl delete secret shared-bootstrap-data
sleep 3

# Delete persistent volume claims
kubectl delete persistentvolumeclaims -l role=mongo
kubectl delete persistentvolumeclaims -l app=mongo