> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# S3

> Conserva los archivos y el historial de los proyectos en un almacenamiento compatible con S3 en un despliegue de Kubernetes.

Los archivos de los proyectos y su historial los almacena el servicio **history-v1**, y los archivos de plantillas el servicio **filestore**, ambos dentro de cada pod de Ayakaleaf Pro. Por defecto escriben en el volumen de datos; con S3 escriben en buckets. Qué buckets y permisos se necesitan se describe en [S3](https://ayakaleaf-pro.mintlify.site/es/on-premises/configuration/overleaf-toolkit/s3.md).

| | |
| - | - |
| Servicios | history-v1 (archivos e historial de los proyectos), filestore (archivos de plantillas), en cada pod de Ayakaleaf Pro |
| Pod → S3 | el endpoint de S3, para cada archivo que se lee o escribe |
| Obligatorio | para [varias réplicas](https://ayakaleaf-pro.mintlify.site/es/on-premises/configuration/kubernetes/horizontal-scaling.md): sus volúmenes de datos no se comparten, los buckets sí |
| Tareas periódicas | ninguna |

> [!WARNING]
>
> Elige S3 antes de que los usuarios creen proyectos. Una instancia que ya guarda archivos en su volumen necesita primero la [migración a S3](https://ayakaleaf-pro.mintlify.site/es/on-premises/maintenance/s3-migration.md).

### Configuración

**1. Buckets y claves**

Crea los tres buckets `overleaf-template-files`, `overleaf-project-blobs` y `overleaf-chunks` y los dos usuarios restringidos con tu servicio S3 como se describe en [Configuración de S3](https://ayakaleaf-pro.mintlify.site/es/on-premises/configuration/overleaf-toolkit/s3.md#s3-setup), o ejecuta Garage en el clúster como se muestra más abajo. Guarda las cuatro claves en un Secret:

```bash wrap theme={null}
kubectl -n overleaf create secret generic overleaf-s3 \
  --from-literal=OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID=<filestore key> \
  --from-literal=OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY=<filestore secret> \
  --from-literal=OVERLEAF_HISTORY_S3_ACCESS_KEY_ID=<history key> \
  --from-literal=OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY=<history secret>
```

**2. ConfigMap**

```yaml title="30-config.yaml (additions)" wrap theme={null}
  OVERLEAF_FILESTORE_BACKEND: s3
  OVERLEAF_FILESTORE_TEMPLATE_FILES_BUCKET_NAME: overleaf-template-files
  OVERLEAF_FILESTORE_S3_REGION: eu-west-1
  OVERLEAF_HISTORY_BACKEND: s3
  OVERLEAF_HISTORY_PROJECT_BLOBS_BUCKET: overleaf-project-blobs
  OVERLEAF_HISTORY_CHUNKS_BUCKET: overleaf-chunks
  OVERLEAF_HISTORY_S3_REGION: eu-west-1
  # a self-hosted S3 service also needs its endpoint and path-style addressing
  # OVERLEAF_FILESTORE_S3_ENDPOINT: http://garage:3900
  # OVERLEAF_FILESTORE_S3_PATH_STYLE: "true"
  # OVERLEAF_HISTORY_S3_ENDPOINT: http://garage:3900
  # OVERLEAF_HISTORY_S3_PATH_STYLE: "true"
```

**3. Añadir el Secret al pod y reiniciar**

En el Deployment (o StatefulSet), añade el Secret junto a los demás:

```yaml theme={null}
          envFrom:
            - configMapRef: {name: overleaf-env}
            - secretRef: {name: overleaf-secrets}
            - secretRef: {name: overleaf-s3}
```

```bash theme={null}
kubectl apply -f 30-config.yaml -f 40-overleaf.yaml
kubectl -n overleaf rollout restart deployment/overleaf     # or statefulset/overleaf
```

### Garage en el clúster

Si no tienes un servicio S3, [Garage](https://garagehq.deuxfleurs.fr/) es un pequeño servidor S3 que se ejecuta en el clúster. La configuración de [Escalado horizontal](https://ayakaleaf-pro.mintlify.site/es/on-premises/configuration/kubernetes/horizontal-scaling.md) se probó con él. Los comandos siguientes generan las claves y crean ellos mismos el Secret `overleaf-s3`, así que úsalos en lugar del comando del Secret del paso 1.

> [!NOTE]
>
> MinIO, que se usa en el ejemplo de Overleaf, ya no publica imágenes de contenedor: `minio/minio` ha desaparecido de Docker Hub y de quay.io.

```yaml title="50-garage.yaml" wrap theme={null}
apiVersion: v1
kind: ConfigMap
metadata:
  name: garage-config
  namespace: overleaf
data:
  garage.toml: |
    metadata_dir = "/var/lib/garage/meta"
    data_dir = "/var/lib/garage/data"
    db_engine = "lmdb"
    replication_factor = 1
    rpc_bind_addr = "[::]:3901"
    rpc_public_addr = "127.0.0.1:3901"
    # rpc_secret and admin_token come from GARAGE_RPC_SECRET / GARAGE_ADMIN_TOKEN
    [s3_api]
    s3_region = "garage"          # Overleaf's OVERLEAF_*_S3_REGION must match
    api_bind_addr = "[::]:3900"
    [admin]
    api_bind_addr = "[::]:3903"
---
apiVersion: v1
kind: Service
metadata:
  name: garage
  namespace: overleaf
spec:
  selector:
    app: garage
  ports:
    - name: s3
      port: 3900
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: garage
  namespace: overleaf
spec:
  serviceName: garage
  replicas: 1
  selector:
    matchLabels:
      app: garage
  template:
    metadata:
      labels:
        app: garage
    spec:
      containers:
        - name: garage
          image: dxflrs/garage:v2.5.0
          env:
            - name: GARAGE_RPC_SECRET
              valueFrom: {secretKeyRef: {name: garage-secrets, key: rpc_secret}}
            - name: GARAGE_ADMIN_TOKEN
              valueFrom: {secretKeyRef: {name: garage-secrets, key: admin_token}}
          ports:
            - containerPort: 3900
          readinessProbe:
            tcpSocket:
              port: 3900
          resources:
            requests: {cpu: 50m, memory: 64Mi}
            limits: {memory: 512Mi}
          volumeMounts:
            - {name: config, mountPath: /etc/garage.toml, subPath: garage.toml}
            - {name: data, mountPath: /var/lib/garage}
      volumes:
        - name: config
          configMap:
            name: garage-config
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: [ReadWriteOnce]
        resources:
          requests:
            storage: 10Gi
```

Genera los secretos, inicia Garage y, después, crea el layout, los buckets y las dos claves restringidas. Los ID de clave de Garage son `GK` seguido de 24 caracteres hexadecimales, y los secretos tienen 64 caracteres hexadecimales:

```bash wrap theme={null}
kubectl -n overleaf create secret generic garage-secrets \
  --from-literal=rpc_secret="$(openssl rand -hex 32)" \
  --from-literal=admin_token="$(openssl rand -base64 32)"
kubectl -n overleaf create secret generic overleaf-s3 \
  --from-literal=OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID="GK$(openssl rand -hex 12)" \
  --from-literal=OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY="$(openssl rand -hex 32)" \
  --from-literal=OVERLEAF_HISTORY_S3_ACCESS_KEY_ID="GK$(openssl rand -hex 12)" \
  --from-literal=OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY="$(openssl rand -hex 32)"
kubectl apply -f 50-garage.yaml
kubectl -n overleaf rollout status statefulset/garage

g() { kubectl -n overleaf exec garage-0 -- /garage "$@"; }
s() { kubectl -n overleaf get secret overleaf-s3 -o jsonpath="{.data.$1}" | base64 -d; }
g layout assign -z dc1 -c 8G "$(g status 2>/dev/null | awk '/^[0-9a-f]{16}/{print $1; exit}')"
g layout apply --version 1
for b in overleaf-template-files overleaf-project-blobs overleaf-chunks; do g bucket create "$b"; done
g key import --yes -n overleaf-filestore "$(s OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID)" "$(s OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY)"
g key import --yes -n overleaf-history "$(s OVERLEAF_HISTORY_S3_ACCESS_KEY_ID)" "$(s OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY)"
g bucket allow --read --write overleaf-template-files --key overleaf-filestore
g bucket allow --read overleaf-project-blobs --key overleaf-filestore
g bucket allow --read --write overleaf-project-blobs --key overleaf-history
g bucket allow --read --write overleaf-chunks --key overleaf-history
```

Los permisos coinciden con las políticas de [S3](https://ayakaleaf-pro.mintlify.site/es/on-premises/configuration/overleaf-toolkit/s3.md#access-policies). Garage comprueba la región: aquí es `garage`, y `OVERLEAF_*_S3_REGION` debe ser la misma.

Con Garage, establece en el ConfigMap el endpoint, `PATH_STYLE: "true"` y la región `garage` para ambos servicios, como en el `60-config.yaml` de [Escalado horizontal](https://ayakaleaf-pro.mintlify.site/es/on-premises/configuration/kubernetes/horizontal-scaling.md).

### Varias réplicas

Todas las réplicas deben usar los mismos buckets y claves. Haz copias de seguridad de los buckets con las herramientas de tu proveedor de S3; así, los discos propios de las réplicas no contienen datos que necesiten copia de seguridad.

### Probado en Kubernetes

En Kubernetes 1.37 con tres réplicas y Garage como se indica arriba, se superaron todas las pruebas de extremo a extremo de estas páginas que crean proyectos, suben archivos, usan el historial o publican plantillas, y después los buckets `overleaf-project-blobs`, `overleaf-chunks` y `overleaf-template-files` contenían los objetos, mientras que el `/var/lib/overleaf/data/history` propio de las réplicas permaneció vacío.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.