< Previous Challenge - Home - Next Challenge >
Not all containers can be stateless. What happens when your application needs to have some persistent storage?
In this challenge we will be creating Azure data disks and using the Kubernetes storage mechanism to make them available to be attached to running containers. This will give MongoDB a place to storage its data without losing it when the container is stopped and restarted.
whatthehackmsft/content-api:v2
whatthehackmsft/content-web:v2
/Challenge-08
folder of the Resources.zip
package for starter templatesVerify that MongoDB is working fine by connecting to the corresponding MongoDB Pod in interactive mode. Make sure that the disks are associated correctly (bold and italic below)
kubectl exec -it <mongo-db pod name> bash
root@mongo-db678745655b-f82vj:/#
df -Th
Filesystem Type Size Used Avail Use% Mounted on
overlay overlay 30G 4.2G 25G 15% /
tmpfs tmpfs 1.7G 0 1.7G 0% /dev
tmpfs tmpfs 1.7G 0 1.7G 0% /sys/fs/cgroup
/dev/sdc ext4 2.0G 304M 1.5G 17% /data/db
/dev/sdd ext4 2.0G 3.0M 1.8G 1% /data/configdb
/dev/sda1 ext4 30G 4.2G 25G 15% /etc/hosts
shm tmpfs 64M 0 64M 0% /dev/shm
tmpfs tmpfs 1.7G 12K 1.7G 1% /run/secrets/kubernetes.io/serviceaccount
tmpfs tmpfs 1.7G 0 1.7G 0% /sys/firmware
root@mongo-db678745655b-f82vj:/#
mongosh --version
MongoDB shell version v3.6.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.1
contentdb
database is populated by connecting to the MongoDB pod with an interactive terminal and verify the database “contentdb” exists.
root@mongo-db678745655b-f82vj:/#
mongo
MongoDB shell version v3.6.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.1
> show dbs
admin 0.000GB
config 0.000GB
contentdb 0.000GB
local 0.000GB
kubectl delete pod <mongo-db-pod>
http://<yourWebServicePIP>:3000/speakers.html
http://<yourWebServicePIP>:3000/sessions.html
Discuss with your coach what would happen if the Node running the MongoDB pod were to crash or be shut down. Would Kubernetes be able to re-deploy the pod on a different node? How do availability zones play into this?