<?xml version="1.0" encoding="UTF-8" ?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" version="2.0"><channel><title>Crunchy Data | CrunchyData Blog</title>
<atom:link href="https://www.crunchydata.com/blog/author/crunchy-data/rss.xml" rel="self" type="application/rss+xml" />
<link>https://www.crunchydata.com/blog/author/crunchy-data</link>
<image><url>https://www.crunchydata.com/build/_assets/default.png-W4XGD4DB.webp</url>
<title>Crunchy Data | CrunchyData Blog</title>
<link>https://www.crunchydata.com/blog/author/crunchy-data</link>
<width>256</width>
<height>256</height></image>
<description>PostgreSQL experts from Crunchy Data share advice, performance tips, and guides on successfully running PostgreSQL and Kubernetes solutions</description>
<language>en-us</language>
<pubDate>Thu, 07 Jan 2021 04:00:00 EST</pubDate>
<dc:date>2021-01-07T09:00:00.000Z</dc:date>
<dc:language>en-us</dc:language>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<item><title><![CDATA[ Crunchy Data PostgreSQL Security Technical Implementation Guide Now Available ]]></title>
<link>https://www.crunchydata.com/blog/crunchy-data-postgresql-security-technical-implementation-guide-now-available</link>
<description><![CDATA[ This new guide is the result of ongoing collaboration with DISA and provides
security guidance for PostgreSQL 9.6 through 12 ]]></description>
<content:encoded><![CDATA[ <p><em>This new guide is the result of ongoing collaboration with DISA and provides security guidance for</em> <em>PostgreSQL 9.6 through 12</em><p>Charleston, S.C. (January 6, 2021) - <a href=https://www.crunchydata.com/>Crunchy Data</a> — the leading provider of trusted open source PostgreSQL — is pleased to announce the release of the <a href=https://www.crunchydata.com/files/stig/PGSQL-STIG-v1r1.pdf>Crunchy Data PostgreSQL <dfn>Security Technical Implementation Guide</dfn></a> (<abbr>STIG</abbr>) by the United States <dfn>Defense Information Systems Agency</dfn> (<abbr>DISA</abbr>). In 2017, Crunchy Data collaborated with DISA to publish the initial version of the PostgreSQL STIG, representing the first published STIG for an open source database.<p>The Crunchy Data PostgreSQL STIG provides guidance for the secure deployment and configuration of Crunchy Certified PostgreSQL in adherence to the United States Department of Defense security requirements guidelines. Enterprises can refer to this comprehensive guide for PostgreSQL security best practices as they consider open source PostgreSQL as an alternative to proprietary database software.<p>“We are proud to work in partnership with DISA to provide this updated security guidance for PostgreSQL and believe that it is yet another validation of the comprehensive security functionality of PostgreSQL,” said Crunchy Data President Paul Laurence. “Crunchy Data is committed to continue bringing the extraordinary cost effectiveness of open source PostgreSQL technology to the U.S. Defense community and to all database users who need to manage their information reliably, securely and efficiently.”<p>This new PostgreSQL STIG includes updated guidance for PostgreSQL 9.6 through 12, including how to use SCRAM authentication, a new logging location for PostgreSQL 10+, and usage of built-in defined roles added in newer Postgres releases. The Crunchy Data PostgreSQL STIG also provides expanded information regarding the use of any <dfn>Federal Information Processing Standard</dfn> (<abbr>FIPS</abbr>) compliant operating systems.<p><a href=https://www.crunchydata.com/products/crunchy-certified-postgresql>Crunchy Certified PostgreSQL</a>, Crunchy Data’s trusted 100% open source PostgreSQL distribution, enables Crunchy Data PostgreSQL STIG compliance by providing trusted PostgreSQL along with the requisite security enhancing audit logging extensions and Crunchy Data's enterprise support. To ensure that Crunchy Certified PostgreSQL represents the most trusted enterprise PostgreSQL distribution, Crunchy Certified PostgreSQL has received <a href=https://www.commoncriteriaportal.org/>Common Criteria <dfn>Evaluation Assurance Level</dfn></a> (<abbr>EAL</abbr>) 2+ certification, an international standard for computer security certification, Crunchy Certified PostgreSQL is the first commercially available open source relational database management system to receive Common Criteria certification.<h2 id=about-disa-stig><a href=#about-disa-stig>About DISA STIG</a></h2><p>STIGs are the configuration standards for DoD <dfn>Information Assurance</dfn> (<abbr>IA</abbr>) and IA-enabled devices/systems. Since 1998, DISA has played a critical role enhancing the security posture of DoD's security systems by providing the STIGs. The STIGs contain technical guidance to "lock down" information systems/software that might otherwise be vulnerable to a malicious computer attack.<h2 id=about-crunchy-data><a href=#about-crunchy-data>About Crunchy Data</a></h2><p>Crunchy Data is the leading provider of trusted open source and enterprise PostgreSQL technology, support and training. Crunchy Data offers Crunchy Certified PostgreSQL, the most advanced open source RDBMS on the market, Crunchy PostgreSQL for Kubernetes, the leading solution for deploying Kubernetes native Postgres, and the recently launched <a href=https://crunchybridge.com/login/>Crunchy Bridge</a>, a fully managed cloud Postgres service that gives enterprises the ultimate choice in Postgres management and provides the ability to modernize infrastructure as needed. Learn more at <a href=https://www.crunchydata.com/>www.crunchydata.com</a>. ]]></content:encoded>
<author><![CDATA[ Crunchy.Data@crunchydata.com (Crunchy Data) ]]></author>
<dc:creator><![CDATA[ Crunchy Data ]]></dc:creator>
<guid isPermalink="false">https://blog.crunchydata.com/blog/crunchy-data-postgresql-security-technical-implementation-guide-now-available</guid>
<pubDate>Thu, 07 Jan 2021 04:00:00 EST</pubDate>
<dc:date>2021-01-07T09:00:00.000Z</dc:date>
<atom:updated>2021-01-07T09:00:00.000Z</atom:updated></item>
<item><title><![CDATA[ Virtual PostGIS Day 2020 is Nov. 19 ]]></title>
<link>https://www.crunchydata.com/blog/postgis-day-2020</link>
<description><![CDATA[ We're putting together an awesome PostGIS Day virtual conference on Thursday, Nov 19th. Last year we hosted our first PostGIS Day in-person in St. Louis and although we can't gather in the same way this year, going virtual allows us to give even more talks! ]]></description>
<content:encoded><![CDATA[ <p>Authored by Steve Pousty<p>Today we are going to talk a little bit about <a href=https://en.wikipedia.org/wiki/Spatial_database>spatial databases</a> and a virtual event Crunchy Data is hosting with several friends and community members. We're putting together an awesome <a href=https://postgisday.rocks/>PostGIS Day</a> virtual conference on Thursday, Nov 19th. Last year, we hosted our first PostGIS Day in-person in St. Louis and although we can't gather in the same way this year, going virtual allows us to give even more talks! Registration is now open so be sure to sign up and log into the presentations throughout the day.<h3 id=history-of-postgis-day><a href=#history-of-postgis-day>History of PostGIS Day</a></h3><p>I have been doing spatial data analysis since 1989 using software called <a href=https://www.nationalgeographic.org/encyclopedia/geographic-information-system-gis/><dfn>Geographic Information Systems</dfn></a> (<a href=https://en.wikipedia.org/wiki/Geographic_information_system><abbr>GIS</abbr></a>) and I fell in love with the field. I mean c’mon, computers <strong>and</strong> maps?! This was 2 legs of my golden triangle (the third we can save for another day).<p>The GIS field has quite a large community and has grown tremendously over time. If you think about it, so much data collected and so many <a href=https://www.linkedin.com/pulse/5-types-questions-gis-can-answer-willy-simons/>questions</a> people ask have a spatial component. In the early days of the field, all the software needed to do this had some sort of graphical interface, though it usually had a command line. Over time, operating systems became GUI driven, GIS practitioners of the field moved to desktop software to do their analysis.<p>Now every year, the GIS community comes together to celebrate all the traditional ways they use desktop computer software to fiddle with maps and locations and they call it <a href=https://en.wikipedia.org/wiki/GIS_Day>GIS Day</a>.<p>And on the day after GIS Day, a second group gathers to celebrate the new and innovative ways to integrate maps and locations and spatial analysis into the wider world of technology, using spatial SQL in the database, and we call that <a href=https://www.xyht.com/spatial-itgis/what-is-postgis-day/>PostGIS Day</a>.<h2 id=postgis-day-its-what-comes-next><a href=#postgis-day-its-what-comes-next>PostGIS day: it's what comes next</a></h2><h3 id=what-we-have-in-store-for-you><a href=#what-we-have-in-store-for-you>What we have in store for YOU!</a></h3><p>With conferences going virtual this year, it was much easier for us to put together a variety of speakers and topics. Here's what the day is going to look like:<ul><li>To kick off the day, we have two introductory sessions for those new to PostGIS. Then talks about PostGIS with the desktop GIS tool, QGIS (<a href=https://en.wikipedia.org/wiki/Free_and_open-source_software>FOSS</a> as well). Following all that cool graphical stuff, we then show you all the analytic glory you can have by doing work right in PostGIS.<li>Right after that we have two great talks on the future of PostGIS. We will hear some of the greatness coming in the next release, PostGIS 3.1. Following that there will be a talk on some of low level greatness coming the <a href=https://trac.osgeo.org/geos/>spatial engine</a> used by PostGIS.<li>The next 5 talks are all applications of PostGIS. We will have talks on things such as, using PostGIS augmented reality as well as using pgRouting for nautical routing. We will see PostGIS being used in local government as well as in data science pipelines.<li>Then we will move to the use of PostGIS in web based applications. There will be specialized application servers and applications to manage space and time for cultural resources.<li>Finally, we will end the day with two very large organizations talking about the power of PostGIS for their research and operations.</ul><h2 id=why-attend><a href=#why-attend>Why Attend?</a></h2><p>Even if you haven't used PostGIS or spatial data before, the PostGIS Day presentations will serve as a great introduction and expand your world of possibilities. If you are already familiar with PostGIS or spatial data, it will give you a lot to enjoy. I am so confident that you will enjoy it that I will promise you twice your money back if you don’t enjoy the day (it’s free to attend, see what I did there?)<p><a href=https://info.crunchydata.com/en/postgis-day-2020-crunchy-data>sign up</a>! What are you waiting for? Go ]]></content:encoded>
<category><![CDATA[ Spatial ]]></category>
<author><![CDATA[ Crunchy.Data@crunchydata.com (Crunchy Data) ]]></author>
<dc:creator><![CDATA[ Crunchy Data ]]></dc:creator>
<guid isPermalink="false">https://blog.crunchydata.com/blog/postgis-day-2020</guid>
<pubDate>Tue, 10 Nov 2020 04:00:00 EST</pubDate>
<dc:date>2020-11-10T09:00:00.000Z</dc:date>
<atom:updated>2020-11-10T09:00:00.000Z</atom:updated></item>
<item><title><![CDATA[ Deploy High Availability PostgreSQL Clusters on Kubernetes by Example ]]></title>
<link>https://www.crunchydata.com/blog/deploy-high-availability-postgresql-on-kubernetes</link>
<description><![CDATA[ Deploy a high-availability PostgreSQL cluster on Kubernetes by example and learn how it works. ]]></description>
<content:encoded><![CDATA[ <p>One of the great things about PostgreSQL is its reliability: it is very stable and typically “just works.” However, there are certain things that can happen in the environment that PostgreSQL is deployed in that can affect its uptime, such as:<ul><li>The database storage disk fails or some other hardware failure occurs<li>The network on which the database resides becomes unreachable<li>The host operating system becomes unstable and crashes<li>A key database file becomes corrupted<li>A data center is lost</ul><p>There may also be downtime events that are due to the normal case of operations, such as performing a minor upgrade, security patching of operating system, hardware upgrade, or other maintenance.<p>Fortunately, the Crunchy PostgreSQL Operator is prepared for this.<p>Crunchy Data recently released version 4.2 of the open source PostgreSQL Operator for Kubernetes. Among the various enhancements included within this release is the introduction of distributed consensus based <dfn>high availability</dfn> (<abbr>HA</abbr>) for PostgreSQL clusters by using the Patroni high availability framework.<p>What does this mean for running high availability PostgreSQL clusters in Kubernetes, how does it work, and how to create a high availability PostgreSQL cluster by example? Read on to find out!<p><img alt="image showing kubernetes control plane with Crunchy Postgres replicate and backups"loading=lazy src=https://2283855.fs1.hubspotusercontent-na1.net/hubfs/2283855/postgresql-ha-overview.png><h2 id=the-crunchy-postgresql-operator-high-availability-fundamentals><a href=#the-crunchy-postgresql-operator-high-availability-fundamentals>The Crunchy PostgreSQL Operator High Availability Fundamentals</a></h2><p>To make the PostgreSQL clusters deployed by the PostgreSQL Operator resilient to the types of downtime events that affect availability, the Crunchy PostgreSQL Operator leverages the <dfn>distributed consensus store</dfn> (<abbr>DCS</abbr>) that backs Kubernetes to determine if the primary PostgreSQL database is in an unhealthy state. The PostgreSQL instances communicate amongst themselves via the Kubernetes DCS to determine which one is the current primary and if they need to failover to a new primary.<p>This is the key to how the PostgreSQL Operator provides high availability: it delegates the management of HA to the PostgreSQL clusters themselves! This ensures that the PostgreSQL Operator is not a single-point of failure for the availability of any of the PostgreSQL clusters that it manages, as the PostgreSQL Operator is only maintaining the definitions of what should be in the cluster (e.g. how many instances in the cluster, etc.). This is similar to what you find in the outline of the Raft algorithm that describes how to provide consensus amongst who is the leader (or primary) instance in a cluster.<p>(A quick aside: the Raft algorithm (“Reliable, Replicated, Redundant, Fault-Tolerant”) was developed for systems that have one “leader” (i.e. a primary) and one-to-many followers (i.e. replicas) to provide the same fault tolerance and safety as the PAXOS algorithm while being easier to implement. Given PostgreSQL runs as one primary and however many replicas you want, it is certainly appropriate to use Raft. PostgreSQL clusters managed by the PostgreSQL Operator, via Patroni, leverage Raft properties of the Kubernetes DCS so that way you can run a smaller number of PostgreSQL instances (i.e. 2) and still have distributed consensus!)<p>For the PostgreSQL cluster group to achieve distributed consensus on who the primary (or leader) is, each PostgreSQL cluster leverages the distributed etcd key-value store that is bundled with Kubernetes. After the PostgreSQL clusters elect a leader, a primary will place a lock in the distributed cluster to indicate that it is the leader. The "lock" is how the primary PostgreSQL instance will provide its heartbeat: it will attempt to periodically update the lock and so long as the other replicas see the update in the allowable automated failover time, the replicas will continue to follow the current primary.<p>The “log replication” portion that is defined in the Raft algorithm, the primary instance will replicate changes to each replica based on the rules set up in the provisioning process. Each replica keeps track of how far along in the recovery process it is using a “<dfn>log sequence number</dfn>” (<abbr>LSN</abbr>), a built-in PostgreSQL serial representation of how many logs have been replayed on each replica. For the purposes of high availability, there are two LSNs that need to be considered: the LSN for the last log received by the replica, and the LSN for the changes replayed for the replica. The LSN for the latest changes received can be compared amongst the replicas to determine which one has replayed the most changes, and an important part of the automated failover process.<p>For PostgreSQL clusters that leverage “synchronous replication,” a transaction is not considered complete until all changes from those transactions have been sent to all replicas that are subscribed to the primary.<h2 id=determining-when-to-failover-and-how-it-works><a href=#determining-when-to-failover-and-how-it-works>Determining When to Failover, And How It Works</a></h2><p>As mentioned above, the PostgreSQL replicas periodically check in on the lock to see if it has been updated by the primary within the allowable time. If a replica believes that the primary is unavailable, it becomes what is called a "candidate" according to the Raft algorithm and initiates an "election." It then votes for itself as the new primary. A candidate must receive a majority of votes in a cluster in order to be elected as the new primary. The replicas try to promote the PostgreSQL instance that is both available and has the highest LSN value on the latest timeline.<p>This system protects against a replica promoting itself when the primary is actually still available. If a replica believes that a primary is down and starts an election, but the primary is actually not down, the replica will not receive enough votes to become a new primary and will go back to following and replaying the changes from the primary.<p>Once an election is decided, the winning replica is immediately promoted to be a primary and takes a new lock in the Kubernetes consensus store. If the new primary has not finished replaying all of its transactions logs, it must do so in order to reach the desired state based on the LSN. Once the logs are finished being replayed, the primary is able to accept new queries.<p>At this point, any existing replicas are updated to follow the new primary.<p>Notice not once did I say anything about the PostgreSQL Operator here. This is the beauty of this high availability method: the PostgreSQL Operator allows for the administration of the PostgreSQL clusters and can set their overall structure (e.g. have 3 PostgreSQL instances in a cluster), but it does not manage their availability. This ensures that the PostgreSQL Operator is not a single-point-of-failure!<h2 id=automatic-healing-of-the-failed-primary><a href=#automatic-healing-of-the-failed-primary>Automatic Healing of the Failed Primary</a></h2><p>One of the most important pieces of this kind of failover is being able to bring back the old primary into the fold as one of the replicas. For very large databases, this can be a challenge if you have to reinitialize the database from scratch. Fortunately, the PostgreSQL Operator provides a way for the failed primary to automatically heal!<p>When the old primary tries to become available again, it realizes that it has been deposed as the leader and must be healed. It leverages the pgBackRest repository that is deployed alongside the PostgreSQL cluster and uses the “delta restore” feature, which does an in place update of all of the missing files from the current primary. This is much more efficient than reprovisioning the failed instance from scratch, and works well for very large databases! When the delta restore is done, the instance is considered heal and is ready to follow the new primary.<h2 id=less-talk-more-examples><a href=#less-talk-more-examples>Less Talk, More Examples</a></h2><p>Now that you understand how this all works let's look at an example!<p>For the 4.2 release, we tested a variety of scenarios that would trigger a failover, from network splits (my favorite one to test) to critical file removal to the primary pod disappearing. For the purposes of this exercise, we will try out the last case as it is a very easy experiment to run.<p>First, I have gone ahead and deployed the PostgreSQL Operator to a Kubernetes cluster. I have set up my cluster to use the <dfn>PostgreSQL Operator client</dfn>, aka <abbr>pgo</abbr>.<p>Let's create a high availability PostgreSQL cluster with two replicas using the pgo create cluster command:<pre><code class=language-shell>pgo create cluster hippo --replica-count=2
</code></pre><p>Notice I don't add any extra flags: high availability is enabled by default in the PostgreSQL Operator starting with version 4.2. If you want to disable high availability, you must use the --disable-autofail flag.<p>(Also note that you may need to explicitly pass in the Kubernetes Namespace with the -n flag. I set the PGO_NAMESPACE environmental variable to automatically use the Namespace).<p>Give the cluster a few minutes to get started. At some point, all of your PostgreSQL instance should be available, which you can test with the pgo test command:<pre><code class=language-shell>pgo test hippo
</code></pre><pre><code class=language-yaml>cluster : hippo
	Services
		primary (10.96.130.226:5432): UP
		replica (10.96.142.11:5432): UP
	Instances
		primary (hippo-9d5fb67c9-6svhm): UP
		replica (hippo-dupt-775c5fc66-fc7vh): UP
		replica (hippo-sekv-5f88dcbc5b-748zl): UP
</code></pre><p>Under the instances section, you can see the name of the Kubernetes Pods that comprise the entirety of the PostgreSQL cluster. Take note of the name of the primary Pod for this cluster, which in this example is hippo-9d5fb67c9-6svhm. Let's have this Pod meet with an unfortunately accident (note, you may need to add a Namespace to this command with a -n flag).:<pre><code class=language-shell>kubectl delete pods hippo-9d5fb67c9-6svhm
</code></pre><p>When demonstrating automatic failover with this method, you may notice that you kubectl command hangs for a few moments. This is due to Kubernetes making its updates after the failover event is detected.<p>Wait a few moments, and run pgo test again to see what happens:<pre><code class=language-shell>pgo test hippo
</code></pre><pre><code class=language-yaml>cluster : hippo
	Services
		primary (10.96.130.226:5432): UP
		replica (10.96.142.11:5432): UP
	Instances
		replica (hippo-9d5fb67c9-bkrht): UP
		replica (hippo-dupt-775c5fc66-fc7vh): UP
		primary (hippo-sekv-5f88dcbc5b-748zl): UP
</code></pre><p>Wow! Not only did a new primary PostgreSQL cluster get elected, but we were able to automatically heal the old primary and turn it into a replica. Granted, this may be far more impressive if we had some more data in the database and I demonstrated the continuity of the availability, but this is already a long article. ;-)<h2 id=conclusion--further-reading><a href=#conclusion--further-reading>Conclusion &#38 Further Reading</a></h2><p>Using Kubernetes to run high availability PostgreSQL clusters is no easy task: while the fundamental building blocks are available to create this kind of environment, it does require some smarts and automation behind it. Fortunately, the PostgreSQL Operator<p>If you want to understand more how the PostgreSQL Operator creates high availability PostgreSQL environments, I encourage you to read the high availability architecture section in our documentation.<p>I also encourage you to deploy the PostgreSQL Operator and try creating your own downtime scenarios and see what happens. We'd love to iron out any edge cases that may occur (though some may be too out on the edge, and at that point you'd still need manual intervention. But hey, we'd like to try to automate it, and maybe you could propose a patch to automate it!), but most importantly, we'd love to understand how you deploy high availability PostgreSQL! ]]></content:encoded>
<category><![CDATA[ Kubernetes ]]></category>
<author><![CDATA[ Crunchy.Data@crunchydata.com (Crunchy Data) ]]></author>
<dc:creator><![CDATA[ Crunchy Data ]]></dc:creator>
<guid isPermalink="false">https://blog.crunchydata.com/blog/deploy-high-availability-postgresql-on-kubernetes</guid>
<pubDate>Tue, 21 Jan 2020 04:00:00 EST</pubDate>
<dc:date>2020-01-21T09:00:00.000Z</dc:date>
<atom:updated>2020-01-21T09:00:00.000Z</atom:updated></item>
<item><title><![CDATA[ Using Kubernetes Deployments for Running PostgreSQL ]]></title>
<link>https://www.crunchydata.com/blog/using-kubernetes-deployments-for-running-postgresql</link>
<description><![CDATA[ The Crunchy PostgreSQL Operator helps to automate many typical database administration tasks at scale and leverages Kubernetes Deployments to flexibility in building environments that feature high-availability, configurable resource management, and seamless upgrades. ]]></description>
<content:encoded><![CDATA[ <p>Running PostgreSQL databases in containerized environments is <a href=https://blog.g2crowd.com/blog/containerization/best-apps-images-repositories-docker-hub-2017/>more popular than ever</a> and is moving beyond running only in local, development environments and into <a href=https://blog.openshift.com/leveraging-the-crunchy-postgresql/>large scale production environments</a>. To answer the need to orchestrate complex, database workloads, the Crunchy Data team created the <a href=https://github.com/CrunchyData/postgres-operator>PostgreSQL Operator</a> to automate many typical database administrator tasks at scale:<ul><li>Provisioning new PostgreSQL clusters<li>Scaling up replicas<li>Setup and manage disaster recovery, high-availability, and monitoring<li>Allocate resources (memory, CPU, etc.) and suggest nodes for databases to run on<li>Mass applying user policies<li>Performing major/minor upgrades</ul><p>and more. In order to keep all of its PostgreSQL databases up and running, the PostgreSQL Operator uses <a href=https://kubernetes.io/docs/concepts/workloads/controllers/deployment/>Kubernetes Deployments</a>, which provides an API to manage replicated applications. In order to understand why this is, first we need to understand about running stateful applications with Kubernetes.<h2 id=running-stateful-applications-with-kubernetes><a href=#running-stateful-applications-with-kubernetes>Running Stateful Applications With Kubernetes</a></h2><p><img alt="crunchy-postgresql-operator-architecture-2-Operator Architecture-arch"loading=lazy src=https://cdn2.hubspot.net/hubfs/2283855/crunchy-postgresql-operator-architecture-2-Operator%20Architecture-arch.png><p>Kubernetes began as a project that focused on managing the compute workload of container-based applications and did not worry about storage management. As the project has matured, the Kubernetes community has incorporated the building blocks that make it possible to run stateful workloads, such as databases, in a Kubernetes environment. Tools such as the <a href=https://coreos.com/operators/>Operator Framework</a> have allowed developers to capture the various nuances of managing complex stateful workloads, e.g. a relational database, and take full advantages of Kubernetes ability to schedule and manage container runtimes.<p>When it comes to managing stateful applications, Kubernetes offers a few different solutions. We are going to focus using <a href=https://kubernetes.io/docs/concepts/workloads/controllers/deployment/>Deployments</a>. A Deployment manages pods based on a particularly container image and operates in a replicated Kubernetes environment, i.e. it uses a <a href=https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/>ReplicaSet</a> and aim to have a given number of pods running at any time.<h2 id=why-run-postgresql-with-kubernetes-deployments><a href=#why-run-postgresql-with-kubernetes-deployments>Why Run PostgreSQL With Kubernetes Deployments?</a></h2><p><img alt=crunchy-postgresql-operator-architecture-2 loading=lazy src=https://cdn2.hubspot.net/hubfs/2283855/crunchy-postgresql-operator-architecture-2.png><p>Running your clusters with Kubernetes Deployments gives you flexibility in how you operate your cluster and other advantages, including:<h3 id=using-different-storage-classes><a href=#using-different-storage-classes>Using Different Storage Classes</a></h3><p>Often in database environments, you will have databases running on different types of disks. For example, you may want your primary databases to run on fast disks, replica databases to run on medium-speed disks, and development databases to run on slow disks.<p>The PostgreSQL Operator accounts for this by allowing you to create different <a href=https://kubernetes.io/docs/concepts/storage/storage-classes/>storage classes</a> for <a href=https://kubernetes.io/docs/concepts/storage/persistent-volumes/><dfn>persistent volumes</dfn></a> (<abbr>PVs</abbr>). When you provision a new database using the PostgreSQL Operator, whether its a primary or a replica, you can specify which storage class for the new persistent volume to use.<p>Additionally, utilizing Kubernetes Deployments allows you to use different storage engines within the same deployment. For instance, you may want to run your primary instances on NFS preallocated persistent volumes but use dynamic storage classes with your replicas using an engine like Gluster.<h3 id=choosing-your-operating-environment><a href=#choosing-your-operating-environment>Choosing Your Operating Environment</a></h3><p>In Kubernetes, a <a href=https://kubernetes.io/docs/concepts/architecture/nodes/>node</a> is a machine (physical or virtual) that is responsible for executing workloads. For our purposes, a node is where the PostgreSQL database software runs.<p>Often a production requirement of running PostgreSQL (let alone any database) is to select the hardware for your database system to operate in. For instance, you typically do not want you primary and replica instances to run on the same physical machine as any problems to the machine could impact your database system availability. Similarly, you may want to have your primary instances run on nodes that have better hardware than your replicas.<p>The PostgreSQL Operator uses <a href=https://kubernetes.io/docs/concepts/configuration/assign-pod-node/>node labels</a> in Kubernetes to create “node affinity” rules, such as “do not deploy a primary and replica to the same node.” Users can specify specific node label rules on each part of a PostgreSQL Deployment (primary and replicas) that influence which node a database workload is scheduled on. This enables a fine-tuned placement of a PostgreSQL database cluster across a Kubernetes nodes.<p>Additionally, the PostgreSQL Operator also allows you to <a href=https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/>specify what CPU and memory resources</a> to each primary or replica instance deployed, giving you finer grained control over how many resources a database can use.<h3 id=selective-postgresql-version-upgrades><a href=#selective-postgresql-version-upgrades>Selective PostgreSQL Version Upgrades</a></h3><p>A favorite past time of every PostgreSQL administrator is planning upgrades and ensuring that they can minimize downtime for all affected users. There are many <a href=https://www.postgresql.org/docs/current/static/upgrading.html>different strategies for upgrading</a>, including some special ones for <a href=https://bricklen.github.io/2018-03-27-Postgres-10-upgrade/>very large clusters</a>, all of which involve different levels of outages. A common theme for upgrading multiple clusters involves using “rolling upgrades,” or selectively upgrading each cluster. In addition to often being easier to manage, this gives the database administrator the ability to rollback an individual cluster should the upgrade fail.<p>The PostgreSQL Operator comes with the ability to perform selective upgrades across all of the PostgreSQL clusters its managing using a combination of Kubernetes selectors and individual PostgreSQL images.<h2 id=conclusion><a href=#conclusion>Conclusion</a></h2><p>There are other ways to run PostgreSQL clusters in a Kubernetes environment (in fact we provide some examples in the <a href=https://github.com/CrunchyData/crunchy-containers>Crunchy Container Suite</a>). The architecture decision to use Deployments in the Crunchy PostgreSQL Operator is specifically geared around flexibility: high-availability: you can choose different nodes, resources, and storage solutions for your databases based upon your operating requirements.<p>The Crunchy PostgreSQL Operator is actively being developed - we recently <a href=https://github.com/CrunchyData/postgres-operator/releases/tag/3.1>released version 3.1</a> - to help you take full advantage of running your PostgreSQL workloads on Kubernetes and ensure you can run your PostgreSQL clusters with all your good database administrator habits. ]]></content:encoded>
<category><![CDATA[ Kubernetes ]]></category>
<author><![CDATA[ Crunchy.Data@crunchydata.com (Crunchy Data) ]]></author>
<dc:creator><![CDATA[ Crunchy Data ]]></dc:creator>
<guid isPermalink="false">https://blog.crunchydata.com/blog/using-kubernetes-deployments-for-running-postgresql</guid>
<pubDate>Mon, 30 Jul 2018 05:00:00 EDT</pubDate>
<dc:date>2018-07-30T09:00:00.000Z</dc:date>
<atom:updated>2018-07-30T09:00:00.000Z</atom:updated></item></channel></rss>