A lightweight utility to integrate with GKE Pod snapshots for fast startup.
Project description
gke-pod-snapshots-tools
A lightweight Python utility to integrate with Google Kubernetes Engine (GKE) Pod snapshots.
Overview
GKE Pod snapshots allow you to save the entire state of a running Pod—including memory and file system changes—and restore new replicas from that exact point. This is particularly valuable for AI/ML workloads or heavy applications that suffer from long initialization times (e.g., loading large models into GPU memory or compiling JIT code).
Instead of starting from scratch every time, your application can "checkpoint" itself after initialization. Future Pods will bypass the startup phase and resume immediately from the snapshot, significantly reducing startup latency.
This package provides a simple Python interface to trigger this checkpointing process from within your application.
Documentation
For a deep dive into the underlying technology, architecture, and limitations, please refer to the official Google documentation:
Installation
Install the package via pip:
pip install gke-pod-snapshots-tools
How to Use
The ideal place to call this function is immediately after your heavy initialization logic but before your application starts serving traffic.
import logging
from gke_pod_snapshots_tools import maybe_snapshot_on_gke
def main():
logging.info("Starting application...")
# 1. Perform heavy initialization
# (e.g., download weights, load ML models, warm up caches)
load_heavy_models()
# 2. Trigger the Snapshot
# If on GKE with checkpointing, this will FREEZE execution here.
# The pod state is saved to disk.
# When a new pod starts from this snapshot, execution RESUMES here instantly.
maybe_snapshot_on_gke()
# 3. Start serving
logging.info("Ready to serve traffic!")
start_server()
if __name__ == "__main__":
main()
What to Expect
When maybe_snapshot_on_gke() is called, the following sequence occurs:
- Detection: The tool checks if the environment supports application-driven checkpointing (specifically looking for the GKE Sandbox/gVisor interface). If not supported, it logs a message and returns immediately (safe for local development).
- Snapshot Trigger: If supported, the tool writes to the checkpoint interface, signaling the runtime to pause the container.
- Execution Pause: Your Python process will effectively "hang" or block at this line. This is normal. The runtime is serializing your memory and state to disk.
- Restoration: When a new Pod is created from this snapshot, execution resumes on the very next line of code.
- State Reset: The tool automatically re-seeds the Python
randommodule to ensure that restored replicas do not produce identical random sequences.
Important Considerations for Restored Pods
Because the application state is frozen and then restored later, certain environment properties change. You must account for these:
- Network Connections: Active network connections (like database sessions) are closed upon restore. You should initialize database connections or bind listening ports after the snapshot function returns.
- Time: The wall-clock time will "jump" forward from the time the snapshot was taken to the current time of restoration.
- Uniqueness: While this tool handles
randomreseeding, you must manually handle other unique identifiers (like UUIDs generated during init) if your application logic requires them to be unique per replica.
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gke_pod_snapshots_tools-0.1.0.tar.gz.
File metadata
- Download URL: gke_pod_snapshots_tools-0.1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a25574e70341f301df8a65a6345161fef0d745c78eb0d0fb1787214870b3f2bb
|
|
| MD5 |
8056ad1363841fbee3643ee372b8176e
|
|
| BLAKE2b-256 |
b25b987dc4d2c4ca29f90aaa1e6bf83b369149c605db23874cd11faf9f330ab9
|
Provenance
The following attestation bundles were made for gke_pod_snapshots_tools-0.1.0.tar.gz:
Publisher:
publish.yml on CoderSherlock/gke-pod-snapshots-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gke_pod_snapshots_tools-0.1.0.tar.gz -
Subject digest:
a25574e70341f301df8a65a6345161fef0d745c78eb0d0fb1787214870b3f2bb - Sigstore transparency entry: 762804944
- Sigstore integration time:
-
Permalink:
CoderSherlock/gke-pod-snapshots-tools@d222cab46b732761413bd34fb28afdcb03e3b7ed -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/CoderSherlock
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d222cab46b732761413bd34fb28afdcb03e3b7ed -
Trigger Event:
release
-
Statement type:
File details
Details for the file gke_pod_snapshots_tools-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gke_pod_snapshots_tools-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
942ff84fac1466812ce39e92306a73ceb48d97f0dc69968867cdd65baa3b38ad
|
|
| MD5 |
1d501b4caa767dc7d62b05398e030023
|
|
| BLAKE2b-256 |
fa01c4750c241de76a0118238469fc2f3364cfda4c690391d56594796a6962e4
|
Provenance
The following attestation bundles were made for gke_pod_snapshots_tools-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on CoderSherlock/gke-pod-snapshots-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gke_pod_snapshots_tools-0.1.0-py3-none-any.whl -
Subject digest:
942ff84fac1466812ce39e92306a73ceb48d97f0dc69968867cdd65baa3b38ad - Sigstore transparency entry: 762804946
- Sigstore integration time:
-
Permalink:
CoderSherlock/gke-pod-snapshots-tools@d222cab46b732761413bd34fb28afdcb03e3b7ed -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/CoderSherlock
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d222cab46b732761413bd34fb28afdcb03e3b7ed -
Trigger Event:
release
-
Statement type: