Overview
TheMetaparticleRunner class enables deployment of containerized applications to Kubernetes using the Metaparticle framework. This runner is designed for production deployments, supporting advanced features like service replication, sharding, job scheduling, and public service exposure.
When to Use MetaparticleRunner
UseMetaparticleRunner when you:
- Need to deploy to Kubernetes clusters
- Require service replication for high availability
- Want to implement sharding strategies
- Need to run batch jobs with multiple iterations
- Want to expose services publicly
Class Reference
MetaparticleRunner
Initializes a new Metaparticle runner instance.Methods
run()
Deploys a containerized application to Kubernetes with the specified configuration.The container image to deploy (e.g.,
"myapp:latest" or "gcr.io/project/app:v1")Name for the service/job in Kubernetes
Configuration object with the following properties:
Number of service replicas to run. Set to 0 if deploying a job instead of a service.
Sharding specification for distributing workload across replicas.When not
None, enables sharding strategy for the service.List of port numbers to expose. Automatically configured with TCP protocol.
Whether to expose the service publicly (creates public load balancer).
- Creates a Metaparticle service specification JSON file
- Configures either a service deployment or job based on options
- Stores specification in
.metaparticle/spec.json - Invokes
mp-compilerto deploy to Kubernetes - Creates the
.metaparticledirectory if it doesn’t exist
- Service: Created when
replicas > 0orshardSpecis defined - Job: Created when
jobSpecis provided
logs()
Attaches to and displays logs from the deployed application.Name of the service/job to retrieve logs from
- Reads the Metaparticle specification from
.metaparticle/spec.json - Attaches to the running containers without deploying
- Streams logs in real-time from Kubernetes pods
- Uses
mp-compilerwith--deploy=falseand--attach=trueflags
The
logs() method requires a valid .metaparticle/spec.json file from a previous run() call.cancel()
Deletes the deployed service or job from Kubernetes.Name of the service/job to delete
- Reads the Metaparticle specification from
.metaparticle/spec.json - Deletes all Kubernetes resources associated with the deployment
- Uses
mp-compilerwith--deleteflag - Removes pods, services, deployments, and jobs
ports()
Internal helper method that converts port numbers to Metaparticle port specifications.List of port numbers
number and protocol fields.
Example:
This is an internal method used by
run(). You typically don’t need to call it directly.Configuration Examples
Simple Web Service
Sharded Service with Multiple Ports
Batch Job Processing
Internal Service (Not Public)
Complete Workflow Example
Implementation Details
Metaparticle Compiler:- Uses
mp-compilercommand-line tool - Specification file stored in
.metaparticle/spec.json - Runs as subprocess with
check_call(raises exception on failure)
- All ports use TCP protocol
- Ports are exposed within the Kubernetes cluster
- Public services get external load balancers when
public=True
Differences from DockerRunner
| Feature | DockerRunner | MetaparticleRunner |
|---|---|---|
| Target | Local Docker | Kubernetes Cluster |
| Replication | Single container | Multiple replicas |
| Sharding | Not supported | Supported |
| Jobs | Not supported | Batch job support |
| Public Access | Port mapping only | Load balancer support |
| Use Case | Development/Testing | Production deployment |
| Complexity | Simple | Advanced features |
See Also
- DockerRunner - For local development
- RuntimeOptions - Configure the executor and runtime settings