CloudNativePG: Kubernetes Databases Made Simple (Full Course)
Read full transcript 17 segments
-
running databases on kubernetes is scary running databases on kubernetes is scary everything is supposed to be stateless everything is supposed to be stateless everything is supposed to be stateless right all wrong I've been running right all wrong I've been running right all wrong I've been running databases on kubernetes for several databases on kubernetes for several databases on kubernetes for several years both at home and in production at years both at home and in production at years both at home and in production at work and in this video I'm going to work and in this video I'm going to work and in this video I'm going to teach you everything you need to know to teach you everything you need to know to teach you everything you need to know to start running databases on kubernetes so start running databases on kubernetes so start running databases on kubernetes so let's jump in we are going to be using let's jump in we are going to be using let's jump in we are going to be using the cloud native PG operator and an the cloud native PG operator and an the cloud native PG operator and an operator is something that enables operator is something that enables operator is something that enables custom resources to be deployed on your custom resources to be deployed on your custom resources to be deployed on your kubernetes cluster and that's something kubernetes cluster and that's something kubernetes cluster and that's something that we're going to I'm going to show that we're going to I'm going to show that we're going to I'm going to show you right after this but this is an you right after this but this is an you right after this but this is an open-source community-driven open-source community-driven open-source community-driven operator that you can install for free operator that you can install for free operator that you can install for free and actually on my home lab I'm using and actually on my home lab I'm using and actually on my home lab I'm using the EDB operator but now they have moved the EDB operator but now they have moved the EDB operator but now they have moved to a subscription model so it's not free to a subscription model so it's not free to a subscription model so it's not free to run anymore so in this tutorial we to run anymore so in this tutorial we to run anymore so in this tutorial we are going to be using the 100% open- are going to be using the 100% open- are going to be using the 100% open- Source Cloud native PG Source Cloud native PG Source Cloud native PG operator so I've prepared a few notes operator so I've prepared a few notes operator so I've prepared a few notes here and the cluster that we're going to here and the cluster that we're going to here and the cluster that we're going to be using is an AKs cluster that I have be using is an AKs cluster that I have be using is an AKs cluster that I have just deployed in my Azure Resource Group just deployed in my Azure Resource Group just deployed in my Azure Resource Group here so let's jump here so let's jump here so let's jump in first of all we need to install the in first of all we need to install the in first of all we need to install the cloud native PG operator and this is cloud native PG operator and this is cloud native PG operator and this is really easy to do we just go to the really easy to do we just go to the really easy to do we just go to the cloud native PG cloud native PG cloud native PG documentation and then we are going to documentation and then we are going to documentation and then we are going to go to the quick go to the quick go to the quick start and here we have a link start and here we have a link start and here we have a link to installing Cloud native PG so you can to installing Cloud native PG so you can to installing Cloud native PG so you can either just apply the manifests or we either just apply the manifests or we either just apply the manifests or we can use the cmpg plug-in to install it
-
can use the cmpg plug-in to install it can use the cmpg plug-in to install it or you can use Helm but I'm just going or you can use Helm but I'm just going or you can use Helm but I'm just going to use the uh this little manifest over to use the uh this little manifest over to use the uh this little manifest over here copy that and I'm now here here copy that and I'm now here here copy that and I'm now here connected to my fresh AKs cluster K get connected to my fresh AKs cluster K get connected to my fresh AKs cluster K get nodes here we see I have two nodes with nodes here we see I have two nodes with nodes here we see I have two nodes with an age of 7 minutes and if I now apply an age of 7 minutes and if I now apply an age of 7 minutes and if I now apply this this this manifest we are going to be installing manifest we are going to be installing manifest we are going to be installing the cmpg operator so if I do K get NS the cmpg operator so if I do K get NS the cmpg operator so if I do K get NS then we then we then we see we have a new namespace here called see we have a new namespace here called see we have a new namespace here called cmpg system so now that we've installed cmpg system so now that we've installed cmpg system so now that we've installed the operator let me just explain a the operator let me just explain a the operator let me just explain a little bit why you should be running little bit why you should be running little bit why you should be running databases on kubernetes and why it's not databases on kubernetes and why it's not databases on kubernetes and why it's not scary because indeed there is this idea scary because indeed there is this idea scary because indeed there is this idea that all kubernetes clusters need to be that all kubernetes clusters need to be that all kubernetes clusters need to be stateless and you should never run any stateless and you should never run any stateless and you should never run any state in your kubernetes cluster and to state in your kubernetes cluster and to state in your kubernetes cluster and to some extent that's true but when you're some extent that's true but when you're some extent that's true but when you're running databases you have methods of running databases you have methods of running databases you have methods of replicating those databases to object replicating those databases to object replicating those databases to object storage so the actual State doesn't storage so the actual State doesn't storage so the actual State doesn't necessarily exist in your kubernetes necessarily exist in your kubernetes necessarily exist in your kubernetes cluster so I'm I'm going to be showing cluster so I'm I'm going to be showing cluster so I'm I'm going to be showing you what I mean by that as soon as we you what I mean by that as soon as we you what I mean by that as soon as we create a cluster here and in order to create a cluster here and in order to create a cluster here and in order to create a cluster we just take this bit create a cluster we just take this bit create a cluster we just take this bit of yaml here and I'm just going to copy of yaml here and I'm just going to copy of yaml here and I'm just going to copy that and and I'm going that and and I'm going that and and I'm going to um open a new file and paste that in so
-
um open a new file and paste that in so what we see here is I'm going to be what we see here is I'm going to be what we see here is I'm going to be creating a creating a creating a namespace and I'm going to create a namespace and I'm going to create a namespace and I'm going to create a cluster resource so this resource is a cluster resource so this resource is a cluster resource so this resource is a custom resource that has been enabled by custom resource that has been enabled by custom resource that has been enabled by installing the operator so if I do K get installing the operator so if I do K get installing the operator so if I do K get crd then you see here these are all the crd then you see here these are all the crd then you see here these are all the custom resources that live on my cluster custom resources that live on my cluster custom resources that live on my cluster here for example we see that we have a here for example we see that we have a here for example we see that we have a backups custom resource but also a backups custom resource but also a backups custom resource but also a cluster custom resource and that's being cluster custom resource and that's being cluster custom resource and that's being installed by the postgressql cmpg io installed by the postgressql cmpg io installed by the postgressql cmpg io oper um API so opening that again we are oper um API so opening that again we are oper um API so opening that again we are deploying a cluster with the name demo deploying a cluster with the name demo deploying a cluster with the name demo cluster in the namespace D cluster in the namespace D cluster in the namespace D database good I quau that there and the database good I quau that there and the database good I quau that there and the instances the amount of instances we're instances the amount of instances we're instances the amount of instances we're deploying is not three and each of them deploying is not three and each of them deploying is not three and each of them has 1 gabt of storage so then I just has 1 gabt of storage so then I just has 1 gabt of storage so then I just apply that database. yaml apply that database. yaml apply that database. yaml file and now we see that we have created file and now we see that we have created file and now we see that we have created a cluster so if I now change my a cluster so if I now change my a cluster so if I now change my namespace to namespace to namespace to database and get my pods there here we database and get my pods there here we database and get my pods there here we see that now an init DB pod is running see that now an init DB pod is running see that now an init DB pod is running so what this does it is preparing the so what this does it is preparing the so what this does it is preparing the database to be deployed database to be deployed database to be deployed it's provisioning some storage for it it's provisioning some storage for it it's provisioning some storage for it and it it's bootstrapping the database and it it's bootstrapping the database and it it's bootstrapping the database itself this takes a few moments but when
-
itself this takes a few moments but when itself this takes a few moments but when as soon as this um INB process has as soon as this um INB process has as soon as this um INB process has finished then we'll see that it's now finished then we'll see that it's now finished then we'll see that it's now initializing the first instance of the initializing the first instance of the initializing the first instance of the actual cluster so a new pod is being actual cluster so a new pod is being actual cluster so a new pod is being created now and that takes a while created now and that takes a while created now and that takes a while because it needs to pull the the image because it needs to pull the the image because it needs to pull the the image for of course but now we see that it is for of course but now we see that it is for of course but now we see that it is making progress It's running and now making progress It's running and now making progress It's running and now it's just waiting for the Readiness it's just waiting for the Readiness it's just waiting for the Readiness probes to be to become ready and now the probes to be to become ready and now the probes to be to become ready and now the first instance of my cluster is actually first instance of my cluster is actually first instance of my cluster is actually running and now it's going to create a running and now it's going to create a running and now it's going to create a second instance in a second pod which is second instance in a second pod which is second instance in a second pod which is then being joined to the postgress then being joined to the postgress then being joined to the postgress cluster so what I can do now I can go k cluster so what I can do now I can go k cluster so what I can do now I can go k get pods here I see my my my pods being get pods here I see my my my pods being get pods here I see my my my pods being created but but I now that we have the created but but I now that we have the created but but I now that we have the operat installed we can use the cnpg operat installed we can use the cnpg operat installed we can use the cnpg cube CTL plugin in order to interact cube CTL plugin in order to interact cube CTL plugin in order to interact with our clusters so first of all I can with our clusters so first of all I can with our clusters so first of all I can do K get do K get do K get clusters here I see if i k get cluster clusters here I see if i k get cluster clusters here I see if i k get cluster then I see that I have my demo cluster then I see that I have my demo cluster then I see that I have my demo cluster over here waiting for the instances to over here waiting for the instances to over here waiting for the instances to become active but if I then do K cnpg become active but if I then do K cnpg become active but if I then do K cnpg status and then select this status and then select this status and then select this cluster then we see that we cluster then we see that we cluster then we see that we have this CMP G plugin is able to give have this CMP G plugin is able to give have this CMP G plugin is able to give us the status of the CL cluster itself us the status of the CL cluster itself us the status of the CL cluster itself now we're seeing that it's waiting for now we're seeing that it's waiting for now we're seeing that it's waiting for the instances to become active we have a
-
the instances to become active we have a the instances to become active we have a an overview of our instances so we see an overview of our instances so we see an overview of our instances so we see that we have a primary which is now uh that we have a primary which is now uh that we have a primary which is now uh in an okay status this one is still in an okay status this one is still in an okay status this one is still being worked on so if I rerun the status being worked on so if I rerun the status being worked on so if I rerun the status command now now we see that we have two command now now we see that we have two command now now we see that we have two instances and it's it's now probably instances and it's it's now probably instances and it's it's now probably busy creating third one yes we see here busy creating third one yes we see here busy creating third one yes we see here that the third one is now in an init that the third one is now in an init that the third one is now in an init state so the cluster is now being state so the cluster is now being state so the cluster is now being provisioned all automatically just by provisioned all automatically just by provisioned all automatically just by applying this little yaml object that's applying this little yaml object that's applying this little yaml object that's how easy it is to provision a cluster how easy it is to provision a cluster how easy it is to provision a cluster now of course this is a very basic uh now of course this is a very basic uh now of course this is a very basic uh yaml object but if I go to my for yaml object but if I go to my for yaml object but if I go to my for example my home lab example my home lab example my home lab repo and open up my LinkedIn database repo and open up my LinkedIn database repo and open up my LinkedIn database for production then we see here that I for production then we see here that I for production then we see here that I have a few more um things that I have a few more um things that I have a few more um things that I configure so I can configure that it configure so I can configure that it configure so I can configure that it needs to bootstrap from a u backup that needs to bootstrap from a u backup that needs to bootstrap from a u backup that I've created earlier and where the I've created earlier and where the I've created earlier and where the backup is located Etc and you can also backup is located Etc and you can also backup is located Etc and you can also for example configure the resources that for example configure the resources that for example configure the resources that it needs to run that that you're it needs to run that that you're it needs to run that that you're requesting so there's a ton that you can requesting so there's a ton that you can requesting so there's a ton that you can configure with this but we are just configure with this but we are just configure with this but we are just doing a very simple deployment for now doing a very simple deployment for now doing a very simple deployment for now so so so checking our status our status is now in checking our status our status is now in checking our status our status is now in a healthy State as you can see here but a healthy State as you can see here but a healthy State as you can see here but we can also do a verbose we can also do a verbose we can also do a verbose status and now we see that we
-
status and now we see that we status and now we see that we have um we have get some more have um we have get some more have um we have get some more information so we have some information information so we have some information information so we have some information about the pot disruption budgets so that about the pot disruption budgets so that about the pot disruption budgets so that it does that automatically as well so if it does that automatically as well so if it does that automatically as well so if I do K get pdb then we see here that we I do K get pdb then we see here that we I do K get pdb then we see here that we have a cluster with a pot disruption have a cluster with a pot disruption have a cluster with a pot disruption budget here as well and this is going to budget here as well and this is going to budget here as well and this is going to be useful in the next be useful in the next be useful in the next section so if you are interested in section so if you are interested in section so if you are interested in learning kubernetes if this if you don't learning kubernetes if this if you don't learning kubernetes if this if you don't if all of this is Magic for you still if all of this is Magic for you still if all of this is Magic for you still then I highly recommend you join my then I highly recommend you join my then I highly recommend you join my devops community in here I have courses devops community in here I have courses devops community in here I have courses on the kubernetes fundamentals a full on the kubernetes fundamentals a full on the kubernetes fundamentals a full kubernetes road map and I have the only kubernetes road map and I have the only kubernetes road map and I have the only kubernetes home lab course in the world kubernetes home lab course in the world kubernetes home lab course in the world on the Internet available for you it's on the Internet available for you it's on the Internet available for you it's an 8 Hour course including the an 8 Hour course including the an 8 Hour course including the fundamentals course which is also eight fundamentals course which is also eight fundamentals course which is also eight hours this will teach you kubernetes on hours this will teach you kubernetes on hours this will teach you kubernetes on a level that is unprecedented it's all a level that is unprecedented it's all a level that is unprecedented it's all practical and it's Theory based but I practical and it's Theory based but I practical and it's Theory based but I bring everything into practice as we bring everything into practice as we bring everything into practice as we learn it so it's a Hands-On way of learn it so it's a Hands-On way of learn it so it's a Hands-On way of learning secondly you can network with learning secondly you can network with learning secondly you can network with over 400 Engineers here you can ask over 400 Engineers here you can ask over 400 Engineers here you can ask questions and I have I host several questions and I have I host several questions and I have I host several group coaching calls every week where group coaching calls every week where group coaching calls every week where you can ask me questions directly or you you can ask me questions directly or you you can ask me questions directly or you can ask questions in the community when can ask questions in the community when can ask questions in the community when you get stuck check it out I think you you get stuck check it out I think you you get stuck check it out I think you might like might like might like it so now that we have our cluster it so now that we have our cluster it so now that we have our cluster running our database cluster that is now running our database cluster that is now running our database cluster that is now let's check out what we can do with it let's check out what we can do with it let's check out what we can do with it so if I open up K9s again and if I then
-
so if I open up K9s again and if I then so if I open up K9s again and if I then attach to one of these instances and if attach to one of these instances and if attach to one of these instances and if I then run psql now I have an interface I then run psql now I have an interface I then run psql now I have an interface to my database I can do L and I see that to my database I can do L and I see that to my database I can do L and I see that the it has created an App database the it has created an App database the it has created an App database automatically the standard name for automatically the standard name for automatically the standard name for these databases that it uses is app so these databases that it uses is app so these databases that it uses is app so if I connect to the app if I connect to the app if I connect to the app database then I can listed tables well database then I can listed tables well database then I can listed tables well there are there isn't anything in there there are there isn't anything in there there are there isn't anything in there yet so let's create something so here I yet so let's create something so here I yet so let's create something so here I have a very simple SQL have a very simple SQL have a very simple SQL script and this is going to create a script and this is going to create a script and this is going to create a users table and it's going to insert users table and it's going to insert users table and it's going to insert Alice and Bob into that table just for Alice and Bob into that table just for Alice and Bob into that table just for demonstration purposes demonstration purposes demonstration purposes so if I now this is now created and if I so if I now this is now created and if I so if I now this is now created and if I now do select star from users then we now do select star from users then we now do select star from users then we see that we have Alice and Bob in our see that we have Alice and Bob in our see that we have Alice and Bob in our database so now that we know how to database so now that we know how to database so now that we know how to interact with the cluster let's do interact with the cluster let's do interact with the cluster let's do something else something else something else Let's uh let's see let's say we have Let's uh let's see let's say we have Let's uh let's see let's say we have created our cluster but then we want to created our cluster but then we want to created our cluster but then we want to apply some changes to it well we can apply some changes to it well we can apply some changes to it well we can just open our database. yaml and let's just open our database. yaml and let's just open our database. yaml and let's say I want to increase my instance to 15 say I want to increase my instance to 15 say I want to increase my instance to 15 I have a very important cluster and I I have a very important cluster and I I have a very important cluster and I want to have 15 instances of my database want to have 15 instances of my database want to have 15 instances of my database here so if I apply that now it then it's here so if I apply that now it then it's here so if I apply that now it then it's going to apply this so if I do K get going to apply this so if I do K get going to apply this so if I do K get pods now now we see it's going to one by
-
pods now now we see it's going to one by pods now now we see it's going to one by one it's going to increase the replicas one it's going to increase the replicas one it's going to increase the replicas and this is going to take a while and this is going to take a while and this is going to take a while because it needs to join and then uh because it needs to join and then uh because it needs to join and then uh replicate the database to it but replicate the database to it but replicate the database to it but eventually we're going to have 15 eventually we're going to have 15 eventually we're going to have 15 replicas of our cluster ready here so replicas of our cluster ready here so replicas of our cluster ready here so while that is running in the background while that is running in the background while that is running in the background this is going to take a while let's this is going to take a while let's this is going to take a while let's check out uh how we can connect to this check out uh how we can connect to this check out uh how we can connect to this database and what that does in the database and what that does in the database and what that does in the background so when I created the background so when I created the background so when I created the database and then the operator then database and then the operator then database and then the operator then created some secrets for us so if I do K created some secrets for us so if I do K created some secrets for us so if I do K get secrets in my namespace here here we get secrets in my namespace here here we get secrets in my namespace here here we see that we have a demo cluster app see that we have a demo cluster app see that we have a demo cluster app which is a basic off secret so if I open which is a basic off secret so if I open which is a basic off secret so if I open that in K9s then it's easier to that in K9s then it's easier to that in K9s then it's easier to decode secret and demo cluster app then decode secret and demo cluster app then decode secret and demo cluster app then here we see that it has created a secret here we see that it has created a secret here we see that it has created a secret with a DB name with a host and a with a DB name with a host and a with a DB name with a host and a password so here we have all of the password so here we have all of the password so here we have all of the connection information available to us connection information available to us connection information available to us in this secret that is automatically in this secret that is automatically in this secret that is automatically created for us and this it even provides created for us and this it even provides created for us and this it even provides us with the us with the us with the gdbc connection string and we can use gdbc connection string and we can use gdbc connection string and we can use this or or this post gql URI and this is this or or this post gql URI and this is this or or this post gql URI and this is the way we can use that in our the way we can use that in our the way we can use that in our applications so if I for example grab applications so if I for example grab applications so if I for example grab that LinkedIn application that I just that LinkedIn application that I just that LinkedIn application that I just showed you then this LinkedIn showed you then this LinkedIn showed you then this LinkedIn application is configured through config application is configured through config application is configured through config maps and in my config map I then can maps and in my config map I then can maps and in my config map I then can configure the host the database host
-
configure the host the database host configure the host the database host that I wanted to connect to and in this that I wanted to connect to and in this that I wanted to connect to and in this case is LinkedIn DB production case is LinkedIn DB production case is LinkedIn DB production V6 so in my in my um in my V6 so in my in my um in my V6 so in my in my um in my cluster if I do K get SV see we see here cluster if I do K get SV see we see here cluster if I do K get SV see we see here that the demo cluster the operator has that the demo cluster the operator has that the demo cluster the operator has created a service for this so you have created a service for this so you have created a service for this so you have your read Service your read only and your read Service your read only and your read Service your read only and your read WR service for example your read WR service for example your read WR service for example so when connecting to this service that so when connecting to this service that so when connecting to this service that means that I can actually write to the means that I can actually write to the means that I can actually write to the database and this is the way that you database and this is the way that you database and this is the way that you can formulate connection strings in can formulate connection strings in can formulate connection strings in inside of your kubernetes cluster inside of your kubernetes cluster inside of your kubernetes cluster because you are you I'm just connecting because you are you I'm just connecting because you are you I'm just connecting to this service directly to this service directly to this service directly then I give it the port and then the then I give it the port and then the then I give it the port and then the database name and in terms of Secrets database name and in terms of Secrets database name and in terms of Secrets then all I need to do is I also in this then all I need to do is I also in this then all I need to do is I also in this case I'm using the Azure key Vault case I'm using the Azure key Vault case I'm using the Azure key Vault operator but basically what I'm doing is operator but basically what I'm doing is operator but basically what I'm doing is I'm just creating a secret object based I'm just creating a secret object based I'm just creating a secret object based from values in my key Vault and then I from values in my key Vault and then I from values in my key Vault and then I set the environment variable lddb user set the environment variable lddb user set the environment variable lddb user and lddb password to the values that and lddb password to the values that and lddb password to the values that were generated by the EDB operator were generated by the EDB operator were generated by the EDB operator so this is how you can then connect your so this is how you can then connect your so this is how you can then connect your your applications to it and another your applications to it and another your applications to it and another example of this is if I go to my grafana example of this is if I go to my grafana example of this is if I go to my grafana over here then I can use these databases over here then I can use these databases over here then I can use these databases as data sources directly so if I go to as data sources directly so if I go to as data sources directly so if I go to my data sources then here I have my
-
my data sources then here I have my my data sources then here I have my settle cast and tracker database for settle cast and tracker database for settle cast and tracker database for example and then the way I connect to example and then the way I connect to example and then the way I connect to this is by defining the host URL in the this is by defining the host URL in the this is by defining the host URL in the kubernetes native DNS kubernetes native DNS kubernetes native DNS format so if I copy this and maybe it's format so if I copy this and maybe it's format so if I copy this and maybe it's a bit easier to read that a bit easier to read that a bit easier to read that way so here we see this is just the the way so here we see this is just the the way so here we see this is just the the standard kubernetes DNS so it's the name standard kubernetes DNS so it's the name standard kubernetes DNS so it's the name of the of the of the service and then you're specifying it is service and then you're specifying it is service and then you're specifying it is a uh then you're specifying the name a uh then you're specifying the name a uh then you're specifying the name space that it is a service in cluster. space that it is a service in cluster. space that it is a service in cluster. loal and this way I can connect to this loal and this way I can connect to this loal and this way I can connect to this service from different namespace and service from different namespace and service from different namespace and because I've done that I now have my zle because I've done that I now have my zle because I've done that I now have my zle cast and tracker as a datab as a data cast and tracker as a datab as a data cast and tracker as a datab as a data source here in grafana and that means source here in grafana and that means source here in grafana and that means that I can create dashboards out of my that I can create dashboards out of my that I can create dashboards out of my data in my data in my data in my kubernetes database so the way that kubernetes database so the way that kubernetes database so the way that works is that I can SE use postgress works is that I can SE use postgress works is that I can SE use postgress queries like this select count Tim stamp queries like this select count Tim stamp queries like this select count Tim stamp as time from markdown as time from markdown as time from markdown counts and then it's going to render counts and then it's going to render counts and then it's going to render this as a time series because I have a this as a time series because I have a this as a time series because I have a time stamp and the result is the amount time stamp and the result is the amount time stamp and the result is the amount of notes that are in my settle Casten of notes that are in my settle Casten of notes that are in my settle Casten which I push push to an API through a which I push push to an API through a which I push push to an API through a Chron job or a system D timer Chron job or a system D timer Chron job or a system D timer technically and every every hour that technically and every every hour that technically and every every hour that amount of notes is being pushed and this amount of notes is being pushed and this amount of notes is being pushed and this way I can keep track of my notes for
-
way I can keep track of my notes for way I can keep track of my notes for example another one that I do is I track example another one that I do is I track example another one that I do is I track my health metrics so like my body weight my health metrics so like my body weight my health metrics so like my body weight and my calories my body fat percentage and my calories my body fat percentage and my calories my body fat percentage all of that I'm currently bulking you all of that I'm currently bulking you all of that I'm currently bulking you can see it's all going up so I do all of can see it's all going up so I do all of can see it's all going up so I do all of this by pushing that to an API that I this by pushing that to an API that I this by pushing that to an API that I wrote myself that inserts all of this wrote myself that inserts all of this wrote myself that inserts all of this into postgress databases and then I can into postgress databases and then I can into postgress databases and then I can query that in query that in query that in grafana so you can connect to these grafana so you can connect to these grafana so you can connect to these databases just by using the local databases just by using the local databases just by using the local kubernetes DNS and it it works really kubernetes DNS and it it works really kubernetes DNS and it it works really well if there's any application that well if there's any application that well if there's any application that uses a postgress database as a backend uses a postgress database as a backend uses a postgress database as a backend in my case I have my if I go to my home in my case I have my if I go to my home in my case I have my if I go to my home here I have my comma feed instance my here I have my comma feed instance my here I have my comma feed instance my RSS reader my RSS reader my RSS reader my wallabag my bookmark manager uh and even wallabag my bookmark manager uh and even wallabag my bookmark manager uh and even my n8n all of that is connecting to my n8n all of that is connecting to my n8n all of that is connecting to their own databases and this is also how their own databases and this is also how their own databases and this is also how I I I select self-hosted apps that I want to select self-hosted apps that I want to select self-hosted apps that I want to run in my home lab I always see if they run in my home lab I always see if they run in my home lab I always see if they if they are using a postgress backend if they are using a postgress backend if they are using a postgress backend that's basically my selection criteria that's basically my selection criteria that's basically my selection criteria because I really like database I like because I really like database I like because I really like database I like running them I like uh optimizing them running them I like uh optimizing them running them I like uh optimizing them and I like the way I just like the way and I like the way I just like the way and I like the way I just like the way the The kubernetes Operators the the the The kubernetes Operators the the the The kubernetes Operators the the cloud native PG operator facilitates cloud native PG operator facilitates cloud native PG operator facilitates running databases on kubernetes it's running databases on kubernetes it's running databases on kubernetes it's super easy okay I was a little bit super easy okay I was a little bit super easy okay I was a little bit overambitious 15 instances was taking a overambitious 15 instances was taking a overambitious 15 instances was taking a bit too long time so I scaled it down to bit too long time so I scaled it down to bit too long time so I scaled it down to six but it serves the purpose now I have
-
six but it serves the purpose now I have six but it serves the purpose now I have six instances but now what happens when six instances but now what happens when six instances but now what happens when I for example upgrade my kubernetes I for example upgrade my kubernetes I for example upgrade my kubernetes cluster right all of these are running cluster right all of these are running cluster right all of these are running on on on on different nodes as you can see here on different nodes as you can see here on different nodes as you can see here this one is running on 1 0 1 0 1 0 so this one is running on 1 0 1 0 1 0 so this one is running on 1 0 1 0 1 0 so it's evenly distributed so that's nice it's evenly distributed so that's nice it's evenly distributed so that's nice but what if I am now going to upgrade my but what if I am now going to upgrade my but what if I am now going to upgrade my cluster well I can go to my AKs cluster cluster well I can go to my AKs cluster cluster well I can go to my AKs cluster here and for demo purposes I'm just here and for demo purposes I'm just here and for demo purposes I'm just going to do this from the portal usually going to do this from the portal usually going to do this from the portal usually you would do this when you're for you would do this when you're for you would do this when you're for example using bicep but here I'm going example using bicep but here I'm going example using bicep but here I'm going to initiate a kubernetes up upgrade so to initiate a kubernetes up upgrade so to initiate a kubernetes up upgrade so I'm going to upgrade to the latest I'm going to upgrade to the latest I'm going to upgrade to the latest version like that I'm going to select version like that I'm going to select version like that I'm going to select upgrade control plane and all the node upgrade control plane and all the node upgrade control plane and all the node pools but before I do that what I need pools but before I do that what I need pools but before I do that what I need to do is I need to set my cluster into to do is I need to set my cluster into to do is I need to set my cluster into maintenance mode so what I do is K cmpg maintenance mode so what I do is K cmpg maintenance mode so what I do is K cmpg maintenance set and then all name maintenance set and then all name maintenance set and then all name spaces and then now it has been set that spaces and then now it has been set that spaces and then now it has been set that the database is now in maintenance mode the database is now in maintenance mode the database is now in maintenance mode which allows it to be which allows it to be which allows it to be rescheduled so here we see that our rescheduled so here we see that our rescheduled so here we see that our maintenance is set to true and reuse PVC maintenance is set to true and reuse PVC maintenance is set to true and reuse PVC is set to false and this is critical is set to false and this is critical is set to false and this is critical because when you said reuse PVC then if because when you said reuse PVC then if because when you said reuse PVC then if that's true then it's going to be that's true then it's going to be that's true then it's going to be reusing the the persistent volume claims reusing the the persistent volume claims reusing the the persistent volume claims and we don't want that so I'm just going
-
and we don't want that so I'm just going and we don't want that so I'm just going to initiate the upgrade here so it's now to initiate the upgrade here so it's now to initiate the upgrade here so it's now going to start to upgrade and very soon going to start to upgrade and very soon going to start to upgrade and very soon we should see our nodes starting to um we should see our nodes starting to um we should see our nodes starting to um be be be rescheduled but again so it's reuse PVC rescheduled but again so it's reuse PVC rescheduled but again so it's reuse PVC is set to false so it's not using the is set to false so it's not using the is set to false so it's not using the same persistent volume claims rather same persistent volume claims rather same persistent volume claims rather it's just going to spin up new ones and it's just going to spin up new ones and it's just going to spin up new ones and using the postgress initi native syncing using the postgress initi native syncing using the postgress initi native syncing capabilities to just sync the data to capabilities to just sync the data to capabilities to just sync the data to this new persistent volume claim because this new persistent volume claim because this new persistent volume claim because if you do K get PVC here we see that all if you do K get PVC here we see that all if you do K get PVC here we see that all of our data is actually stored on of our data is actually stored on of our data is actually stored on persistent volume claims each pod gets persistent volume claims each pod gets persistent volume claims each pod gets its own persistent volume claim that its own persistent volume claim that its own persistent volume claim that contains all of the PG contains all of the PG contains all of the PG data and this is also the reason why we data and this is also the reason why we data and this is also the reason why we can back this up to a different um to can back this up to a different um to can back this up to a different um to object storage for example we could object storage for example we could object storage for example we could actually take snapshots of the actually take snapshots of the actually take snapshots of the persistent volume claims itself persistent volume claims itself persistent volume claims itself themselves or what we can do is we can themselves or what we can do is we can themselves or what we can do is we can use the barman Object Store which then use the barman Object Store which then use the barman Object Store which then points your wall your right a head log points your wall your right a head log points your wall your right a head log to a object store so like Amazon S3 to a object store so like Amazon S3 to a object store so like Amazon S3 buckets or Azure blob storage and then buckets or Azure blob storage and then buckets or Azure blob storage and then periodically let's say once an hour it's periodically let's say once an hour it's periodically let's say once an hour it's going to take a PG dump and back up your going to take a PG dump and back up your going to take a PG dump and back up your wall to the object store and that means wall to the object store and that means wall to the object store and that means that you always have a snapshot that you always have a snapshot that you always have a snapshot available to available to available to you as you see well it's not it's not
-
you as you see well it's not it's not you as you see well it's not it's not starting yet so what I can just show you starting yet so what I can just show you starting yet so what I can just show you is I have my EDB scess for kubernetes uh is I have my EDB scess for kubernetes uh is I have my EDB scess for kubernetes uh dashboard here in my grafana this is dashboard here in my grafana this is dashboard here in my grafana this is running in my home running in my home running in my home lab and this dashboard gives me a full lab and this dashboard gives me a full lab and this dashboard gives me a full overview of everything that I need to overview of everything that I need to overview of everything that I need to know of my databases and here we see know of my databases and here we see know of my databases and here we see that there is also an a pain here set that there is also an a pain here set that there is also an a pain here set saying last base backup so 6 hours ago saying last base backup so 6 hours ago saying last base backup so 6 hours ago my backup my my database has been backed my backup my my database has been backed my backup my my database has been backed up to the cloud which I can then use to up to the cloud which I can then use to up to the cloud which I can then use to restore at any point point if I want to restore at any point point if I want to restore at any point point if I want to when you check out my database. yaml when you check out my database. yaml when you check out my database. yaml here in LinkedIn here this is what I here in LinkedIn here this is what I here in LinkedIn here this is what I meant where I said the bootstrap to meant where I said the bootstrap to meant where I said the bootstrap to recovery and then it is set to a recovery and then it is set to a recovery and then it is set to a database called LinkedIn cluster backup database called LinkedIn cluster backup database called LinkedIn cluster backup which is then stored in my storage which is then stored in my storage which is then stored in my storage account in uh aure blob storage and then account in uh aure blob storage and then account in uh aure blob storage and then it used just that data over there to it used just that data over there to it used just that data over there to replay the wall and to restore the replay the wall and to restore the replay the wall and to restore the cluster from that backup it works really cluster from that backup it works really cluster from that backup it works really well I've done it several times that by well I've done it several times that by well I've done it several times that by I had a power cut and my data got I had a power cut and my data got I had a power cut and my data got corrupted you just point it to the corrupted you just point it to the corrupted you just point it to the object store it replays it and it works object store it replays it and it works object store it replays it and it works super smooth okay here we go now we see that smooth okay here we go now we see that our new node is being uh created here our new node is being uh created here our new node is being uh created here with the new kubernetes version and now with the new kubernetes version and now with the new kubernetes version and now if I open up K9s here we should see that if I open up K9s here we should see that if I open up K9s here we should see that our pods are now being our pods are now being our pods are now being rescheduled and we see indeed that it's
-
rescheduled and we see indeed that it's rescheduled and we see indeed that it's just taking one by one it's taking the just taking one by one it's taking the just taking one by one it's taking the Pod and then it's scheduling it to the Pod and then it's scheduling it to the Pod and then it's scheduling it to the new node and then when that one when new node and then when that one when new node and then when that one when that PVC has then been replicated so that PVC has then been replicated so that PVC has then been replicated so when the data has been replicated when the data has been replicated when the data has been replicated properly then it's going to do the next properly then it's going to do the next properly then it's going to do the next one as you see here number six and as you see according to the Pod six and as you see according to the Pod disruption budget it's just taking its disruption budget it's just taking its disruption budget it's just taking its time one by one rescheduling the pods to time one by one rescheduling the pods to time one by one rescheduling the pods to the new node and I don't have to do the new node and I don't have to do the new node and I don't have to do anything it's just it's just keeping one anything it's just it's just keeping one anything it's just it's just keeping one in running on the old node at all times in running on the old node at all times in running on the old node at all times and when all of them are moved to the and when all of them are moved to the and when all of them are moved to the next one then it's going to reschedule next one then it's going to reschedule next one then it's going to reschedule the the late last one it's going to the the late last one it's going to the the late last one it's going to promote one of the instances to the promote one of the instances to the promote one of the instances to the primary and it it goes all automatic as primary and it it goes all automatic as primary and it it goes all automatic as you see so now number six is you see so now number six is you see so now number six is initializing it's in a running State and initializing it's in a running State and initializing it's in a running State and as soon as that's ready then we should as soon as that's ready then we should as soon as that's ready then we should see another one being rescheduled here see another one being rescheduled here see another one being rescheduled here we go now we see number two is being we go now we see number two is being we go now we see number two is being terminated and now it's going to up dat terminated and now it's going to up dat terminated and now it's going to up dat that one so if I check my nodes again we that one so if I check my nodes again we that one so if I check my nodes again we have still one node and the old node is have still one node and the old node is have still one node and the old node is still being Dred so it's now just taking still being Dred so it's now just taking still being Dred so it's now just taking all of the pods from the old node and all of the pods from the old node and all of the pods from the old node and rescheduling that one to the new one and rescheduling that one to the new one and rescheduling that one to the new one and when that one is done it's going to do when that one is done it's going to do when that one is done it's going to do the next one and one by one is going to the next one and one by one is going to the next one and one by one is going to to upgrade the nodes to the new to upgrade the nodes to the new to upgrade the nodes to the new kubernetes version
-
kubernetes version kubernetes version and when you see here we have the allow and when you see here we have the allow and when you see here we have the allow disruption set to zero so we always have disruption set to zero so we always have disruption set to zero so we always have one primary available at all times So one primary available at all times So one primary available at all times So eventually it's going to just create eventually it's going to just create eventually it's going to just create another instance and promote that and another instance and promote that and another instance and promote that and then we have our primary available on then we have our primary available on then we have our primary available on the new node on the new kubernetes the new node on the new kubernetes the new node on the new kubernetes version and finally I just want to show version and finally I just want to show version and finally I just want to show you one more thing which is that I can you one more thing which is that I can you one more thing which is that I can you can also run PG admin directly on you can also run PG admin directly on you can also run PG admin directly on your cluster so this is my home lab your cluster so this is my home lab your cluster so this is my home lab cluster and I'm running PG admin in a cluster and I'm running PG admin in a cluster and I'm running PG admin in a container it's it's all available in my container it's it's all available in my container it's it's all available in my home lab repo home lab repo home lab repo and all of these databases are deployed and all of these databases are deployed and all of these databases are deployed through the EDB operator or the cloud through the EDB operator or the cloud through the EDB operator or the cloud native PG operator and I can just check native PG operator and I can just check native PG operator and I can just check out these tables that I have for example out these tables that I have for example out these tables that I have for example this is my wallabag entry and if I just this is my wallabag entry and if I just this is my wallabag entry and if I just go and view my data for the first 100 go and view my data for the first 100 go and view my data for the first 100 rows here I have all of the articles rows here I have all of the articles rows here I have all of the articles that I have saved in my wack instance that I have saved in my wack instance that I have saved in my wack instance for example and all of this again I can for example and all of this again I can for example and all of this again I can just back up to the cloud and if just back up to the cloud and if just back up to the cloud and if something goes wrong I just restore it something goes wrong I just restore it something goes wrong I just restore it to a new database this instance and it to a new database this instance and it to a new database this instance and it works super clean so running databases works super clean so running databases works super clean so running databases in kubernetes is nothing to be scared of in kubernetes is nothing to be scared of in kubernetes is nothing to be scared of it works really clean as you have seen it works really clean as you have seen it works really clean as you have seen and I'm going to in the next video I'm and I'm going to in the next video I'm and I'm going to in the next video I'm going to be going deeper into how to run going to be going deeper into how to run going to be going deeper into how to run backups so that you can store your data backups so that you can store your data backups so that you can store your data safely in your home lab so if you found safely in your home lab so if you found safely in your home lab so if you found this useful I'm sure that you're going this useful I'm sure that you're going this useful I'm sure that you're going to love my private devops Community I
-
to love my private devops Community I to love my private devops Community I have everything you need to start have everything you need to start have everything you need to start learning kubernetes from scratch and learning kubernetes from scratch and learning kubernetes from scratch and Beyond and how to set your home lab from Beyond and how to set your home lab from Beyond and how to set your home lab from up from scratch you only need a up from scratch you only need a up from scratch you only need a Raspberry Pi or an old laptop to get Raspberry Pi or an old laptop to get Raspberry Pi or an old laptop to get started you can ask me questions started you can ask me questions started you can ask me questions directly and network with over 400 directly and network with over 400 directly and network with over 400 Engineers that are available in the Engineers that are available in the Engineers that are available in the community it's an amazing place I wish I community it's an amazing place I wish I community it's an amazing place I wish I had this when I got started so I hope to had this when I got started so I hope to had this when I got started so I hope to see you in the CBE graph community
Summary
This transcript addresses the common misconception that databases cannot be run on Kubernetes, arguing it's not inherently scary, especially with tools like the open-source Cloud Native PG operator. The key takeaway is that leveraging operators and proper configuration, like replicating data to object storage, allows for reliable database deployments within Kubernetes clusters, dispelling the notion of strict statelessness for all cluster operations.