Zot私有镜像仓库部署方案设计

Posted by Forgus on 2026-03-22

概述

在 k3s 集群上部署 Zot 作为私有镜像仓库,使用 Longhorn 作为持久化存储,通过 NodePort 暴露服务,无需认证。

需求

  • 镜像仓库软件: Zot
  • 存储: Longhorn PVC (200Gi)
  • 访问方式: NodePort 30500
  • 认证: 无需认证(开放访问)
  • 传输: HTTP(无 TLS)
  • Web UI: 启用 Zot 内置 UI(search 扩展)

架构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
┌─────────────────────────────────────────────┐
│ k3s Cluster
│ │
│ ┌──────────────────────────────────────┐ │
│ │ Zot Deployment (1 replica) │ │
│ │ - Image: ghcr.io/project-zot/zot │ │
│ │ - Container Port: 5000 │ │
│ │ - Config: /etc/zot/config.json │ │
│ │ - Storage: /var/lib/registry (PVC) │ │
│ └──────────┬───────────────────────────┘ │
│ │ ClusterIP │
│ ┌──────────▼───────────────────────────┐ │
│ │ Service (NodePort: 305005000) │ │
│ └──────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────┐ │
│ │ Longhorn PVC (10Gi, RWO) │ │
│ └──────────────────────────────────────┘ │
└─────────────────────────────────────────────┘

外部访问: <node-ip>:30500

组件清单

1. Namespace

  • 名称: zot-registry

2. ConfigMap

  • 名称: zot-config
  • 包含 config.json,配置要点:
    • storage.rootDirectory: /var/lib/registry
    • http.address: 0.0.0.0
    • http.port: 5000
    • 无认证配置
    • 启用 search 扩展(支持 Web UI 和镜像搜索)
    • 启用 ui 扩展(内置 Web 界面)
    • 关闭 CVE 扫描(减少资源占用)
    • 关闭 metrics 扩展

3. PersistentVolumeClaim

  • 名称: zot-data
  • StorageClass: longhorn
  • 容量: 200Gi
  • AccessMode: ReadWriteOnce

4. Deployment

  • 名称: zot
  • 副本数: 1
  • 容器:
    • 镜像: ghcr.io/project-zot/zot:latest
    • 端口: 5000
    • VolumeMount:
      • /var/lib/registry → PVC zot-data
      • /etc/zot/config.json → ConfigMap zot-config
    • 资源限制:
      • requests: cpu 100m, memory 256Mi
      • limits: cpu 1000m, memory 1Gi

5. Service

  • 名称: zot
  • 类型: NodePort
  • 端口: 5000 → NodePort 30500

使用方式

推送镜像

1
2
docker tag myapp <node-ip>:30500/myapp:latest
docker push <node-ip>:30500/myapp:latest

k3s 拉取配置

由于是 HTTP 无 TLS 仓库,需在 k3s 节点配置 insecure 仓库:

1
2
3
4
5
# /etc/rancher/k3s/registries.yaml
mirrors:
"<node-ip>:30500":
endpoint:
- "http://<node-ip>:30500"

配置后重启 k3s: systemctl restart k3s

拉取镜像

1
docker pull <node-ip>:30500/myapp:latest

部署顺序

  1. 创建 Namespace
  2. 创建 ConfigMap
  3. 创建 PVC
  4. 创建 Deployment
  5. 创建 Service
  6. 配置 k3s registries.yaml(如需从 k3s Pod 拉取)