---
title: "How to Deploy Postgres to Kubernetes"
description: "Learn how to securely deploy PostgreS to Kubernetes using two methods, via Helm charts and YAML configurations, in this step-by-step tutorial!"
canonical: "https://adamtheautomator.com/postgres-to-kubernetes/"
---

# How to Deploy Postgres to Kubernetes

> Learn how to securely deploy PostgreS to Kubernetes using two methods, via Helm charts and YAML configurations, in this step-by-step tutorial!

Source: https://adamtheautomator.com/postgres-to-kubernetes/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Deploy Postgres to Kubernetes](https://adamtheautomator.com/wp-content/uploads/2022/04/How-to-Deploy-Postgres-to-Kubernetes.jpg)

# How to Deploy Postgres to Kubernetes

[![](https://secure.gravatar.com/avatar/572a248f516b6d0cd566cb44fdbd9336f30ef95aa0f6d78f118c1f47b1b6d6b7?s=192&d=mm&r=g)Arvid Larson](https://adamtheautomator.com/author/arvid-larson/)27 April 202210 min. read

Categories: [DevOps](/category/devops/)

Tags:[Kubernetes](/tag/kubernetes/)[PostgreSQL](/tag/postgresql/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Deploying PostgreSQL with Helm Chart](#deploying-postgresql-with-helm-chart)
*   [Adding a Helm Chart Repository](#adding-a-helm-chart-repository)
*   [Creating a PersistentVolume (PV) and a PersistentVolumeClaim (PVC)](#creating-a-persistentvolume-pv-and-a-persistentvolumeclaim-pvc)
*   [Creating a Custom Configuration](#creating-a-custom-configuration)
*   [Deploying PostgreSQL to Kubernetes](#deploying-postgresql-to-kubernetes)
*   [Connecting to PostgreSQL](#connecting-to-postgresql)
*   [Deploying PostgreSQL to Kubernetes Manually](#deploying-postgresql-to-kubernetes-manually)
*   [Creating a ConfigMap to Store Database Details](#creating-a-configmap-to-store-database-details)
*   [Creating PersistentVolume (PV) and PersistentVolumeClaim (PVC)](#creating-persistentvolume-pv-and-persistentvolumeclaim-pvc)
*   [Creating PostgreSQL Deployment](#creating-postgresql-deployment)
*   [Creating a Service for PostgreSQL](#creating-a-service-for-postgresql)
*   [Connecting to PostgreSQL via kubectl Command](#connecting-to-postgresql-via-kubectl-command)
*   [Connecting to PostgreSQL via PostgreSQL Client](#connecting-to-postgresql-via-postgresql-client)
*   [Conclusion](#conclusion)

Deploying PostgreSQL with container technology can be challenging, especially in complicated environments, like Kubernetes. But no worries, this tutorial got you covered, so you can securely deploy PostgreSQL to Kubernetes.

In this tutorial, you will learn how to install and deploy PostgreS to Kubernetes environment in two different ways, using Helm charts and using manual YAML configurations.

## Prerequisites

This tutorial will be a hands-on demonstration. To follow along, be sure you have the following:

*   A Kubernetes cluster or local [Kubernetes](https://adamtheautomator.com/aws-eks-cli/) environment, such as [Minikube](https://minikube.sigs.k8s.io/docs/start/).

Related:[How to Create a Kubernetes Cluster With the AWS EKS CLI](https://adamtheautomator.com/aws-eks-cli/)

*   [Helm](https://helm.sh/docs/) installed on your local machine.

Related:[Getting Started With Kubernetes Helm](https://adamtheautomator.com/kubernetes-helm/)

*   [kubectl](https://kubernetes.io/docs/reference/kubectl/) tool installed on your local machine.
    
*   A Linux client machine.
    

## Deploying PostgreSQL with Helm Chart

Helm is the package manager for Kubernetes that allows you to deploy applications to Kubernetes in no time. Helm simplifies the application deployment complexity on Kubernetes and comes with quick update features, sharing of charts, and rollbacks feature.

Learn how to deploy PostgreSQL to Kubernetes using the Helm repository as your template in the following sections.

### Adding a Helm Chart Repository

Many available Helm repositories you can use to deploy PostgreSQL to Kubernetes. But this tutorial uses the Helm repository provided by Bitnami.

> _For the complete list of available Helm repositories, visit_ [_Artifacthub.io_](https://artifacthub.io/)_._

Open your terminal, and run the `helm` commands below to add the Bitnami helm repository to your system and refresh the index chart of the Helm repository.

```bash
# Add Helm repository by Bitnami
helm repo add bitnami <https://charts.bitnami.com/bitnami>

# Update Helm index charts
helm repo update
```

![Updating and Refreshing Helm Index Charts](https://adamtheautomator.com/wp-content/uploads/2022/04/image-350.png)

Updating and Refreshing Helm Index Charts

Now run the `helm` command below to verify the list of available Helm repositories on your system.

```bash
helm repo lists
```

You should get the Bitnami Helm repository available on your system, as shown below.

![Verifying Repository](https://adamtheautomator.com/wp-content/uploads/2022/04/image-351.png)

Verifying Repository

### Creating a PersistentVolume (PV) and a PersistentVolumeClaim (PVC)

You’ve now added the Bitnami Helm repository to your system. But before deploying your PostgreSQL, you’ll need a place for storing PostgreSQL data permanently.

You’ll create the [PersistentVolume (PV) and PersistentVolumeClaim (PVC)](https://kubernetes.io/docs/concepts/storage/persistent-volumes/) on Kubernetes:

*   PV – is a Kubernetes resource for storing data of your applications.

> _There are multiple types of PV supported by Kubernetes. These PV types include local directory and third-party cloud storage providers, such as Amazon EBS and AzureDisk._

*   PVC – is the way your application uses a given PV. PVC is used to mount a PV to your application’s pod.

To create persistent storage:

1\. Create a new YAML configuration (_local-pv.yaml_) file with your preferred editor and populate the following configuration.

The configuration below creates a new PV named postgresql-data on Kubernetes with the PV’s type as local. Be sure to change the storage capacity with your need and the path with your local directory.

```yaml
apiVersion: v1
kind: PersistentVolume # Create a PV
metadata:
  name: postgresql-data # Sets PV's name
  labels:
    type: local # Sets PV's type to local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi # Sets PV Volume
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/volume" # Sets the volume's path
```

2\. Next, run the [`kubectl apply`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply) command below to apply the configuration in the `local-pv.yaml` file to Kubernetes.

```bash
kubectl apply -f local-pv.yaml
```

3\. Create another YAML configuration file (_pv-claim.yaml_) and populate the following configuration.

The below configuration creates a PVC named postgresql-data-claim with the size of 10GB.

```yaml
apiVersion: v1
kind: PersistentVolumeClaim # Create PVC
metadata:
  name: postgresql-data-claim # Sets name of PV
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce # Sets read and write access
  resources:
    requests:
      storage: 10Gi # Sets volume size
```

4\. Now, run the `kubectl` command below to apply the `pv-claim.yaml` configuration.

```bash
kubectl apply -f pv-claim.yaml
```

5\. Lastly, run each command below to verify the PV and PVC on your Kubernetes.

```bash
# Checking PersistentVolume
kubectl get pv

# Checking PersistentVolumeClaim
kubectl get pvc
```

If your configurations are correct, you’ll see an output similar to below. The PV (postgresql-data) is bounded to the PVC (postgresql-data-claim) and vice-versa.

![](https://adamtheautomator.com/wp-content/uploads/2022/04/image-352-1024x168.png)

Verifying PersistentVolume (PV) and PersistentVolumeClaim (PVC)

### Creating a Custom Configuration

You’ve now created the PV and PVC on your Kubernetes for permanently storing data. But how about your PostgreSQL secrets?

Typically, you wouldn’t want sensitive information lying around, so you’ll create a custom configuration. A custom configuration lets you store PostgreSQL secrets and add the `postgresql-data-claim` PVC to the PostgreSQL deployment for storing data permanently.

1\. Create a new configuration file (_values.yaml_) using your preferred editor and populate the following configuration.

The below configuration deploys the PostgreSQL to Kubernetes, creating a new database called app\_db and a new user named app1 with a password (StrongPassword).

```yaml
# define default database user, name, and password for PostgreSQL deployment
auth:
  enablePostgresUser: true
  postgresPassword: "StrongPassword"
  username: "app1"
  password: "AppPassword"
  database: "app_db"

# The postgres helm chart deployment will be using PVC postgresql-data-claim
primary:
  persistence:
    enabled: true
    existingClaim: "postgresql-data-claim"
```

### Deploying PostgreSQL to Kubernetes

You’ve completed setting up your resources, but they’re not doing much unless you deploy your PostgreSQL data to Kubernetes. You’ll start the PostgreSQL deployment to Kubernetes using the Bitnami Helm chart.

Run the [`helm install`](https://helm.sh/docs/helm/helm_install/) command below to deploy PostgreSQL to Kubernetes with the name `postgresql-dev` using the Bitnami Helm chart (`bitnami/postgresql`).

```bash
helm install postgresql-dev -f values.yaml bitnami/postgresql
```

After deployment, you’ll get an output like the screenshot below. As you can see, `postgresql-dev` is deployed to the Kubernetes with the default PostgreSQL version **14.1.0**.

Notice that you also get messages on how to connect to the PostgreSQL pod.

![](https://s3.us-west-2.amazonaws.com/secure.notion-static.com/9f96ecfc-38cf-4fba-86d6-9578bd6537f5/deploy-postgresql.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220413%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220413T200324Z&X-Amz-Expires=86400&X-Amz-Signature=1366976ab5df7b4b91c636f872ecd6d907576f30b0a76bbed34c8fccada57b7a&X-Amz-SignedHeaders=host&response-content-disposition=filename%20%3D%22deploy-postgresql.png%22&x-id=GetObject)

Deploying PostgreSQL to Kubernetes using Helm

Now, run the `kubectl` commands below to check the PostgreSQL pod and pod’s logs. Be sure to change `postgresql-dev-0` with your pod.

```bash
# Checking pods
kubectl get pods

# Checking logs of pods
kubectl logs postgresql-dev-0
```

As you can see below, the pod (**postgresql-dev-0**) **STATUS** is **running**. And at the bottom of pod logs, you’ll see the message **database system is ready to accept connections**. This message indicates the PostgreSQL deployment is complete.

![5-check-deployment](https://adamtheautomator.com/wp-content/uploads/2022/04/image-353.png)

5-check-deployment

### Connecting to PostgreSQL

At this point, you’ve completed the PostgreSQL deployment on Kubernetes. But how do you connect to the PostgreSQL database for managing the database itself?

You’ll connect to the PostgreSQL database on Kubernetes using a temporary pod. The temporary pod will automatically be deleted when the pod exits.

1\. Run the below `export` command to create the `POSTGRES_PASSWORD` environment variable, which contains the password for the PostgreSQL database (app\_db).

> _This command doesn’t have an output, but you’ll verify the PostgreSQL connection in the following steps._

```bash
export POSTGRES_PASSWORD=$(kubectl get secret --namespace default postgresql-dev -o jsonpath="{.data.password}" | base64 --decode)
```

2\. Next, run the [`kubectl run`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#run) command below to connect to the PostgreSQL database (`app_db`).

This command creates a new temporary pod called postgresql-dev-client that connects to the PostgreSQL database (app\_db) with the user app1.

```bash
kubectl run postgresql-dev-client --rm --tty -i --restart='Never' --namespace default --image docker.io/bitnami/postgresql:14.1.0-debian-10-r80 --env="PGPASSWORD=$POSTGRES_PASSWORD" \
--command -- psql --host postgresql-dev -U app1 -d app_db -p 5432
```

![Connecting to PostgreSQL Database](https://adamtheautomator.com/wp-content/uploads/2022/04/image-354.png)

Connecting to PostgreSQL Database

3\. Lastly, run the following PostgreSQL query to verify your connection to the PostgreSQL database.

```bash
# Checking PostgreSQL connection
\conninfo

# Logout from PostgreSQL shell
exit
```

Below, you can see that you’re connected to the PostgreSQL database (app\_db) inside Kubernetes using the database user app1.

Notice that when you log out from the PostgreSQL shell, the pod postgresql-dev-client is deleted.

![Connecting to PostgreSQL on Kubernetes and Verifying Connection](https://adamtheautomator.com/wp-content/uploads/2022/04/image-355.png)

Connecting to PostgreSQL on Kubernetes and Verifying Connection

## Deploying PostgreSQL to Kubernetes Manually

You’ve seen how to deploy PostgreSQL using a Helm chart as your template, so why choose manual deployment? The advantage of deploying PostgreSQL to Kubernetes manually is that it gives you a more in-depth understanding of application deployment on the Kubernetes environment.

You’ll create some Kubernetes resources required to manually deploy the PostgreSQL to Kubernetes.

### Creating a ConfigMap to Store Database Details

Deploying PostgreSQL to Kubernetes manually requires some Kubernetes resources. One of those resources is a ConfigMap, an API object you’ll use to store key-value pairs.

You’ll create a Kubernetes ConfigMap to store database details such as user, database name, and password for the PostgreSQL deployment.

> _For the production environment, deploying secrets such as password authentication using the [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/secret/) is highly recommended for security._

1\. Create a new YAML configuration file (_postgres-configmap.yaml_) and populate the following configuration. The configuration below creates a `ConfigMap` named `postgres-secret` for the `postgres` application and a database called `appdb`.

You can set the database details with your preferred ones. But for this tutorial, the user is set as appuser and the password as strongpassword.

```yaml
# Create ConfigMap postgres-secret for the postgres app
# Define default database name, user, and password
apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-secret
  labels:
    app: postgres
data:
  POSTGRES_DB: appdb
  POSTGRES_USER: appuser
  POSTGRES_PASSWORD: strongpasswordapp
```

2\. Now run the `kubectl` command below to apply the configuration in the `postgres-configmap.yaml` file.

```bash
kubectl apply -f postgres-configmap.yaml
```

![Applying the postgres-configmap.yaml Configuration to Create a ConfigMap](https://adamtheautomator.com/wp-content/uploads/2022/04/image-356.png)

Applying the _postgres-configmap.yaml_ Configuration to Create a ConfigMap

3\. Lastly, run the below command to get the list of ConfigMaps on your Kubernetes.

```bash
kubectl get configmap
```

You’ll see the postgres-secret ConfigMap on the list, as shown below.

![Checking Kubernetes ConfigMap](https://adamtheautomator.com/wp-content/uploads/2022/04/image-357.png)

Checking Kubernetes ConfigMap

### Creating PersistentVolume (PV) and PersistentVolumeClaim (PVC)

Like deploying PostgreSQL with Helm chart, you’ll also create a PV and PVC for manual deployment to store PostgreSQL data on your Kubernetes host permanently.

1\. Create a new YAML configuration file (_postgres-volume.yaml_) and populate the following configuration.

The configuration below creates a new PV called postgres-volume with a type as local on the Kubernetes host.

```yaml
apiVersion: v1
kind: PersistentVolume # Create PV 
metadata:
  name: postgres-volume # Sets PV name
  labels:
    type: local # Sets PV's type
    app: postgres
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi # Sets PV's size
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/data/postgresql" # Sets PV's host path
```

2\. Next, run the `kubectl` command below to `apply` the `postgres-volume.yaml` file’s configuration.

```bash
kubectl apply -f postgres-volume.yaml
```

![Applying the postgres-volume.yaml Configuration to Create a PV](https://adamtheautomator.com/wp-content/uploads/2022/04/image-358.png)

Applying the _postgres-volume.yaml_ Configuration to Create a PV

3\. Create another configuration file (_postgres-pvc.yaml_) and populate the following configuration.

This configuration creates the PVC called postgres-volume-claim for your PostgreSQL deployment.

```yaml
apiVersion: v1
kind: PersistentVolumeClaim # Create PVC
metadata:
  name: postgres-volume-claim # Sets PVC's name
  labels:
    app: postgres # Defines app to create PVC for
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi # Sets PVC's size
```

4\. Now run the following command to `apply` the `postgres-pvc.yaml` file’s configuration.

```bash
kubectl apply -f postgres-pvc.yaml
```

![Applying the postgres-pvc.yaml Configuration to Create a PVC](https://adamtheautomator.com/wp-content/uploads/2022/04/image-359.png)

Applying the _postgres-pvc.yaml_ Configuration to Create a PVC

5\. Lastly, run each command below to verify all available PV and PVC on your Kubernetes.

```bash
# Get list of PersistentVolume
kubectl get pv

# Get list of PersistentVolumeClaim
kubectl get pvc
```

You should see the postgres-volume PV  and the postgres-volume-pvc PVC with the status Bound to each other like the screenshot below.

![Verifying PV and PVC on Kubernetes](https://adamtheautomator.com/wp-content/uploads/2022/04/image-360.png)

Verifying PV and PVC on Kubernetes

### Creating PostgreSQL Deployment

You’ve created a PersistentVolume and PersistentVolumeClaim for the PostgreSQL deployment. Now it’s time to create a PostgreSQL deployment and declare Pods configuration for the PostgreSQL in Kubernetes.

1\. Create a new YAML file for the PostgreSQL deployment called _postgres-deployment.yaml_ using your preferred editor and populate the following configuration.

```yaml
apiVersion: apps/v1
kind: Deployment # Create a deployment
metadata:
  name: postgres # Set the name of the deployment
spec:
  replicas: 3 # Set 3 deployment replicas
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:12.10 # Docker image
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432 # Exposing the container port 5432 for PostgreSQL client connections.
          envFrom:
            - configMapRef:
                name: postgres-secret # Using the ConfigMap postgres-secret
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgresdata
      volumes:
        - name: postgresdata
          persistentVolumeClaim:
            claimName: postgres-volume-claim
```

2\. Next, run the `kubectl` command below to `apply` the `postgres-deployment.yaml` configuration to create the PostgreSQL deployment.

This command will download Docker images postgres:12.10 for your deployment and create three pods replicas.

```bash
kubectl apply -f postgres-deployment.yaml
```

![Applying postgres-deployment.yaml Configuration to Create the PostgreSQL Deployment](https://adamtheautomator.com/wp-content/uploads/2022/04/image-361.png)

Applying _postgres-deployment.yaml_ Configuration to Create the PostgreSQL Deployment

3\. Run the `kubectl` command below to verify the list of running pods and deployments on your Kubernetes.

```bash
# checking Kubernetes deployment
kubectl get deployments

# checking pods
kubectl get pods
```

Below is the screenshot of pods in creating status. The STATUS of all pods is still on the ContainerCreating process.

![Viewing ContainerCreating for the PostgreSQL Deployment](https://adamtheautomator.com/wp-content/uploads/2022/04/image-362.png)

Viewing ContainerCreating for the PostgreSQL Deployment

After the deployment process completes, you’ll see the STATUS of all pods is Running.

![Viewing Completed PostgreSQL Deployment on Kubernetes](https://adamtheautomator.com/wp-content/uploads/2022/04/image-363.png)

Viewing Completed PostgreSQL Deployment on Kubernetes

### Creating a Service for PostgreSQL

At this point, you’ve completed the deployment of PostgreSQL on Kubernetes. But how do you let clients connect to the PostgreSQL pod? You’ll expose PostgreSQL outside of the Kubernetes environment by creating and running a Kubernetes service.

1\. Create a new YAML configuration file (_postgres-service.yaml_) and populate the following configuration.

This configuration creates the Kubernetes service with the type as [NodePort](https://docs.openshift.com/container-platform/3.11/dev_guide/expose_service/expose_internal_ip_nodeport.html) for the postgres application running on the default port 5432.

```yaml
apiVersion: v1
kind: Service # Create service
metadata:
  name: postgres # Sets the service name
  labels:
    app: postgres # Defines app to create service for
spec:
  type: NodePort # Sets the service type
  ports:
    - port: 5432 # Sets the port to run the postgres application
  selector:
    app: postgres
```

2\. Next, run the `kubectl` command below to `apply` the `postgres-service.yaml` configuration to create a new Kubernetes service.

```bash
kubectl apply -f postgres-service.yaml
```

![Applying postgres-service.yaml Configuration to Create New Kubernetes Service](https://adamtheautomator.com/wp-content/uploads/2022/04/image-364.png)

Applying _postgres-service.yaml_ Configuration to Create New Kubernetes Service

3\. Lastly, run the `kubectl get` command below to verify the Kubernetes service.

```bash
kubectl get svc
```

Below, you can see that the postgres service with the type NodePort exposes the port 31398 on the Kubernetes host for the PostgreSQL client connections.

> _You may have a different port than 31398 because the NodePort is a randomly selected port for your service. The NodePort service will randomly select the port for your service between 30000-32767._

Notice the NodePort 31398 on the Kubernetes host is mapped to PostgreSQL pods on port 5432.

![Checking Postgres Kubernetes Service](https://adamtheautomator.com/wp-content/uploads/2022/04/image-365.png)

Checking Postgres Kubernetes Service

### Connecting to PostgreSQL via `kubectl` Command

You’ve created the Kubernetes service resource for the PostgreSQL deployment, and now you’re ready to connect to the PostgreSQL pod. How? You’ll connect to the PostgreSQL shell using the [`kubectl exec`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec) command or the PostgreSQL client on your host.

> _You can jump to the “Connecting to PostgreSQL via PostgreSQL Client” section if you prefer to use the PostgreSQL client instead._

1\. Run the `kubectl exec` command below to connect to the PostgreSQL pod. Be sure to change the pod name, database name, and the user.

```bash
kubectl exec -it postgres-xxxx -- psql -h localhost -U appuser --password -p 5432 appdb
```

2\. Input the password for your database, and you’ll get the PostgreSQL shell like the screenshot below.

![12-connect-topostgresql](https://adamtheautomator.com/wp-content/uploads/2022/04/image-366.png)

12-connect-topostgresql

3\. Lastly, run the query below to get information about your connection to the PostgreSQL shell and type `exit` to log out.

```bash
\conninfo
```

![Connecting to PostgreSQL pod using kubectl](https://adamtheautomator.com/wp-content/uploads/2022/04/image-367.png)

Connecting to PostgreSQL pod using kubectl

### Connecting to PostgreSQL via PostgreSQL Client

If you prefer to connect to the PostgreSQL shell using the PostgreSQL client, run the [`psql`](https://www.geeksforgeeks.org/postgresql-psql-commands/) command instead. Be sure the PostgreSQL client packages are installed on your local machine.

1\. Run the `psql` command below to connect to the PostgreSQL pod through the NodePort (`31389`). Change the IP address `192.168.39.196` with your Kubernetes host IP address and port `31398` with the port of your NodePort resources.

```bash
psql -h 192.168.39.196 -U appuser --password -p 31398 appdb
```

2\. Input the password for your database to connect to the PostgreSQL shell.

![Connecting to PostgreSQL Pod using PostgreSQL Client](https://adamtheautomator.com/wp-content/uploads/2022/04/image-368.png)

Connecting to PostgreSQL Pod using PostgreSQL Client

3\. Finally, run the query below to get information about your connection.

```bash
\conninfo
```

The output below confirms you’ve connected successfully to your PostgreSQL database.

![Connecting to PostgreSQL Pod](https://adamtheautomator.com/wp-content/uploads/2022/04/image-369.png)

Connecting to PostgreSQL Pod

## Conclusion

In this tutorial, you’ve learned how to deploy a PostgreSQL database to Kubernetes using the Helm chart. You’ve also deployed a PostgreSQL database manually using YAML configuration files. And at this point, you’ve acquired a basic understanding of how to deploy applications to Kubernetes securely.

Now how would you build on this newfound knowledge? Perhaps apply the [PostgreSQL High Availability](https://ralph.blog.imixs.com/2021/06/25/postgresql-ha-kubernetes/) on your Kubernetes?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpostgres-to-kubernetes%2F&text=How%20to%20Deploy%20Postgres%20to%20Kubernetes)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpostgres-to-kubernetes%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpostgres-to-kubernetes%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/07/featured_image-3.png)

### [Build Your First Internal Developer Platform](/build-first-internal-developer-platform/)

Build your first Internal Developer Platform with Backstage, a software catalog, software templates, CI/CD handoffs, and Kubernetes deployment manifests.

![](https://adamtheautomator.com/wp-content/uploads/2026/06/featured_image-9.png)

### [DevOps to Platform Engineer: 2026 Transition Roadmap](/devops-platform-engineer-2026-transition-roadmap/)

Learn how to move from DevOps to platform engineering in 2026 with a practical roadmap covering transferable skills, internal developer platforms, Backstage, Crossplane, and portfolio projects.

![](https://adamtheautomator.com/wp-content/uploads/2024/02/kubernetes-blue-green.jpg)

### [Learning the Kubernetes Blue Green Deployment Strategy](/kubernetes-blue-green/)

Dive into Kubernetes blue-green deployments for smooth updates. Enhance your release process with this smart Kubernetes strategy!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
