Run a job on Slurm
Overview
LuxProvide's KaaS can login to Slurm (see Handling jobs) to run jobs, get jobs status, etc.
Slurm Rest API
Credentials
Using the Slurm Rest API requires to authenticate with a JWT; see Slurm Rest API.
Run jobs
curl -X POST ${SLURM_URL}/slurm/${API_VER}/job/submit \
-H "X-SLURM-USER-NAME:${USER_NAME}" \
-H "X-SLURM-USER-TOKEN:${SLURM_JWT}" \
-H "Content-Type: application/json" \
-d @- <<- EOF
{
"script": "echo 'Hello, world'",
"job": {
"qos": "default",
"time_limit": 5,
"account": "lxp",
"environment": {
"FOO": "bar"
}
}
}
EOF
SSH
Credentials
Using SSH to login requires to authenticate with SSH private key; see SSH Connection.
It is recommend to store the SSH private key in a K8S secret, then to mount this secret in the containers used to interact with Slurm:
kubectl create secret generic ${secret_name} \
--from-file=${key_name}=${key_path}
Variables:
${secret_name}
is the name of the secret in K8S, e.g.id_ed25519
${key_name}
is your ED25519 key file name, e.g.id_ed25519
${key_path}
is your ED25519 key file path, e.g.~/.ssh/id_ed25519
Importing a key in a running container is useful for debug purposes.
kubectl cp ${key_path} ${namespace}/${pod_name}:${key_dest} \
-c ${container_name}
Variables:
${key_path}
is your ED25519 key file path, e.g.~/.ssh/id_ed25519
${namespace}
is the target K8S namespace, e.g.default
${pod_name}
is your K8S pod name${key_dest}
is the ED25519 key destination path, e.g./tmp/id_ed25519
${container_name}
is your K8S container name
Run jobs
You can submit an local batch file from a K8S container.
Command:
ssh ${user}@cloudlogin.meluxina.lxp.lu \
-p 8822 -i ${key_path} sbatch < ${batch_path}
Example batch file (i.e. ${batch_path}
):
#!/bin/bash -l
#SBATCH --qos=default
#SBATCH --time=00:05:00
#SBATCH --account=${account_name}
echo "Hello, world"
Result:
Submitted batch job ${job_id}
Variables:
${user}
is your login on MeluXina, e.g.u000000
${key_path}
is the path to the ED25519 key to use${batch_path}
is the path to a local batch script${account_name}
is your project name on MeluXIna, e.g.p000000
${job_id}
is the job ID as returned by Slurm (a positive base 10 integer, e.g.123456
)
You can submit an inline batch file from a K8S container.
Command:
ssh ${user}@cloudlogin.meluxina.lxp.lu \
-p 8822 -i ${key_path} sbatch <<EOF
#!/bin/bash -l
#SBATCH --qos=default
#SBATCH --time=00:05:00
#SBATCH --account=${account_name}
echo "Hello, world"
EOF
Result:
Submitted batch job ${job_id}
Variables:
${user}
is your login on MeluXina, e.g.u000000
${key_path}
is the path to the ED25519 key to use${account_name}
is your project name on MeluXIna, e.g.p000000
${job_id}
is the job ID as returned by Slurm (a positive base 10 integer, e.g.123456
)
You can open an interactive Shell from a K8S container:
ssh ${user}@cloudlogin.meluxina.lxp.lu -p 8822 -i ${key_path}
Variables:
${user}
is your login on MeluXina, e.g.u000000
${key_path}
is the path to the ED25519 key to use
List jobs
List all jobs information as a JSON document:
ssh ${user}@cloudlogin.meluxina.lxp.lu -p 8822 -i ${key_path} squeue --json
List jobs information:
ssh ${user}@cloudlogin.meluxina.lxp.lu -p 8822 -i ${key_path} squeue
Variables:
${user}
is your login on MeluXina, e.g.u000000
${key_path}
is the path to the ED25519 key to use