diff --git a/resources/mongodb-service.yaml b/resources/mongodb-service.yaml index 6b47e66..f3bd350 100644 --- a/resources/mongodb-service.yaml +++ b/resources/mongodb-service.yaml @@ -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: @@ -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" @@ -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: @@ -87,4 +82,3 @@ spec: resources: requests: storage: 1Gi - diff --git a/scripts/configure_repset_auth.sh b/scripts/configure_repset_auth.sh index 270f58e..75314c6 100755 --- a/scripts/configure_repset_auth.sh +++ b/scripts/configure_repset_auth.sh @@ -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 diff --git a/scripts/delete_service.sh b/scripts/delete_service.sh index 2ff4b03..4e0313a 100755 --- a/scripts/delete_service.sh +++ b/scripts/delete_service.sh @@ -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 diff --git a/scripts/teardown.sh b/scripts/teardown.sh index fe00305..f437b72 100755 --- a/scripts/teardown.sh +++ b/scripts/teardown.sh @@ -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