From d1c2339b8a2ef5c3d44e88b6bcc119a984aeca34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20J=2E=20Salda=C3=B1a?= Date: Thu, 28 Dec 2023 23:58:57 +0100 Subject: [PATCH] 1.0.0 --- README.md | 93 +++++++++++++++++++++++++++++++ app/ghost/configmap.yaml | 14 +++++ app/ghost/deployment.yaml | 84 ++++++++++++++++++++++++++++ app/ghost/ingress-questverse.yaml | 18 ++++++ app/ghost/ingress.yaml | 25 +++++++++ app/ghost/pvc.yaml | 12 ++++ app/ghost/secrets.yaml | 9 +++ app/ghost/service.yaml | 15 +++++ app/mysql/deployment.yaml | 63 +++++++++++++++++++++ app/mysql/pvc.yaml | 12 ++++ app/mysql/service.yaml | 15 +++++ base/namespace.yaml | 4 ++ base/secrets.yaml | 10 ++++ kustomization.yaml | 20 +++++++ 14 files changed, 394 insertions(+) create mode 100644 README.md create mode 100644 app/ghost/configmap.yaml create mode 100644 app/ghost/deployment.yaml create mode 100644 app/ghost/ingress-questverse.yaml create mode 100644 app/ghost/ingress.yaml create mode 100644 app/ghost/pvc.yaml create mode 100644 app/ghost/secrets.yaml create mode 100644 app/ghost/service.yaml create mode 100644 app/mysql/deployment.yaml create mode 100644 app/mysql/pvc.yaml create mode 100644 app/mysql/service.yaml create mode 100644 base/namespace.yaml create mode 100644 base/secrets.yaml create mode 100644 kustomization.yaml diff --git a/README.md b/README.md new file mode 100644 index 0000000..d8d588a --- /dev/null +++ b/README.md @@ -0,0 +1,93 @@ +# Blog de Ghost en Kubernetes + +Este repositorio contiene manifiestos de Kubernetes para implementar un blog de Ghost junto con una base de datos MySQL. La configuración está organizada utilizando Kustomize para una mejor gestión y personalización. + +## Contenido + +- **base/namespace.yaml**: Define el espacio de nombres de Kubernetes para la implementación de Ghost. +- **base/secrets.yaml**: Contiene secretos genéricos utilizados tanto por Ghost como por MySQL. +- **app/ghost/deployment.yaml**: Describe la implementación de la aplicación Ghost. +- **app/ghost/configmap.yaml**: ConfigMap para la configuración de la aplicación Ghost. +- **app/ghost/secrets.yaml**: Secretos específicos de la aplicación Ghost. +- **app/ghost/service.yaml**: Configuración del servicio para la aplicación Ghost. +- **app/ghost/pvc.yaml**: Reclamación de volumen persistente para el almacenamiento de Ghost. +- **app/ghost/ingress.yaml**: Configuración de Ingress para acceder al blog de Ghost. +- **app/mysql/deployment.yaml**: Describe la implementación de la base de datos MySQL. +- **app/mysql/service.yaml**: Configuración del servicio para la base de datos MySQL. +- **app/mysql/pvc.yaml**: Reclamación de volumen persistente para el almacenamiento de MySQL. + +## Configuración de la Implementación de Ghost + +### Implementación + +- **Replicas**: 1 +- **Estrategia**: Recrear +- **Imagen del Contenedor**: ghost:alpine +- **Recursos**: + - Solicitudes: CPU=250m, Memoria=180Mi + - Límites: CPU=350m, Memoria=300Mi +- **Puertos**: ContainerPort=2368 + +### Sondas + +- **Sonda de Disponibilidad**: Verifica si Ghost está listo para aceptar tráfico. +- **Sonda de Supervivencia**: Verifica si Ghost está vivo y saludable. + +### Variables de Entorno + +- Ghost depende de variables de entorno para la configuración, incluyendo detalles de conexión a la base de datos y configuración de Mailgun. + +## Configuración de Ingress + +- **Hosts**: questverse.blog, www.questverse.blog +- **TLS**: Utiliza el secreto questverse-com-tls para HTTPS. +- **Anotaciones**: + - Redirección de from-to-www. + - Varios ajustes de NGINX para proxy, almacenamiento en búfer, caché y brotli. + +## Configuración de Ghost + +### ConfigMap + +- ConfigMap llamado `ghost-configmap` con pares clave-valor para la configuración de Ghost, incluyendo URL, conexión a la base de datos y configuración de correo. + +### Almacenamiento Persistente + +- Ghost utiliza una Reclamación de Volumen Persistente (PVC) llamada `ghost` con una solicitud de almacenamiento de 15Gi y la clase de almacenamiento `do-block-storage`. + +### Secretos + +- Secretos llamados `ghost-secrets` para datos sensibles, incluyendo credenciales de Mailgun. + +### Servicio + +- Servicio de Kubernetes llamado `ghost` con asignación de puertos (80:ghost). + +## Configuración de la Implementación de MySQL + +### Implementación + +- **Replicas**: 1 +- **Estrategia**: Recrear +- **Imagen del Contenedor**: mysql:8.0.33 +- **Recursos**: + - Solicitudes: CPU=200m, Memoria=450Mi + - Límites: CPU=400m, Memoria=550Mi +- **Puertos**: ContainerPort=3306 + +### Sondas + +- **Sonda de Disponibilidad**: Verifica si MySQL está listo para aceptar tráfico. +- **Sonda de Supervivencia**: Verifica si MySQL está vivo y saludable. + +### Variables de Entorno + +- La configuración de MySQL incluye la contraseña de root, el nombre de la base de datos y depende de secretos. + +### Almacenamiento Persistente + +- MySQL utiliza una Reclamación de Volumen Persistente (PVC) llamada `mysql` con una solicitud de almacenamiento de 5Gi y la clase de almacenamiento `do-block-storage`. + +### Servicio + +- Servicio de Kubernetes llamado `mysql` con clusterIP configurado como None para un servicio sin cabeza. \ No newline at end of file diff --git a/app/ghost/configmap.yaml b/app/ghost/configmap.yaml new file mode 100644 index 0000000..b8e4d2c --- /dev/null +++ b/app/ghost/configmap.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: ghost-configmap + namespace: ghost +data: + url: "https://questverse.blog" + database__connection__host: "mysql" + database__client: "mysql" + mail__transport: "SMTP" + mail__options__service: "Mailgun" + mail__options__host: "smtp.eu.mailgun.org" + mail__options__port: "465" + mail__options__secure: "true" \ No newline at end of file diff --git a/app/ghost/deployment.yaml b/app/ghost/deployment.yaml new file mode 100644 index 0000000..6f5479b --- /dev/null +++ b/app/ghost/deployment.yaml @@ -0,0 +1,84 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: ghost + name: ghost + labels: + app: ghost +spec: + selector: + matchLabels: + app: ghost + replicas: 1 + strategy: + type: Recreate + template: + metadata: + labels: + app: ghost + spec: + containers: + - name: ghost + image: ghost:alpine + imagePullPolicy: Always + resources: + requests: + cpu: 250m + memory: 180Mi + limits: + cpu: 350m + memory: 300Mi + ports: + - containerPort: 2368 + name: ghost + readinessProbe: + tcpSocket: + port: ghost + initialDelaySeconds: 10 + periodSeconds: 10 + livenessProbe: + tcpSocket: + port: ghost + initialDelaySeconds: 30 + periodSeconds: 30 + env: + - name: database__connection__database + valueFrom: + secretKeyRef: + name: mysql-secrets + key: db-name + optional: false + - name: database__connection__user + valueFrom: + secretKeyRef: + name: mysql-secrets + key: db-user + optional: false + - name: database__connection__password + valueFrom: + secretKeyRef: + name: mysql-secrets + key: db-pass + optional: false + - name: mail__options__auth__user + valueFrom: + secretKeyRef: + name: ghost-secrets + key: mailgun_username + optional: false + - name: mail__options__auth__pass + valueFrom: + secretKeyRef: + name: ghost-secrets + key: mailgun_password + optional: false + envFrom: + - configMapRef: + name: ghost-configmap + volumeMounts: + - name: ghost-persistent-storage + mountPath: /var/lib/ghost/content + volumes: + - name: ghost-persistent-storage + persistentVolumeClaim: + claimName: ghost \ No newline at end of file diff --git a/app/ghost/ingress-questverse.yaml b/app/ghost/ingress-questverse.yaml new file mode 100644 index 0000000..edee5c2 --- /dev/null +++ b/app/ghost/ingress-questverse.yaml @@ -0,0 +1,18 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ghost + namespace: ghost +spec: + rules: + - host: questverse.blog + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: ghost + port: + number: 80 + ingressClassName: nginx diff --git a/app/ghost/ingress.yaml b/app/ghost/ingress.yaml new file mode 100644 index 0000000..a14c2f0 --- /dev/null +++ b/app/ghost/ingress.yaml @@ -0,0 +1,25 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ghost + namespace: ghost + annotations: + nginx.ingress.kubernetes.io/from-to-www-redirect: "true" +spec: + ingressClassName: nginx + tls: + - hosts: + - questverse.blog + - www.questverse.blog + secretName: questverse-com-tls + rules: + - host: questverse.blog + http: + paths: + - backend: + service: + name: ghost + port: + name: http + path: / + pathType: Prefix diff --git a/app/ghost/pvc.yaml b/app/ghost/pvc.yaml new file mode 100644 index 0000000..5b62175 --- /dev/null +++ b/app/ghost/pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: ghost + namespace: ghost +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 15Gi + storageClassName: do-block-storage \ No newline at end of file diff --git a/app/ghost/secrets.yaml b/app/ghost/secrets.yaml new file mode 100644 index 0000000..ca7476e --- /dev/null +++ b/app/ghost/secrets.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: ghost-secrets + namespace: ghost +type: Opaque +data: + mailgun_username: test + mailgun_password: test diff --git a/app/ghost/service.yaml b/app/ghost/service.yaml new file mode 100644 index 0000000..19636b1 --- /dev/null +++ b/app/ghost/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: ghost + namespace: ghost + labels: + app: ghost +spec: + selector: + app: ghost + ports: + - protocol: TCP + port: 80 + targetPort: ghost + name: http diff --git a/app/mysql/deployment.yaml b/app/mysql/deployment.yaml new file mode 100644 index 0000000..c9d9233 --- /dev/null +++ b/app/mysql/deployment.yaml @@ -0,0 +1,63 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mysql + namespace: ghost + labels: + app: mysql +spec: + selector: + matchLabels: + app: mysql + tier: mysql + replicas: 1 + strategy: + type: Recreate + template: + metadata: + labels: + app: mysql + tier: mysql + spec: + containers: + - name: mysql + image: mysql:8.0.33 + imagePullPolicy: Always + resources: + requests: + cpu: 200m + memory: 450Mi + limits: + cpu: 400m + memory: 550Mi + ports: + - containerPort: 3306 + name: mysql + readinessProbe: + tcpSocket: + port: mysql + initialDelaySeconds: 10 + periodSeconds: 10 + livenessProbe: + tcpSocket: + port: mysql + initialDelaySeconds: 30 + periodSeconds: 30 + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-secrets + key: db-pass + - name: MYSQL_DATABASE + valueFrom: + secretKeyRef: + name: mysql-secrets + key: db-name + volumeMounts: + - name: mysql-persistent-storage + mountPath: /var/lib/mysql + volumes: + - name: mysql-persistent-storage + persistentVolumeClaim: + claimName: mysql \ No newline at end of file diff --git a/app/mysql/pvc.yaml b/app/mysql/pvc.yaml new file mode 100644 index 0000000..43b6afe --- /dev/null +++ b/app/mysql/pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: mysql + namespace: ghost +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi + storageClassName: do-block-storage \ No newline at end of file diff --git a/app/mysql/service.yaml b/app/mysql/service.yaml new file mode 100644 index 0000000..41b8107 --- /dev/null +++ b/app/mysql/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: mysql + namespace: ghost + labels: + app: mysql +spec: + selector: + app: mysql + ports: + - port: 3306 + targetPort: 3306 + name: mysql + clusterIP: None diff --git a/base/namespace.yaml b/base/namespace.yaml new file mode 100644 index 0000000..9cf06a2 --- /dev/null +++ b/base/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: ghost \ No newline at end of file diff --git a/base/secrets.yaml b/base/secrets.yaml new file mode 100644 index 0000000..68dc658 --- /dev/null +++ b/base/secrets.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: mysql-secrets + namespace: ghost +type: Opaque +data: + db-name: Z2hvc3Q= + db-user: cm9vdA== + db-pass: Z29saWF0 \ No newline at end of file diff --git a/kustomization.yaml b/kustomization.yaml new file mode 100644 index 0000000..478eca3 --- /dev/null +++ b/kustomization.yaml @@ -0,0 +1,20 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +generatorOptions: + disableNameSuffixHash: true + labels: + app: ghost + +resources: + - ./base/namespace.yaml + - ./base/secrets.yaml + - ./app/ghost/deployment.yaml + - ./app/ghost/configmap.yaml + - ./app/ghost/secrets.yaml + - ./app/ghost/service.yaml + - ./app/ghost/pvc.yaml + - ./app/ghost/ingress.yaml + - ./app/mysql/deployment.yaml + - ./app/mysql/service.yaml + - ./app/mysql/pvc.yaml \ No newline at end of file