Using Labels and Constraints
This guide provides a comprehensive overview of Bacalhau's label and constraint system, which enables fine-grained control over job scheduling and resource allocation.
Understanding Labels and Constraints
Labels in Bacalhau are key-value pairs attached to nodes that describe their characteristics, capabilities, and properties. Constraints are rules you define when submitting jobs to ensure they run on nodes with specific labels.
Label Configuration
Command Line Configuration
Labels are defined when starting a Bacalhau node using the -c Labels
flag:
Configuration File
You can also define labels in a YAML configuration file:
Then start the node with:
Verifying Labels
Check node labels using:
Constraint Operators
Bacalhau supports various operators for precise node selection:
=
region=us-east
Exact match
!=
env!=staging
Not equal
exists
gpu
Key exists
!
!temporary
Key doesn't exist
in
zone in (a,b,c)
Value in set
gt
mem-gb gt 32
Greater than
lt
cpu-cores lt 16
Less than
Job Submission Patterns
Basic Constraint Usage
Here are common patterns for submitting jobs with constraints:
Environment-Specific Patterns
Label Management Best Practices
Naming Conventions
Follow these patterns for consistent label naming:
Use lowercase alphanumeric characters
Separate words with hyphens
Use descriptive prefixes for categorization
Examples:
Label Hierarchies
Organize labels hierarchically for better management:
Label Inheritance and Templates
Dynamic Label Assignment
Constraint Composition
Maintenance and Operations
Node Updates
Monitoring and Troubleshooting
Security and Compliance
Secure Workload Placement
Advanced Use Cases
Multi-Dimensional Constraints
Multi-team Coordination
Troubleshooting Common Issues
No Matching Nodes
If your job fails with no matching nodes:
Check available nodes and their labels:
Verify your constraints aren't too restrictive:
Ensure required nodes are online:
Label Updates Not Taking Effect
Remember that label changes require node restarts. After updating labels:
Gracefully stop the node
Apply new configuration
Restart the node
Verify labels with
bacalhau node list
Conclusion
Effective use of Bacalhau's label and constraint system enables precise control over workload placement and resource utilization. Follow these best practices:
Use consistent naming conventions
Document your label taxonomy
Regularly audit and clean up unused labels
Test constraints before production deployment
Monitor constraint patterns for optimization opportunities
For additional support, consult the Bacalhau documentation or community resources.
Last updated
Was this helpful?