From e5362bed87d296dd74ff87788464a734fe701e61 Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Fri, 28 Feb 2025 12:57:13 +0100 Subject: [PATCH] first commit --- README.md | 87 ++++++++++++++++++++++++++ hello-template.yaml | 95 ++++++++++++++++++++++++++++ init-mongo.sh | 20 ++++++ jugar.yaml | 98 +++++++++++++++++++++++++++++ lanza.sh | 1 + mongodb-deployment.yaml | 80 ++++++++++++++++++++++++ unifi-network-application.yaml | 110 +++++++++++++++++++++++++++++++++ 7 files changed, 491 insertions(+) create mode 100644 README.md create mode 100644 hello-template.yaml create mode 100644 init-mongo.sh create mode 100644 jugar.yaml create mode 100644 lanza.sh create mode 100644 mongodb-deployment.yaml create mode 100644 unifi-network-application.yaml diff --git a/README.md b/README.md new file mode 100644 index 0000000..566e180 --- /dev/null +++ b/README.md @@ -0,0 +1,87 @@ +# Versión para openshift + +## Instalación + +### Crear un proyecto + + oc new-project unifi-server + +#### Permitir que los pods puedan funcionar como root + + oc adm policy add-scc-to-user anyuid -z default + +### Añadir la app desde gitea + + oc new-app + +Tal y como está la estructura de directorios, deberia detectar automáticamente una compilación Python + +## Asignación de los volúmenes +### Si la pvc no está creada + + oc set volume deployment.apps/jugaralpadel --add -t pvc --claim-size=300M --name=jugaralpadel-eventos-migrations --claim-name='jugaralpadel-eventos-migrations' --mount-path='/app/eventos/migrations' --claim-class='lvms-vg1' + + oc set volume deployment.apps/jugaralpadel --add -t pvc --claim-size=300M --name=jugaralpadel-media --claim-name='jugaralpadel-media' --mount-path='/app/mediafiles' --claim-class='lvms-vg1' + + oc set volume deployment.apps/jugaralpadel --add -t pvc --claim-size=300M --name=reymota-reymotausers-migrations --claim-name='reymota-reymotausers-migrations' --mount-path='/app/reymotausers/migrations' --claim-class='lvms-vg1' + + oc set volume deployment.apps/jugaralpadel --add -t pvc --claim-size=50G --name=static-volume --claim-name='static-volume' --mount-path='/app/staticfiles' --claim-class='lvms-vg1' + + +### Si la pvc ya está creada + + oc set volume deployment.apps/jugaralpadel --add -t pvc --name=jugaralpadel-eventos-migrations --claim-name='jugaralpadel-eventos-migrations' --mount-path='/app/eventos/migrations' + + oc set volume deployment.apps/jugaralpadel --add -t pvc --name=jugaralpadel-media --claim-name='jugaralpadel-media' --mount-path='/app/mediafiles' + + oc set volume deployment.apps/jugaralpadel --add -t pvc --name=reymota-reymotausers-migrations --claim-name='reymota-reymotausers-migrations' --mount-path='/app/reymotausers/migrations' + + oc set volume deployment.apps/jugaralpadel --add -t pvc --name=static-volume --claim-name='static-volume' --mount-path='/app/staticfiles' + + +## Exponer el servicio + oc expose service/jugaralpadel + +### postgresql +Los ficheros yaml están en el directorio Yamls. + +Se crea el deployment y el servicio con la shell creaDB.sh +Se borran con borraDB.sh + +Hay que tener en cuenta que la PVC *no* se crea en estas shells. Hay que crearla a mano. Esto se hace para no perder los datos. + + +## Cosas a hacer la primera vez +Desde dentro de la shell del pod + + python manage.py createsuperuser + + python manage.py makemigrations + + python manage.py migrate + +# Cambiar la secuencia de los id + +ALTER SEQUENCE tablename_id_seq RESTART WITH nn; + +esto se hace cuando restauro un volcado de la bd sobre una instalación nueva. Si hay índices ya creados, hay que reinciar a partir del último. + +# GIT + +avoid credentials: + + git config credential.helper store + +después se hace un pull o push o lo que sea que te pida el usuario y password, los metes y ya la próxima no hace falta + +## PVC y paths + + volumeMounts: + - mountPath: /app/mediafiles + name: jugaralpadel-media + - mountPath: /app/eventos/migrations + name: jugaralpadel-eventos-migrations + - mountPath: /app/reymotausers/migrations + name: jugaralpadel-reymotausers-migrations + - mountPath: /app/staticfiles + name: static-volume diff --git a/hello-template.yaml b/hello-template.yaml new file mode 100644 index 0000000..172d06f --- /dev/null +++ b/hello-template.yaml @@ -0,0 +1,95 @@ +--- +apiVersion: v1 +kind: Template +labels: + template: hello +message: Una nueva app hello ha sido creada" +metadata: + annotations: + description: This is an example of application template in OpenShift 3 + iconClass: default + tags: hello, world + name: hello-world-template + namespace: unifi-server +objects: +- kind: Service + metadata: + name: hello-world-service + spec: + ports: + - name: http + nodePort: 0 + port: ${{SERVICE_PORT}} + protocol: TCP + targetPort: ${{INTERNAL_PORT}} + selector: + name: hello +- kind: Route + metadata: + labels: + name: hello + name: hello-world-route + spec: + host: ${APPLICATION_DOMAIN} + tls: + termination: edge + to: + kind: Service + name: hello-world-service +- kind: ReplicationController + metadata: + name: hello-world-rc + spec: + replicas: 1 + selector: + name: hello + template: + metadata: + creationTimestamp: null + labels: + name: hello + spec: + containers: + - env: + - name: MESSAGE + value: ${GREATING_MESSAGE} + image: docker.io/kalise/nodejs-web-app:latest + imagePullPolicy: IfNotPresent + name: hello + ports: + - containerPort: ${{INTERNAL_PORT}} + name: http + protocol: TCP + resources: + limits: + cpu: 25m + memory: 128Mi + securityContext: + privileged: false + livenessProbe: + tcpSocket: + port: ${{INTERNAL_PORT}} + timeoutSeconds: 1 + initialDelaySeconds: 30 + terminationMessagePath: /dev/termination-log + dnsPolicy: ClusterFirst + nodeSelector: + region: primary + restartPolicy: Always + serviceAccount: "" +parameters: +- description: The exposed hostname that will route to the Hello World service + name: APPLICATION_DOMAIN + value: "hello-world.cloud.openshift.b-cloud.it" + required: true +- description: The internal port used by the pods + name: INTERNAL_PORT + value: "8080" + required: true +- description: The port exposed by the service + name: SERVICE_PORT + value: "9000" + required: true +- description: Greating message + name: GREATING_MESSAGE + value: "Hello OpenShift" diff --git a/init-mongo.sh b/init-mongo.sh new file mode 100644 index 0000000..cd7082d --- /dev/null +++ b/init-mongo.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if which mongosh > /dev/null 2>&1; then + mongo_init_bin='mongosh' +else + mongo_init_bin='mongo' +fi +"${mongo_init_bin}" <