tl;dr: I'm about to open a bounty on StackOverflow because I'm stuck setting up a Mongo StatefulSet on K8s.
Yes, it is my day off but I really want to learn K8s 😤.
Edit: Doh, about 30 minutes after I made the bounty I ended up figuring out the issue in my question. Waste of 50 reputation on StackoverFlow but at the same time maybe it gave me the motivation to look closer. Still don't have mongo running though ... new issue relating to not having created my local persistent volume correctly.
I'm still trying to convert our Docker Cloud setup to Kubernetes.
To make things easier I'm breaking that larger task up into several smaller ones.
Currently I'm trying to replicate our MongoDb setup. We have a replica set of 3 just like in the picture below (though we don't have the k8s or side-car part) (though we don't have the k8s or side-car part).
The image is from an article I found that talks about setting up Mongo inside a StatefulSet in Kubernetes. Each of the 3 pods inside the StatefulSet include a "sidecar" which assists with configuration (still reading about this, new concept).
I found an example on github which looks very similar to what I need for a basic mongo replica set:
apiVersion: v1
kind: Service
metadata:
name: mongo
labels:
name: mongo
spec:
ports:
- port: 27017
targetPort: 27017
clusterIP: None
selector:
role: mongo
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: mongo
spec:
serviceName: "mongo"
replicas: 3
template:
metadata:
labels:
role: mongo
environment: test
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mongo
image: mongo
command:
- mongod
- "--replSet"
- rs0
- "--bind_ip"
- 0.0.0.0
- "--smallfiles"
- "--noprealloc"
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
- name: mongo-sidecar
image: cvallance/mongo-k8s-sidecar
env:
- name: MONGO_SIDECAR_POD_LABELS
value: "role=mongo,environment=test"
volumeClaimTemplates:
- metadata:
name: mongo-persistent-storage
annotations:
volume.beta.kubernetes.io/storage-class: "fast"
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 2Gi
The issue I'm having is the persistent volume claims. I've made a persistent volume but the connection doesn't seem to happen.
I keep getting this error that the PersistentVolumeClaim is not bound.
I'd really love to get this working. If anyone has information or suggestions to put me in the right direction please let me know! I'm so stuck right now.
In writing this post I came across a site which seems to be dedicated to information about running Mongo on K8s.
It seems they say the "side-car" approach shown above shouldn't be used:
WARNING: Some online resources advocate deploying a sidecar, called mongo-k8s-sidecar, to help “auto-configure” a MongoDB cluster. Do NOT employ that approach in Production environments, because this will result in non-deterministic behaviour, adversely affecting database resiliency.
The good thing is it looks like I have lots more to read. Hopefully with this information I can get everything setup and I'll go back and answer my own question.
Edit #2: I'm outside the Google office in Montreal. Can anyone help me?!