Deploy Postgresql on AKS

Kopl 166 Reputation points
2022-02-03T17:26:13.623+00:00

Hello,

I am trying to deploy a postgresql database in AKS using Persistent Volume Claim. Could you please help?

Thanks!

Azure Kubernetes Service
Azure Kubernetes Service
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,458 questions
{count} votes

Accepted answer
  1. shiva patpi 13,366 Reputation points Microsoft Employee Moderator
    2022-02-04T02:09:34.647+00:00

    Hello @ahmed-86273 ,
    I just tried below yaml files to deploy postgresdb pod , try to format it accordingly !

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: pvc-postgre
    spec:
    accessModes:
    - ReadWriteOnce
    storageClassName: managed-premium
    resources:
    requests:
    storage: 1Gi
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: postgresdb
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: postgresdb
    template:
    metadata:
    labels:
    app: postgresdb
    spec:
    containers:
    - name: postgresdb
    image: postgres:latest
    ports:
    - containerPort: 5432
    env:
    - name: POSTGRES_USER
    value: postgresuser
    - name: POSTGRES_PASSWORD
    value: postgrespwd
    - name: POSTGRES_DB
    value: postgresdb
    - name: PGDATA
    value: /var/lib/postgresql/backup
    volumeMounts:
    - name: database
    mountPath: /var/lib/postgresql
    subPath: backup
    volumes:
    - name: database
    persistentVolumeClaim:
    claimName: pvc-postgre

    ////////////////////////////////////////////

    After deploying that YAML file , a pod will get created

    171187-image.png

    //////////////////////////////////////////

    Login to that POD to perform all the psql related operations:

    171157-image.png

    /////////////////////////////////////////

    Additionally you can expose the pod through a load balancer type service by using below yaml

    apiVersion: v1
    kind: Service
    metadata:
    name: postgres-db-lb
    spec:
    selector:
    app: postgresdb
    type: LoadBalancer
    ports:

    • port: 5432

    //////////////////////////////////////////////

    LB IP gets created
    171100-image.png

    ///////////////////////////////////////////
    you can use that LB IP to connect by leveraging pgadmin UI tool.

    Download pgadmin tool from here https://www.postgresql.org/ftp/pgadmin/pgadmin4/v6.4/windows/

    Connect to it and you are good to go!

    171221-image.png

    Let us know if those steps helps you out in getting started with postgres + AKS + PVC !

    Regards,
    Shiva.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.