I am trying to install postgresdb in minikube environment and access it from my django-app. This is my deployment file
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres-deployment
labels:
app: posrgres-db
type: app-db
spec:
template:
metadata:
name: postgres-pod
labels:
app: posrgres-db
type: app-db
spec:
containers:
- name: posrgres-db
image: postgres
ports:
- containerPort: 5432
env:
- name: POSTGRES_USER
value: "postgres"
- name: POSTGRES_PASSWORD
value: "Ssl12345#"
- name: POSTGRES_DB
value: appserver_db
replicas: 1
selector:
matchLabels:
app: posrgres-db
type: app-db
I want to create custom database named appserver_db, Any idea on how it can be achieved ?? Do I have to install pgAdmin and go that way?
CodePudding user response:
create a job which connects to the pod and create a database on your database:
apiVersion: batch/v1
kind: Job
metadata:
name: id
spec:
ttlSecondsAfterFinished: 20
template:
spec:
containers:
- name: postgres
image: bitnami/postgresql:11.5.0
command:
- createdb
args:
- "-h"
- postgres
- "-U"
- postgres
- DESIRED_DB_NAME
env:
- name: PGPASSWORD
value: YOUR_PSQL_PASSWORD
restartPolicy: Never
CodePudding user response:
Kubernetes pods are ephemeral. Which means, when they are restarted you will lose data. For databases you have to use PersistentVolumes and PersistentVolumeClaims. Also, use a Statefulset instead of deployments (optional). Take a look at : https://kubernetes.io/docs/concepts/storage/persistent-volumes/
CodePudding user response:
Please see the follow article:
https://itnext.io/basic-postgres-database-in-kubernetes-23c7834d91ef
I would recommend using helm rather than yaml files it will simply the installation process.