> ## 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.

# 5. 部署 Ayakaleaf Pro

> 部署 Ayakaleaf Pro pod、其数据卷以及一个 NodePort Service。

```yaml title="40-overleaf.yaml" wrap theme={null}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: overleaf-data
  namespace: overleaf
spec:
  accessModes: [ReadWriteOnce]
  resources:
    requests:
      storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: overleaf
  namespace: overleaf
spec:
  replicas: 1
  strategy:
    type: Recreate          # one pod owns the data volume; never run two at once
  selector:
    matchLabels:
      app: overleaf
  template:
    metadata:
      labels:
        app: overleaf
    spec:
      terminationGracePeriodSeconds: 60   # time to flush pending edits, like the Toolkit
      # Keep the environment to what the ConfigMap and Secret set: no REDIS_PORT=tcp://... and the like
      enableServiceLinks: false
      containers:
        - name: sharelatex
          image: ghcr.io/ayaka-notes/overleaf-pro:6.3.2
          envFrom:
            - configMapRef:
                name: overleaf-env
            - secretRef:
                name: overleaf-secrets
          ports:
            - containerPort: 80
          readinessProbe:
            httpGet:
              path: /status
              port: 80
            periodSeconds: 10
          resources:
            requests:
              cpu: 500m
              memory: 1536Mi
            limits:
              memory: 3Gi
          volumeMounts:
            - name: data
              mountPath: /var/lib/overleaf
            - name: compiles
              mountPath: /var/lib/overleaf/data/compiles
            - name: output
              mountPath: /var/lib/overleaf/data/output
            - name: cache
              mountPath: /var/lib/overleaf/data/cache
            - name: docker-sock
              mountPath: /var/run/docker.sock
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: overleaf-data
        # Compile scratch space on the node; same paths as SANDBOXED_COMPILES_HOST_DIR_*
        - name: compiles
          hostPath:
            path: /srv/overleaf/compiles
            type: DirectoryOrCreate
        - name: output
          hostPath:
            path: /srv/overleaf/output
            type: DirectoryOrCreate
        - name: cache
          hostPath:
            path: /srv/overleaf/cache
            type: DirectoryOrCreate
        - name: docker-sock
          hostPath:
            path: /var/run/docker.sock
            type: Socket
---
apiVersion: v1
kind: Service
metadata:
  name: overleaf
  namespace: overleaf
spec:
  type: NodePort
  selector:
    app: overleaf
  ports:
    - name: http
      port: 80
      targetPort: 80
      nodePort: 30080
```

```bash theme={null}
kubectl apply -f 40-overleaf.yaml
kubectl -n overleaf rollout status deployment/overleaf --timeout=10m
kubectl -n overleaf logs deployment/overleaf | grep -E 'Finished migrations|Missing required'
```

首次启动会运行数据库迁移，需要一到两分钟。当 `/status` 有响应时 pod 即为就绪状态；然后打开 `OVERLEAF_SITE_URL`。

### 清单文件为何如此编写

* **数据卷。**`/var/lib/overleaf` 下的所有内容（项目文件、历史记录、上传文件）都保存在 PVC 上。使用 local-path 等节点本地存储时，数据会固定在一个节点上；使用网络块存储时，pod 可以在节点之间迁移。
* **编译卷和 Docker 套接字。**Ayakaleaf Pro 请求节点的 Docker 启动 TeX Live 容器，并**通过其在节点上的路径**将项目的编译目录传递给容器。因此这些目录是 `hostPath` 卷，其路径在 `SANDBOXED_COMPILES_HOST_DIR_*` 中重复指定。其内容是临时数据，无需备份。
* **`enableServiceLinks: false`。**Kubernetes 会为命名空间中的每个 Service 向每个 pod 添加 Docker 风格的变量：Service `redis` 会变成 `REDIS_PORT=tcp://10.x.x.x:6379`，Service `git-bridge` 会变成 `GIT_BRIDGE_PORT=tcp://...`。某些 Overleaf 服务会读取这些名称的变量。在此 pod 中，来自 `OVERLEAF_REDIS_*` 和 ConfigMap 的设置优先，但 git-bridge 会将 `GIT_BRIDGE_PORT` 作为其端口并因此停止（参见 [Git 集成](https://ayakaleaf-pro.mintlify.site/zh-CN/on-premises/configuration/kubernetes/integrations/git-integration.md)）。关闭这些链接可使环境仅包含你设置的内容。
* **`Recreate`。**绝不能让两个 pod 同时使用同一个数据卷或同时运行迁移。
* **对外暴露。**NodePort Service 在每个节点的 `30080` 端口上响应。在生产环境中，请在前端放置你的 ingress 控制器或负载均衡器，并在那里终止 TLS；它必须允许 WebSocket、10 分钟的请求超时（长时间编译）和 50 MB 的上传，并传递 `X-Forwarded-For` 和 `X-Forwarded-Proto`。


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