This example shows different types of storage options that can be used. Because a local Kubernetes is running (with a single Node), we'll only use the local-storage option, however in cloud scenarios the SC/PVC could be modififed as appropriate for the cloud provider's storage options.
- Create the following folder structure on your local system:
Mac/Linux: /tmp/data/db Windows: c:/temp/data/db
-
If you're on Windows go into
mongo.deployment.ymland change the PersistentVolume's local path to/c/temp/data/db. Save the file. -
Run the following to add the database passwords as secrets:
kubectl create secret generic db-passwords --from-literal=db-password='password' --from-literal=db-root-password='password' -
Start up the Pod:
kubectl create -f mongo.deployment.yml -
Run
kubectl get podsto see the pod. -
Run
k exec [mongo-pod-name] -it shto shell into the container. Run themongocommand to make sure the database is working. Typeexitto exit the shell.Note: If you have a tool that can hit MongoDB externally you can
kubectl port-forwardto the pod to expose 27017. -
Delete the mongo Pod:
kubectl delete pod [mongo-pod-name] -
Once the pod is deleted, run
kubectl get pvand note the reclaim policy that's shown and the status (should show Bound since the policy was Retain -
Delete everything else:
kubectl delete -f mongo.deployment.yml