Now we properly preloaded the images without load at boot

This commit is contained in:
2026-03-24 21:16:21 +08:00
parent 58da0aada6
commit 81d192d577
3 changed files with 148 additions and 125 deletions

View File

@@ -1,56 +0,0 @@
#!/bin/sh
set -eu
KUBE_VERSION="${KUBE_VERSION:-v1.35.3}"
REGISTRY_ADDR="${REGISTRY_ADDR:-127.0.0.1:5000}"
mkdir -p /opt/registry
cat >/opt/registry/config.yml <<EOF
version: 0.1
log:
level: info
storage:
filesystem:
rootdirectory: /var/lib/registry
http:
addr: ${REGISTRY_ADDR}
EOF
cat >/opt/crictl.yaml <<'EOF'
runtime-endpoint: unix:///var/run/crio/crio.sock
image-endpoint: unix:///var/run/crio/crio.sock
timeout: 10
debug: false
EOF
registry serve /opt/registry/config.yml >/var/log/registry.log 2>&1 &
REG_PID=$!
cleanup() {
kill "$REG_PID" 2>/dev/null || true
}
trap cleanup EXIT INT TERM
for _ in $(seq 1 30); do
if curl -fsS "http://${REGISTRY_ADDR}/v2/_catalog" >/dev/null; then
break
fi
sleep 1
done
curl -fsS "http://${REGISTRY_ADDR}/v2/_catalog" >/dev/null
for img in $(kubeadm config images list --kubernetes-version "${KUBE_VERSION}"); do
name="${img#registry.k8s.io/}"
echo "Importing ${img} from ${REGISTRY_ADDR}/${name}"
skopeo copy --src-tls-verify=false \
"docker://${REGISTRY_ADDR}/${name}" \
"containers-storage:${img}"
done
echo "Imported images now visible to CRI-O:"
crictl images
kill "$REG_PID" 2>/dev/null || true
wait "$REG_PID" 2>/dev/null || true
trap - EXIT INT TERM

View File

@@ -0,0 +1,65 @@
#!/bin/bash
set -euo pipefail
RUNTIME_ENDPOINT="${RUNTIME_ENDPOINT:-unix:///var/run/crio/crio.sock}"
# 1. Get pause image
PAUSE_IMAGE="$(kubeadm config images list | grep pause)"
echo "Using pause image: $PAUSE_IMAGE"
# 2. Create pod sandbox config
cat > pod.json <<EOF
{
"metadata": {
"name": "pause-test",
"namespace": "default",
"attempt": 1
},
"log_directory": "/tmp",
"linux": {}
}
EOF
# 3. Create container config
cat > container.json <<EOF
{
"metadata": {
"name": "pause-container"
},
"image": {
"image": "$PAUSE_IMAGE"
},
"log_path": "pause.log",
"linux": {}
}
EOF
# 4. Run pod sandbox
POD_ID=$(crictl --runtime-endpoint "$RUNTIME_ENDPOINT" runp pod.json)
echo "Pod ID: $POD_ID"
# 5. Create container
CONTAINER_ID=$(crictl --runtime-endpoint "$RUNTIME_ENDPOINT" create "$POD_ID" container.json pod.json)
echo "Container ID: $CONTAINER_ID"
# 6. Start container
crictl --runtime-endpoint "$RUNTIME_ENDPOINT" start "$CONTAINER_ID"
# 7. Verify
echo "=== Pods ==="
crictl --runtime-endpoint "$RUNTIME_ENDPOINT" pods
echo "=== Containers ==="
crictl --runtime-endpoint "$RUNTIME_ENDPOINT" ps
# 8. Cleanup
echo "Cleaning up..."
crictl --runtime-endpoint "$RUNTIME_ENDPOINT" stop "$CONTAINER_ID" || true
crictl --runtime-endpoint "$RUNTIME_ENDPOINT" rm "$CONTAINER_ID" || true
crictl --runtime-endpoint "$RUNTIME_ENDPOINT" stopp "$POD_ID" || true
crictl --runtime-endpoint "$RUNTIME_ENDPOINT" rmp "$POD_ID" || true
rm -f pod.json container.json
echo "Done."