Learning Kubernetes through experimentation.
I'm working on Windows, I have multiple minor issues when I try several things with minikube and docker, so I will work into the WSL2 environment.
Docker Desktop for Windows allows to use it from within WSL2. I clone my repository within the WSL2 environment to dodge any further Windows Linux conflicts.
cd ~/repositories/
git clone <github project>
Follow these steps to install the required tools.
Branch simple-mongodb-deployment
The goal here is to learn to deploy the following :
- Mongodb
- Mongo-express (web-application)
We won't use Helm charts.
We don't want the mongodb to be publicly reachable, so we will expose it only within the k8s cluster.
We will access the mongodb only through mongo-express, so it will be publicly reachable.
We will not set a Persistent Volume (PV).
- Launch Docker Desktop on Windows
- minikube start
- Create the mongodb deployment
- Create the secret
- Apply the secret
- Reference values from the secret into the mongodb deployment
- Apply the deployment
- Create the mongodb service (internal, ClusterIP) in the same file as the deployment
- Create the ConfigMap (contain the mongodb server address) and apply it
- Create the mongo-express deployment and apply it
- Create the mongo-express LoadBalancer service in the same file and reapply it
- Run
minikube service mongo-express-service
Branch persistent-volume
The goal is to learn how to add a persistent volume.
- Create a Persistent Volume (local for learning, in production I would use a StorageClass)
- Turn "Headless" the mongodb service (needed for StatefulSets to allow stable network identities)
- Replace the mongodb Deployment with a StatefulSet
kubectl apply -f config-map.yamlkubectl apply -f secret.yamlkubectl apply -f persistent-volume.yamlkubectl apply -f mongodb-stateful.yamlkubectl apply -f mongo-express.yamlkubectl get pods --watchminikube service mongo-express-service
We don't need a PVC because the StatefulSet handle it with its volumeClaimTemplates.
- Go on mongo-express to create a database
kubectl delete pod mongodb-statefulset-0: k8s delete the pod and recreate it automatically.- Once the pod is recreated and running, return to mongo-express and check that the created database is still present.