 Hello, everyone. This video is about using persistent storage with OpenShift version 3. In order to understand why we need persistent storage, let's look at an example first of a non-persistent storage. If you have seen my earlier videos, you would already know how to spin up my SQL application component on OpenShift, and I did exactly the same thing. I have a ephemeral MySQL database that is spun up, and let's use it first to see how it looks like. First, I'll do port forwarding to my MySQL database. Now, this command will port forward to the part that is running the MySQL database, and any traffic that I send to my local host on port 3306 will be forwarded to this part. Now, let's connect to this database. Here, I'm connecting to my local host. It's 127.001, and I'm connecting to port 3306 because this gets forwarded to the part. I'm using username v and password v, which I gave when I was creating that database. If I say show databases, it will show me a sample database. I'll use that. I'll add a table named users, and I'll insert a few rows. Now, if I do select start from users, you'll see that there are three records. I'll exit from this database. Now, there is some data that I added to this database. Let me cancel this port forwarding. If you see, I have one instance of MySQL running here, and let me go and kill that OC delete part. What you'll observe is immediately the replication controller acts immediately, and this is the part that is gone. A new part replaces in its place because I deleted it physically, which is good. If an instance goes down, another instance comes in its place. OpenShifter is doing its job. Now, it's still in the pending status. Let's wait till it gets to running. It's running now. Let me do a port forwarding to this database. Now, I'm doing the same exact thing again. I'm connecting to my local host on port 3306. Show databases. It shows the sample database. I say use sample, and when I say show tables, earlier we inserted table, and it's gone. So the data that was written to the database, the previous instance of the part is all gone because it is ephemeral. So why did that happen? When we were writing data to our MySQL part, in case of an ephemeral storage instance, that the data was being written inside the part. So when the part went off, the data also got deleted along with the part. So although the part comes back up, the data inside the part is gone because it's a new instance of part. So how do we deal with it? That's the place where persistent storage comes into picture. In case of persistent storage, you would have the part separated out from where you write your data. So you would mount your persistent storage onto the part, in which case, for example, if a part dies for some reason, OpenShift will create a new part, and it will also mount the persistent storage that was there before. So you'll not lose any data. Let's see how it works. Now in order for our applications to use persistent storage, we need to do a couple of things. One, the administrator needs to set up persistent storage or make persistent storage available for the applications to use, which involves making the persistent storage available as what we call persistent volume in OpenShift. We are using NFS here as an example, but you could be using Gluster or CIF or any other storage technology. OpenShift currently supports NFS, but very soon it's going to support Gluster, CIF and other technologies as well. If you look at the NFS exports, I have a couple of exports here. They are via export wall 1 and wall 2, and they are set up as read, write, sing, call, squash. Now as an administrator on the OpenShift host, I'm trying to set up a persistent volume. Actually, I already have a persistent volume, so one of them is mounted as PV001. Now let me show you what I have. I mounted the var export wall 1, which we have seen here, the first one with the name PV001. Now let's mount another one as PV002. I'm just copying this all I'm going to do is say that the name of the volume is PV002, the size in my case is 512 megabytes, and I'm volume 2, and this is on so and so NFS server. This is the IP address of my NFS server. After making this change, I'm just going to create based on this file. Now it has mounted PV002. So if I do OC get PV, I should see two volumes here. One is with 5 gigabytes storage, and the other one is 512 megabytes storage, and it's PV001 and PV002. So I have two different persistent volumes. They are not used yet. They are still available. Now the job of administrator is done. We made the persistent volume available. Now let's use that persistent volume. So I have a new project, and I'm going to create a database using MySQL persistent template. So here you see MySQL persistent template. I'm going to use that, and I will edit the parameters. I will give the same username password. We call it sample database, and the capacity that it is asking for is 512 megabytes. Remember we had two persistent volumes. One is 512 megabytes, and the other one is 5 gigabytes. So there are two available, and this guy is asking for 512 MB. Now let's say create. Now at this time, OpenShift will spin up a new pod for this MySQL database, and it will also create what we call persistent volume claim, because this is a persistent database. It will ask for persistent volume claim, which will go and use one of those persistent volumes available. So I'm using the persistent project. If I say OC get pods, this MySQL pod is spinning up. It's not ready yet. And if I run OC get PVC, PVC stands for persistent volume claim, and this is done by the user who is asking for it. And if you look at it, it is actually now, it has created a persistent volume claim, and that persistent volume claim is bound to PV0002. Now going back to the master, if you look at PV001, that was 5 gigabytes, and PV002 was 512 megabytes. We asked for 512 megabytes. So OpenShift has automatically matched in spite of two being available. It picked the one of the right size, and it got that allocated to the persistent volume claim. Now if I do run OC get PV, it shows that the persistent volume 002 is bound to the MySQL volume claim that got created when we created the application. Now let's use this and see how it works. Now I'll do the same thing like before. I'll port forward to the MySQL pod, and from the other window, I'll try to access the MySQL client. I'll use the sample database. I'll add a table. I'll insert a few users. I see all my users exit. Now let me cancel port forwarding, and let me delete the pod like before. OpenShift spins up a new pod again. It's in the pending status. Now it is running. Let me port forward to this again. I'll go back and connect to this new pod this time. Use sample database, show tables. Now the users table that we added before is still there. In case of our non-persistent example, this was missing. So let's say select star from users. It shows the data. So this is exactly what we wanted. So even if you delete the pod, another pod comes up. It connects to the same persistent storage as before, and the data is available to use. So that gives us the advantage of persistent storage behind the pod. This is just one example. Database is just a simple example. You could be using persistent storage in different ways. Perhaps you could be writing some data as files directly from your application onto the persistent storage, that data is available across multiple pods. So effectively, you could have multiple pods of your application sharing the same persistent storage at the same time. So they could all be writing data into the persistent storage, and it is available across all the applications. So to summarize, the administrator creates a persistent volume and makes it available, and the users or the projects can claim the persistent volumes as persistent volume claims. OpenShift will look at the list of available persistent volumes that are available to use, and it will allocate a persistent volume or it will grab a persistent volume of appropriate storage size that is equal to or a little higher than the size that is being asked for. And that's how it works. I hope you enjoyed the video. Thanks a lot for watching.