ACK Serverless runs batch jobs on demand — billing stops when the pod lifecycle ends, so you don't need to reserve nodes or expand the cluster for burst workloads. For cost-sensitive batch tasks, you can further reduce costs by using preemptible instances.
Prerequisites
Before you begin, make sure you have:
Run a job
Step 1: Create the job manifest
Create a file named job.yaml with the following content:
apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
resources:
requests:
cpu: 16
memory: 32Gi
restartPolicy: Never
backoffLimit: 4
This example computes pi to 2,000 decimal places using 16 CPUs and 32 GiB of memory.
Step 2: Deploy the job
kubectl apply -f job.yaml
Step 3: Check the job status
Run the following command to check the state of the pod:
kubectl get pod
Expected output:
NAME READY STATUS RESTARTS AGE
pi-4f7w5 0/1 Completed 0 80s
Run the following command to view detailed information about the state of the pod:
kubectl describe pod
Expected output:
Name: pi-4f7w5
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: virtual-kubelet-cn-hongkong-b/10.10.66.169
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulMountVolume 114s kubelet, eci MountVolume.SetUp succeeded for volume "default-token-8k4jz"
Normal Pulling 113s kubelet, eci pulling image "perl"
Normal Pulled 64s kubelet, eci Successfully pulled image "perl"
Normal Created 64s kubelet, eci Created container
Normal Started 64s kubelet, eci Started container
Use preemptible instances
Preemptible instances can reduce computing costs. To use a preemptible instance, add the k8s.aliyun.com/eci-spot-strategy: SpotAsPriceGo annotation to the pod template:
apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
metadata:
annotations:
k8s.aliyun.com/eci-spot-strategy: SpotAsPriceGo
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
resources:
requests:
cpu: 16
memory: 32Gi
restartPolicy: Never
backoffLimit: 4
For more information, see Use preemptible instances.
What's next
-
Learn about Kubernetes Job concepts to configure parallelism, completion counts, and failure handling.