diff --git a/Libros/K8S/Makefile b/Libros/K8S/Makefile index 505a3cf..05a497e 100644 --- a/Libros/K8S/Makefile +++ b/Libros/K8S/Makefile @@ -1,5 +1,5 @@ export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':') -export IMG_VERSION = 1.30 +export IMG_VERSION = 1.34 export IMG_NGINX_VERSION = 1.17 # limpia todo @@ -9,6 +9,8 @@ imagen: cd ../; make install: + -kubectl create -f namespace.yaml + -kubectl create -f reg-secret.yaml -kubectl create -f env-prod-configmap.yaml -kubectl create -f env-prod-db-configmap.yaml @@ -39,6 +41,8 @@ clean: -kubectl delete -f static-volume-persistentvolumeclaim.yaml -kubectl delete -f libros-prod-persistentvolumeclaim.yaml -kubectl delete -f pv-local-libros.yaml + -kubectl delete -f reg-secret.yaml + -kubectl delete -f namespace.yaml nginx: cd ../nginx; make diff --git a/Libros/K8S/db-deployment.yaml b/Libros/K8S/db-deployment.yaml index 016d29c..cf4ddf1 100644 --- a/Libros/K8S/db-deployment.yaml +++ b/Libros/K8S/db-deployment.yaml @@ -7,6 +7,7 @@ metadata: labels: io.kompose.service: db name: db + namespace: libros spec: replicas: 1 selector: diff --git a/Libros/K8S/db-service.yaml b/Libros/K8S/db-service.yaml index d12661d..be32ea9 100644 --- a/Libros/K8S/db-service.yaml +++ b/Libros/K8S/db-service.yaml @@ -7,6 +7,7 @@ metadata: labels: io.kompose.service: db name: db + namespace: libros spec: ports: - name: "5432" diff --git a/Libros/K8S/entra.sh b/Libros/K8S/entra.sh index 308aa14..6ee7d2f 100644 --- a/Libros/K8S/entra.sh +++ b/Libros/K8S/entra.sh @@ -1 +1 @@ -kubectl exec -ti deployment.apps/libros -- /bin/bash +kubectl -n libros exec -ti deployment.apps/libros -- /bin/bash diff --git a/Libros/K8S/env-prod-configmap.yaml b/Libros/K8S/env-prod-configmap.yaml index 130529a..986d8d3 100644 --- a/Libros/K8S/env-prod-configmap.yaml +++ b/Libros/K8S/env-prod-configmap.yaml @@ -1,7 +1,8 @@ apiVersion: v1 data: DEBUG: "0" - DJANGO_ALLOWED_HOSTS: libros.reymota.es k8s-server localhost 127.0.0.1 [::1] + DJANGO_ALLOWED_HOSTS: "libros.reymota.es k8s-server localhost 127.0.0.1 [::1]" + CSRF_TRUSTED_ORIGINS: "https://libros.reymota.es" SECRET_KEY: change_me SQL_DATABASE: libros SQL_ENGINE: django.db.backends.postgresql @@ -15,3 +16,4 @@ metadata: labels: io.kompose.service: web-env-prod name: env-prod + namespace: libros diff --git a/Libros/K8S/env-prod-db-configmap.yaml b/Libros/K8S/env-prod-db-configmap.yaml index 93f9dc8..90e2104 100644 --- a/Libros/K8S/env-prod-db-configmap.yaml +++ b/Libros/K8S/env-prod-db-configmap.yaml @@ -8,3 +8,4 @@ metadata: labels: io.kompose.service: db-env-prod-db name: env-prod-db + namespace: libros diff --git a/Libros/K8S/libros-deployment.yaml b/Libros/K8S/libros-deployment.yaml index 741897a..b9baa69 100644 --- a/Libros/K8S/libros-deployment.yaml +++ b/Libros/K8S/libros-deployment.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: Service metadata: name: libros + namespace: libros spec: ports: - name: "8000" @@ -14,6 +15,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: libros + namespace: libros labels: app: libros spec: @@ -51,6 +53,11 @@ spec: configMapKeyRef: key: DJANGO_ALLOWED_HOSTS name: env-prod + - name: CSRF_TRUSTED_ORIGINS + valueFrom: + configMapKeyRef: + key: CSRF_TRUSTED_ORIGINS + name: env-prod - name: SECRET_KEY valueFrom: configMapKeyRef: diff --git a/Libros/K8S/libros-prod-persistentvolumeclaim.yaml b/Libros/K8S/libros-prod-persistentvolumeclaim.yaml index c67cd5e..ee1e017 100644 --- a/Libros/K8S/libros-prod-persistentvolumeclaim.yaml +++ b/Libros/K8S/libros-prod-persistentvolumeclaim.yaml @@ -5,6 +5,7 @@ metadata: labels: io.kompose.service: libros-media name: libros-media + namespace: libros spec: accessModes: - ReadWriteOnce @@ -20,6 +21,7 @@ metadata: labels: io.kompose.service: libros-migrations name: libros-migrations + namespace: libros spec: accessModes: - ReadWriteOnce diff --git a/Libros/K8S/namespace.yaml b/Libros/K8S/namespace.yaml new file mode 100644 index 0000000..5f0c693 --- /dev/null +++ b/Libros/K8S/namespace.yaml @@ -0,0 +1,7 @@ +################################################### +# Namespace Libros +################################################### +apiVersion: v1 +kind: Namespace +metadata: + name: libros diff --git a/Libros/K8S/nginx-deployment.yaml b/Libros/K8S/nginx-deployment.yaml index ba52d20..b24df16 100644 --- a/Libros/K8S/nginx-deployment.yaml +++ b/Libros/K8S/nginx-deployment.yaml @@ -7,6 +7,7 @@ metadata: labels: io.kompose.service: nginx name: nginx + namespace: libros spec: replicas: 1 selector: @@ -23,7 +24,7 @@ spec: io.kompose.service: nginx spec: containers: - - image: registry.reymota.es/nginx-$ARQUITECTURA:$IMG_NGINX_VERSION + - image: registry.reymota.es/nginx-libros-$ARQUITECTURA:$IMG_NGINX_VERSION name: nginx ports: - containerPort: 80 diff --git a/Libros/K8S/nginx-service.yaml b/Libros/K8S/nginx-service.yaml index 3e15c36..e5d563f 100644 --- a/Libros/K8S/nginx-service.yaml +++ b/Libros/K8S/nginx-service.yaml @@ -7,6 +7,7 @@ metadata: labels: io.kompose.service: nginx name: nginx + namespace: libros spec: type: NodePort ports: diff --git a/Libros/K8S/postgres-data-persistentvolumeclaim.yaml b/Libros/K8S/postgres-data-persistentvolumeclaim.yaml index 27c2094..5c04801 100644 --- a/Libros/K8S/postgres-data-persistentvolumeclaim.yaml +++ b/Libros/K8S/postgres-data-persistentvolumeclaim.yaml @@ -4,6 +4,7 @@ metadata: labels: io.kompose.service: postgres-data name: postgres-data + namespace: libros spec: accessModes: - ReadWriteOnce diff --git a/Libros/K8S/pv-local-libros.yaml b/Libros/K8S/pv-local-libros.yaml index 899d282..b92e7fa 100644 --- a/Libros/K8S/pv-local-libros.yaml +++ b/Libros/K8S/pv-local-libros.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: PersistentVolume metadata: name: libros-media-folder + namespace: libros labels: app: libros spec: @@ -16,6 +17,7 @@ apiVersion: v1 kind: PersistentVolume metadata: name: libros-migrations-folder + namespace: libros labels: app: libros spec: @@ -30,6 +32,7 @@ apiVersion: v1 kind: PersistentVolume metadata: name: libros-static-folder + namespace: libros labels: app: libros spec: @@ -44,6 +47,7 @@ apiVersion: v1 kind: PersistentVolume metadata: name: libros-pg-folder + namespace: libros labels: app: libros spec: @@ -52,4 +56,4 @@ spec: accessModes: - ReadWriteOnce hostPath: - path: "/mnt/Externo/libros/pg" \ No newline at end of file + path: "/mnt/Externo/libros/pg" diff --git a/Libros/K8S/reg-secret.yaml b/Libros/K8S/reg-secret.yaml new file mode 100644 index 0000000..fb66841 --- /dev/null +++ b/Libros/K8S/reg-secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: myregistrykey + namespace: libros +data: + .dockerconfigjson: ewoJImF1dGhzIjogewoJCSJyZWdpc3RyeS5yZXltb3RhLmVzIjogewoJCQkiYXV0aCI6ICJZM0psZVd4dmNHVjZPbEpsZVMweE1UYzIiCgkJfQoJfQp9 +type: kubernetes.io/dockerconfigjson diff --git a/Libros/K8S/static-volume-persistentvolumeclaim.yaml b/Libros/K8S/static-volume-persistentvolumeclaim.yaml index 555a643..e2330bb 100644 --- a/Libros/K8S/static-volume-persistentvolumeclaim.yaml +++ b/Libros/K8S/static-volume-persistentvolumeclaim.yaml @@ -4,6 +4,7 @@ metadata: labels: io.kompose.service: static-volume name: static-volume + namespace: libros spec: accessModes: - ReadWriteOnce diff --git a/Libros/biblioteca/biblioteca/settings.py b/Libros/biblioteca/biblioteca/settings.py index 776e14a..b027377 100644 --- a/Libros/biblioteca/biblioteca/settings.py +++ b/Libros/biblioteca/biblioteca/settings.py @@ -31,6 +31,8 @@ DEBUG = bool(os.environ.get("DEBUG", default=0)) ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ") +print("HOSTS PERMITIDOS: ", ALLOWED_HOSTS) + # Application definition INSTALLED_APPS = [ @@ -161,4 +163,4 @@ LOGGING = { }, } -CSRF_TRUSTED_ORIGINS = ["http://localhost:30443"] +CSRF_TRUSTED_ORIGINS = os.environ.get("CSRF_TRUSTED_ORIGINS").split(" ") diff --git a/Libros/nginx/Makefile b/Libros/nginx/Makefile index 6c52e2c..c472d52 100644 --- a/Libros/nginx/Makefile +++ b/Libros/nginx/Makefile @@ -2,7 +2,7 @@ install: echo "Creando imagen con version ${IMG_NGINX_VERSION} para la arquitectura ${ARQUITECTURA}" - docker build --no-cache -t registry.reymota.es/nginx-${ARQUITECTURA}:${IMG_NGINX_VERSION} . - docker push registry.reymota.es/nginx-${ARQUITECTURA}:${IMG_NGINX_VERSION} + docker build --no-cache -t registry.reymota.es/nginx-libros-${ARQUITECTURA}:${IMG_NGINX_VERSION} . + docker push registry.reymota.es/nginx-libros-${ARQUITECTURA}:${IMG_NGINX_VERSION}