In this tutorial we will see how to use custom Labels with Ocean Launch Specifications.
key/value pairs that are attached to objects, such as
pods. Labels allow constraining a pod to only be able to run on particular nodes or have a preference for a particular node. See the Kubernetes documentation here for more.
Ocean supports custom label selectors, as well as built-in node labels and affinity/anti-affinity for pods & nodes.
Once configured, Ocean considers the constraints and launches capacity only when Pods that have the predefined labels are waiting to be scheduled.
Configuring Custom Label Selectors
Step 1: Label the pods
Make sure that your Pods are labeled properly. See the Kubernetes documentation.
Step 2: Define the custom labels in Ocean
In your Ocean cluster go to Actions > Launch Specifications > Add Launch Specification.
This will add a new Launch Specification to your Ocean Cluster:
Here you can add key / value of custom label and click on “Add”.
Step 3: Add labels to the nodes
Add Labels to EKS:
Add labels to the nodes by using the user data:
#!/bin/bash set -o xtrace /etc/eks/bootstrap.sh Ocean_Cluster --kubelet-extra-args --node-labels=mykey=myvalue,mykey2=myvalue2
For all of the above, new nodes will be launched with new labels.
Add labels to Spotinst-KOPS (Cluster that were created by KOPS natively):
- Recognize the IG name you originally created (“nodes” in the following example)
kops edit ig nodesand add the relevant label
kops update cluster
Built-in Node Labels Support
Spotinst auto scaler also supports Built-in Node Labels, there is no need to explicitly add any launch specifications for built-in labels. In Scale-Up, Ocean will launch eligible instances into the cluster to satisfy the built-in labels of the pods that are pending. Respectively, during the scale-down Ocean will look for under-utilized instances in the cluster to accommodate the pods that run on the host that is scheduled for scale down.
The following built-in labels are supported:
kubernetes.io/hostname failure-domain.beta.kubernetes.io/zone failure-domain.beta.kubernetes.io/region beta.kubernetes.io/instance-type node.kubernetes.io/instance-type topology.kubernetes.io/region topology.kubernetes.io/zone
You can also use Spotinst labels, please review here.