Browse Source

Añado PGO para ver si hago funcionar postgres

main
Celestino Rey 3 years ago
parent
commit
bc05163a85
13 changed files with 206 additions and 0 deletions
  1. +6
    -0
      PGO/creaTodo.sh
  2. +1
    -0
      PGO/entra.sh
  3. +10
    -0
      PGO/paraTodo.sh
  4. +20
    -0
      PGO/pgadmin-configmap.yaml
  5. +8
    -0
      PGO/pgadmin-secret.yaml
  6. +13
    -0
      PGO/pgadmin-service.yaml
  7. +55
    -0
      PGO/pgadmin-statefulset.yaml
  8. +13
    -0
      PGO/postgres-configmap.yaml
  9. +31
    -0
      PGO/postgres-deployment.yaml
  10. +13
    -0
      PGO/postgres-service.yaml
  11. +11
    -0
      PGO/pv-local-pg.yaml
  12. +11
    -0
      PGO/pv-local-pgadmin.yaml
  13. +14
    -0
      PGO/pvc-pg.yaml

+ 6
- 0
PGO/creaTodo.sh View File

@ -0,0 +1,6 @@
kubectl create -f pv-local-pg.yaml
kubectl create -f pvc-pg.yaml
kubectl create -f postgres-configmap.yaml
kubectl create -f postgres-deployment.yaml
kubectl create -f postgres-service.yaml
watch kubectl get all -n postgres

+ 1
- 0
PGO/entra.sh View File

@ -0,0 +1 @@
kubectl exec -ti deployment.apps/postgres -n postgres -- /bin/bash

+ 10
- 0
PGO/paraTodo.sh View File

@ -0,0 +1,10 @@
kubectl delete -f postgres-service.yaml
kubectl delete -f postgres-deployment.yaml
kubectl delete -f postgres-configmap.yaml
kubectl delete -f pvc-pg.yaml
kubectl delete -f pv-local-pg.yaml
kubectl delete -f pgadmin-configmap.yaml
kubectl delete -f pgadmin-secret.yaml
kubectl delete -f pgadmin-service.yaml
kubectl delete -f pgadmin-statefulset.yaml
kubectl delete -f pv-local-pgadmin.yaml

+ 20
- 0
PGO/pgadmin-configmap.yaml View File

@ -0,0 +1,20 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: pgadmin-config
namespace: postgres
data:
servers.json: |
{
"Servers": {
"1": {
"Name": "PostgreSQL DB",
"Group": "Servers",
"Port": 5432,
"Username": "postgres",
"Host": "postgres",
"SSLMode": "prefer",
"MaintenanceDB": "postgres"
}
}
}

+ 8
- 0
PGO/pgadmin-secret.yaml View File

@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: pgadmin
namespace: postgres
data:
pgadmin-password: UmV5LTExNzYK

+ 13
- 0
PGO/pgadmin-service.yaml View File

@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: pgadmin-service
namespace: postgres
spec:
ports:
- protocol: TCP
port: 80
targetPort: http
selector:
app: pgadmin
type: NodePort

+ 55
- 0
PGO/pgadmin-statefulset.yaml View File

@ -0,0 +1,55 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: pgadmin
namespace: postgres
spec:
serviceName: pgadmin-service
podManagementPolicy: Parallel
replicas: 1
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
app: pgadmin
template:
metadata:
labels:
app: pgadmin
spec:
terminationGracePeriodSeconds: 10
containers:
- name: pgadmin
image: dpage/pgadmin4:5.4
imagePullPolicy: Always
env:
- name: PGADMIN_DEFAULT_EMAIL
value: celestino.rey@gmail.com
- name: PGADMIN_DEFAULT_PASSWORD
valueFrom:
secretKeyRef:
name: pgadmin
key: pgadmin-password
ports:
- name: http
containerPort: 80
protocol: TCP
volumeMounts:
- name: pgadmin-config
mountPath: /pgadmin4/servers.json
subPath: servers.json
readOnly: true
- name: pgadmin-data
mountPath: /var/lib/pgadmin
volumes:
- name: pgadmin-config
configMap:
name: pgadmin-config
volumeClaimTemplates:
- metadata:
name: pgadmin-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 3Gi

+ 13
- 0
PGO/postgres-configmap.yaml View File

@ -0,0 +1,13 @@
# Create ConfigMap postgres-secret for the postgres app
# Define default database name, user, and password
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-secret
namespace: postgres
labels:
app: postgres
data:
POSTGRES_DB: productos
POSTGRES_USER: creylopez
POSTGRES_PASSWORD: Rey-1176

+ 31
- 0
PGO/postgres-deployment.yaml View File

@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment # Create a deployment
metadata:
name: postgres # Set the name of the deployment
namespace: postgres
spec:
replicas: 1 # 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: pg-pv-claim

+ 13
- 0
PGO/postgres-service.yaml View File

@ -0,0 +1,13 @@
apiVersion: v1
kind: Service # Create service
metadata:
name: postgres # Sets the service name
namespace: postgres
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

+ 11
- 0
PGO/pv-local-pg.yaml View File

@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: pg-data
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/cluster/postgres/postgres-db"

+ 11
- 0
PGO/pv-local-pgadmin.yaml View File

@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: pgadmin-data
spec:
capacity:
storage: 3Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/cluster/postgres/pgadmin"

+ 14
- 0
PGO/pvc-pg.yaml View File

@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pg-pv-claim
namespace: postgres
labels:
app: postgres
spec:
accessModes:
- ReadWriteOnce
storageClassName: ""
resources:
requests:
storage: 10Gi

Loading…
Cancel
Save