Tuesday 2 April 2019

How to take postgresql dump from kubernetes cluster on Google cloud Platform


How to take PostgreSQL dump from Kubernetes cluster on Google cloud Platform








Almost all the web application has the database. When we deploy our application in Cloud (in this case Google Cloud Platform) it’s quite possible that we put the database on a different POD other than the application POD.

In this section we are going to show, how can we take the Postgres DB dump which is deployed on the Kubernetes cluster.

Assumptions: The postgres pod is already deployed in the Kubernetes cluster.

Steps 

1. Open the browser and go to the  "https://console.cloud.google.com/" 
2. On the GCP menu click on the "Activate Cloud Shell" 

3. Find out the name of the running POD using the command 
yogeshsonawane@cloudshell:~ (Project-1)$ kubectl get pods | grep <Name of deployment or Pod>
e.g. kubectl get pods | grep "mytestApp"

4. Switch to the raw terminal mode i.e. Open a shell in the running Kubernetes POD

        kubectl exec -it <POD Name> -c <Container Name> -- /bin/bash
        kubectl exec -it mytestApp-7c4fb7594c-qd94j   -c datastore -- /bin/bash

In this command "mytestApp-7c4fb7594c-qd94j" is the POD name found from the command in step#3. "DataStore" is the container name.

5. take the pgdump
        /usr/bin/pg_dump --dbname mcmdb -u myappb  > myappdb.sql

6. Open another shell. by clicking on the "Add Cloud Shell Session  button " (+) button displayed on the 
7. copy the dump file from pg datastore cluster to outside. i.e. to the current shell.
8. take the pgdump using the following command
        kubectl cp mytestApp-7c4fb7594c-qd94j:/root/ myappdb.sql  -c datastore .

You can also copy this dump file to the Google Storage bucket using the following command.

gsutil cp myappdb.sql gs://<bucket_name>/<folder_inside_bucket>/

9. Download the dump using the option available in the active shell session.

10 comments:

  1. A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  2. Thanks for updating the information I liked it
    Sanjary Academy is the best Piping Design institute in Hyderabad, Telangana. It is the best Piping design Course in India and we have offer professional Engineering Courses like Piping design Course, QA/QC Course, document controller course, Pressure Vessel Design Course, Welding Inspector Course, Quality Management Course and Safety Officer Course.
    Piping Design Course

    ReplyDelete
  3. Excellent explanation of the information provided

    Pressure Vessel Design Course is one of the courses offered by Sanjary Academy in Hyderabad. We have offer professional Engineering Course like Piping Design Course,QA / QC Course,document Controller course,pressure Vessel Design Course,Welding Inspector Course, Quality Management Course, #Safety officer course.
    Document Controller course
    Pressure Vessel Design Course
    Welding Inspector Course
    Safety officer course
    Quality Management Course
    Quality Management Course in India

    ReplyDelete
  4. Very impressive article! The blog is highly informative and has answered all my questions.
    To introduce about our company and the activities, B2b contact list is a database provider
    that helps you to boost your sales & grow your business through well-build Google-Cloud-Platform-Users-Email

    ReplyDelete
  5. Nice Post! Thank you for sharing very good post, it was so nice to read and useful to improve my knowledge
    Google Cloud Platform Training
    GCP Online Training
    Google Cloud Platform Training In Hyderabad

    ReplyDelete
  6. Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome
    Rani Durgavati VishwaVidhyalaya BCOM 1st, 2nd & Final Year Time Schedule 2020

    ReplyDelete
  7. Your blog is in a convincing manner, thanks for sharing such an information with lots of your effort and time
    Kubernetes online training
    Kubernetes certification training
    Kubernetes training
    Kubernetes course

    ReplyDelete
  8. Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended.
    If you want Digital Marketing Serives :-
    Digital marketing Service in Delhi
    SMM Services
    PPC Services in Delhi
    Website Design & Development Packages
    SEO Services PackagesLocal SEO services
    E-mail marketing services
    YouTube plans

    ReplyDelete
  9. Excellent post. I was always checking this blog, Mustache Transplantation Cost

    ReplyDelete