diff --git a/PGO/creaTodo.sh b/PGO/creaTodo.sh new file mode 100755 index 00000000..09fc3198 --- /dev/null +++ b/PGO/creaTodo.sh @@ -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 diff --git a/PGO/entra.sh b/PGO/entra.sh new file mode 100755 index 00000000..87f15102 --- /dev/null +++ b/PGO/entra.sh @@ -0,0 +1 @@ +kubectl exec -ti deployment.apps/postgres -n postgres -- /bin/bash diff --git a/PGO/paraTodo.sh b/PGO/paraTodo.sh new file mode 100755 index 00000000..0a0d9a28 --- /dev/null +++ b/PGO/paraTodo.sh @@ -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 diff --git a/PGO/pgadmin-configmap.yaml b/PGO/pgadmin-configmap.yaml new file mode 100644 index 00000000..83eeba6d --- /dev/null +++ b/PGO/pgadmin-configmap.yaml @@ -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" + } + } + } diff --git a/PGO/pgadmin-secret.yaml b/PGO/pgadmin-secret.yaml new file mode 100644 index 00000000..96a37dba --- /dev/null +++ b/PGO/pgadmin-secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +type: Opaque +metadata: + name: pgadmin + namespace: postgres +data: + pgadmin-password: UmV5LTExNzYK diff --git a/PGO/pgadmin-service.yaml b/PGO/pgadmin-service.yaml new file mode 100644 index 00000000..4da00433 --- /dev/null +++ b/PGO/pgadmin-service.yaml @@ -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 diff --git a/PGO/pgadmin-statefulset.yaml b/PGO/pgadmin-statefulset.yaml new file mode 100644 index 00000000..78ba5dd4 --- /dev/null +++ b/PGO/pgadmin-statefulset.yaml @@ -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 diff --git a/PGO/postgres-configmap.yaml b/PGO/postgres-configmap.yaml new file mode 100644 index 00000000..2f3b1d13 --- /dev/null +++ b/PGO/postgres-configmap.yaml @@ -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 diff --git a/PGO/postgres-deployment.yaml b/PGO/postgres-deployment.yaml new file mode 100644 index 00000000..2b597f9e --- /dev/null +++ b/PGO/postgres-deployment.yaml @@ -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 diff --git a/PGO/postgres-service.yaml b/PGO/postgres-service.yaml new file mode 100644 index 00000000..baee280e --- /dev/null +++ b/PGO/postgres-service.yaml @@ -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 diff --git a/PGO/pv-local-pg.yaml b/PGO/pv-local-pg.yaml new file mode 100644 index 00000000..9009b42d --- /dev/null +++ b/PGO/pv-local-pg.yaml @@ -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" diff --git a/PGO/pv-local-pgadmin.yaml b/PGO/pv-local-pgadmin.yaml new file mode 100644 index 00000000..f24d0fba --- /dev/null +++ b/PGO/pv-local-pgadmin.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: pgadmin-data +spec: + capacity: + storage: 3Gi + accessModes: + - ReadWriteOnce + hostPath: + path: "/mnt/cluster/postgres/pgadmin" diff --git a/PGO/pvc-pg.yaml b/PGO/pvc-pg.yaml new file mode 100644 index 00000000..ef9710f5 --- /dev/null +++ b/PGO/pvc-pg.yaml @@ -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