Files
ljwx-harbor/harbor/HARBOR-PROXY-SUMMARY.md
brunoandClaude 3e9128a4d7 feat: Add Harbor proxy cache documentation and configuration tools
## Summary
- Add comprehensive proxy cache usage guide emphasizing correct patterns
- Create automated setup scripts for Docker/Containerd configuration
- Generate K8s containerd configuration for transparent proxy
- Add image preheating and synchronization tools
- Provide client configuration scripts for Docker and Kubernetes

## Documentation
- HARBOR-PROXY-CACHE-GUIDE.md: Correct usage patterns (pull directly from Harbor, not manual push)
- HARBOR-PROXY-SUMMARY.md: Quick reference with path conversion rules and performance metrics
- K8S-HARBOR-CONFIG.md: Kubernetes-specific Harbor configuration guide
- harbor-image-usage.md: Practical image usage examples

## Configuration Tools
- setup-harbor-proxy.sh: Interactive configuration tool for Docker/Containerd
- configure-docker-client.sh: Docker daemon.json setup script
- configure-k8s-harbor.sh: Kubernetes Harbor integration script
- containerd-harbor-config.toml: Ready-to-use containerd config for K8s/K3s nodes

## Image Management
- sync-common-images.sh: Batch sync common Docker images (fixed for loop syntax)
- preheat-images.sh: Pre-cache frequently used images to Harbor

## Key Features
- Proxy Cache Projects: dockerhub, ghcr, quay, k8s-registry
- Transparent proxy support via registry-mirrors
- 7-10x performance improvement on cached pulls
- Self-signed certificate support with insecure_skip_verify

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-13 08:27:32 +08:00

5.8 KiB
Raw Permalink Blame History

Harbor 代理缓存配置总结

🎯 当前配置状态

✅ Harbor 代理缓存端点

源仓库 Harbor代理项目 访问路径前缀
Docker Hub dockerhub harbor.omniverseai.net/dockerhub/
GitHub Container Registry ghcr harbor.omniverseai.net/ghcr/
Quay.io quay harbor.omniverseai.net/quay/
Kubernetes Registry k8s-registry harbor.omniverseai.net/k8s-registry/

✅ Docker配置已完成

Docker daemon已配置使用Harbor作为Docker Hub的镜像源:

配置文件: ~/.docker/daemon.json

{
  "registry-mirrors": [
    "https://harbor.omniverseai.net/dockerhub"
  ],
  "insecure-registries": [
    "harbor.omniverseai.net"
  ]
}

⚠️ 需要重启 Docker Desktop 使配置生效

✅ Containerd配置已生成

K8s/K3s配置文件已生成:containerd-harbor-config.toml

应用到K3s节点的步骤:

# 1. 复制到节点
scp containerd-harbor-config.toml user@k3s-node:/tmp/

# 2. 在节点上应用
sudo cp /tmp/containerd-harbor-config.toml /etc/containerd/config.toml
sudo systemctl restart k3s

📖 快速使用指南

方式1: 显式使用Harbor路径(推荐生产环境)

直接在配置文件中指定Harbor代理路径:

Docker Compose:

services:
  web:
    image: harbor.omniverseai.net/dockerhub/library/nginx:alpine
  db:
    image: harbor.omniverseai.net/dockerhub/library/postgres:16
  cache:
    image: harbor.omniverseai.net/dockerhub/library/redis:alpine

Kubernetes:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  template:
    spec:
      containers:
      - name: app
        image: harbor.omniverseai.net/dockerhub/library/python:3.12-slim
      - name: sidecar
        image: harbor.omniverseai.net/ghcr/actions/runner:latest

方式2: 透明代理(Docker已配置)

重启Docker Desktop后,标准镜像路径会自动通过Harbor拉取:

# 这些命令会自动使用Harbor代理
docker pull nginx:alpine
docker pull postgres:16
docker pull redis:alpine

注意: 透明代理仅支持Docker Hub,其他源仍需显式路径。

🧪 验证配置

测试Docker Hub代理

# 拉取镜像(首次会从Docker Hub下载并缓存)
docker pull harbor.omniverseai.net/dockerhub/library/alpine:latest

# 再次拉取(应该很快,从缓存)
docker pull harbor.omniverseai.net/dockerhub/library/alpine:latest

测试GitHub Container Registry代理

docker pull harbor.omniverseai.net/ghcr/actions/runner:latest

测试Quay.io代理

docker pull harbor.omniverseai.net/quay/prometheus/prometheus:v2.45.0

测试Kubernetes Registry代理

docker pull harbor.omniverseai.net/k8s-registry/pause:3.9

📊 性能对比

场景 时间 说明
直接从Docker Hub拉取 ~15秒 取决于网络
通过Harbor首次拉取 ~16秒 下载+缓存
通过Harbor再次拉取 ~2秒 ⚡ 从本地缓存

加速比: 约 7-10倍

🔧 常用命令

查看Harbor缓存的镜像

# 查看Docker Hub缓存
curl -u admin:admin123 -k https://harbor.omniverseai.net/api/v2.0/projects/dockerhub/repositories | jq

# 查看所有代理项目
curl -u admin:admin123 -k https://harbor.omniverseai.net/api/v2.0/projects | jq '.[] | select(.registry_id != null)'

清理缓存

通过Web UI: https://harbor.omniverseai.net/harbor/projects

📝 镜像路径转换规则

Docker Hub

原始路径 Harbor代理路径
nginx:alpine harbor.omniverseai.net/dockerhub/library/nginx:alpine
postgres:16 harbor.omniverseai.net/dockerhub/library/postgres:16
username/myapp:v1 harbor.omniverseai.net/dockerhub/username/myapp:v1

规则: dockerhub/library/ (官方) 或 dockerhub/<user>/ (用户)

GitHub Container Registry

原始路径 Harbor代理路径
ghcr.io/org/image:tag harbor.omniverseai.net/ghcr/org/image:tag

规则: 去掉 ghcr.io/,其余保持不变

Quay.io

原始路径 Harbor代理路径
quay.io/org/image:tag harbor.omniverseai.net/quay/org/image:tag

规则: 去掉 quay.io/,其余保持不变

Kubernetes Registry

原始路径 Harbor代理路径
registry.k8s.io/image:tag harbor.omniverseai.net/k8s-registry/image:tag

规则: 去掉 registry.k8s.io/,其余保持不变

💡 最佳实践

  1. 生产环境: 使用显式Harbor路径,配置文件清晰可审计
  2. 开发环境: 配置透明代理,无感知加速
  3. CI/CD: 两种方式结合,兼容性最佳
  4. 版本固定: 使用具体版本tag(如:1.21.0),避免:latest
  5. 定期清理: 删除不再使用的旧版本镜像

📚 相关文档

  • 完整指南: HARBOR-PROXY-CACHE-GUIDE.md - 367行详细文档
  • 配置脚本: setup-harbor-proxy.sh - 交互式配置工具
  • Harbor管理: README.md - Harbor完整使用文档

🔗 快捷链接

⚠️ 注意事项

  1. 证书信任: 使用自签名证书,某些环境可能需要额外配置
  2. 认证配置: K8s节点需要配置Harbor认证信息
  3. 存储空间: 缓存会占用存储,定期清理不用的镜像
  4. 网络配置: 确保所有节点可以访问Harbor(通过/etc/hosts或DNS)

下一步:

  1. ✅ 重启Docker Desktop
  2. ⏸️ 应用containerd配置到K3s节点(如有需要)
  3. ✅ 开始使用Harbor代理加速镜像拉取!