Files
ljwx-k8s/MORNING-CACHE-GUIDE.md
2026-02-20 22:50:45 +08:00

2.7 KiB

Morning Image Caching Guide

This guide explains how to use the morning window when the EU Harbor connection is fastest to cache commonly used images to the local Harbor.

Overview

The cache-morning-images.sh script is designed to cache commonly used Docker images during the morning hours (6AM-10AM) when the connection to the EU Harbor is typically fastest. This helps ensure that frequently used images are available locally, reducing deployment times and avoiding pull timeouts.

Files

  • cache-morning-images.sh - Main script for batch caching images in the morning
  • common-images.txt - List of commonly used images to cache
  • images-example.txt - Example image list file

Usage

Basic Usage

# Cache images from default file during morning window
./cache-morning-images.sh

Custom Images File

# Cache images from a custom file
./cache-morning-images.sh -f my-images.txt

Dry Run

# See what would be cached without actually caching
./cache-morning-images.sh --dry-run

Scheduling for Morning Window

To automatically run the script during the optimal morning window, you can add it to your crontab:

# Edit crontab
crontab -e

# Add this line to run at 7 AM every weekday during the morning fast window
0 7 * * 1-5 /path/to/your/k8s/cache-morning-images.sh >> /path/to/your/k8s/morning-cache.log 2>&1

Configuration

The script supports the following options:

  • -f, --file FILE: Specify a custom images file (default: common-images.txt)
  • -s, --script FILE: Specify a custom cache script (default: ./cache-image.sh)
  • --dry-run: Show what would be cached without actually caching
  • -h, --help: Show help message

Common Images List

The common-images.txt file contains a curated list of commonly used images including:

  • Web servers (nginx, httpd)
  • Databases (MySQL, PostgreSQL, Redis)
  • Object storage (MinIO)
  • Monitoring tools (Prometheus, Grafana)
  • Kubernetes dashboard
  • Development tools (Python, Node, Golang)
  • Infrastructure tools (apt-cacher-ng)

Best Practices

  1. Run during morning window: The script works best when run between 6AM-10AM when EU connection is fastest
  2. Regular updates: Update the common-images.txt file as your infrastructure needs evolve
  3. Monitor logs: Check the generated log files to track caching success/failure rates
  4. Schedule automatically: Use cron or similar scheduling tools to run automatically during optimal times

Troubleshooting

  • If images fail to cache, check your connection to the EU Harbor
  • Verify that the cache-image.sh script is working properly
  • Check that the Harbor credentials in cache-image.sh are still valid
  • Monitor the log files for detailed error information