How To Deploy PostgreSQL on Kubernetes
What is PostgreSQL?
PostgreSQL is a powerful, open source Relational Database Management System. PostgreSQL is not controlled by any organization or any individual. Its source code is available free of charge. It is pronounced as "post-gress-Q-L".
PostgreSQL has earned a strong reputation for its reliability, data integrity, and correctness.
- It runs on all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, MacOS, Solaris, Tru64), and Windows.
- It is fully ACID compliant, has full support for foreign keys, joins, views, triggers, and stored procedures (in multiple languages).
- It includes most SQL:2008 data types, including INTEGER, NUMERIC, BOOLEAN, CHAR, VARCHAR, DATE, INTERVAL, and TIMESTAMP.
- It also supports storage of binary large objects, including pictures, sounds, or video.
- It has native programming interfaces for C/C++, Java, .Net, Perl, Python, Ruby, Tcl, ODBC, among others, and exceptional documentation.
To follow this guide you need -
Step 1 - Create a PostgreSQL Container Image
Create a file name “Dockerfile” for PostgreSQL. This image contains our custom config dockerfile which will look like -
This Postgres image has a base image of ubuntu xenial. After that, we create Super User and default databases. Exposing 5432 port will help external system to connect the PostgreSQL server.
Step 2 - Build PostgreSQL Docker Image
Step 3 - Create a Storage Volume (Using GlusterFS)
Using below-mentioned command create a volume in GlusterFS for PostgreSQL and start it. As we don’t want to lose our PostgreSQL Database data just because a Gluster server dies in the cluster, so we put replica 2 or more for higher availability of data.
Step 4 - Deploy PostgreSQL on Kubernetes
Deploying PostgreSQL on Kubernetes have following prerequisites -
Docker Image: We have created a Docker Image for Postgres in Step 2
Persistent Shared Storage Volume: We have created a Persistent Shared Storage Volume in Step 3
Deployment & Service Files: Next, we will create Deployment & Service Files
Create a file name “deployment.yml” for PostgreSQL. This deployment file will look like -
We need to Define the Environment Variables for PostgreSQL
1. POSTGRES_USER (Super Username for PostgreSQL)
2. POSTGRES_PASSWORD (Super User password for PostgreSQL)
3. PGDATA (Data Directory for PostgreSQL Database)
Now we need to create a file named “service.yml” for PostgreSQL. This deployment file will look like -
Now let's deploy PostgreSQL using following commands:
Now you have successfully Deployed PostgreSQL on Kubernetes
PostgreSQL is a powerful, open source object-relational database system. PostgreSQL on kubernetes helped to utilize resources even much better than virtual machines and also provide isolation from other apps which are deployed on the same machine.
At XenonStack we have specialized professionals that can help you in starting with Microservices Architecture, NoSQL and SQL Database like PostgreSQL On Docker & Kubernetes. Reach Us for Development, Deployment, and Consulting for MicroServices, Kubernetes, and Docker Technology Solutions.
XenonStack is a leading Software Company in Product Development and Solution Provider for DevOps, Big Data Integration, Real Time Analytics & Data Science.
Product NexaStack - Unified DevOps Platform Provides monitoring of Kubernetes, Docker, OpenStack infrastructure, Big Data Infrastructure and uses advanced machine learning techniques for Log Mining and Log Analytics.
Product ElixirData - Modern Data Integration Platform Enables enterprises and Different agencies for Log Analytics and Log Mining.
Product Akira.AI is an Automated & Knowledge Drive Artificial Intelligence Platform that enables you to automate the Infrastructure to train and deploy Deep Learning Models on Public Cloud as well as On-Premises.
Get 1 Hour Free Assessment For DevOps, Big Data Strategy, and Data Science. CONTACT US NOW!