Skip to content

Commit

Permalink
add: examples k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
mosoriob committed Aug 30, 2024
1 parent fe3b75d commit 9b358d6
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
76 changes: 76 additions & 0 deletions examples/create-job-pvc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const k8s = require("@kubernetes/client-node");

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const batchV1Api = kc.makeApiClient(k8s.BatchV1Api);

const namespace = "wifire-mint";
const jobName = "hello-world-pvc";
const claimName = "wifire-ensemble-manager";

const jobManifest = {
apiVersion: "batch/v1",
kind: "Job",
metadata: {
name: jobName
},
spec: {
volumes: [
{
name: "data",
persistentVolumeClaim: {
claimName: claimName
}
}
],
template: {
spec: {
containers: [
{
name: "main",
image: "busybox",
command: ["echo", "Hello, World!"],
volumeMounts: [
{
name: "data",
mountPath: "/data"
}
],
resources: {
limits: {
cpu: "200m", // Limit the CPU usage to 200 millicores
memory: "128Mi" // Limit the memory usage to 128 MiB
},
requests: {
cpu: "100m", // Request at least 100 millicores of CPU
memory: "64Mi" // Request at least 64 MiB of memory
}
}
}
],
volumes: [
{
name: "data",
persistentVolumeClaim: {
claimName: claimName
}
}
],
restartPolicy: "Never"
}
},
backoffLimit: 4
}
};

const main = async () => {
try {
const createRes = await batchV1Api.createNamespacedJob(namespace, jobManifest);
console.log("Job created:", createRes.body.metadata.name);
} catch (err) {
console.error("Error creating job:", err);
}
};

main();
53 changes: 53 additions & 0 deletions examples/create-job.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const k8s = require("@kubernetes/client-node");

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const batchV1Api = kc.makeApiClient(k8s.BatchV1Api);

const namespace = "wifire-mint";
const jobName = "hello-world";

const jobManifest = {
apiVersion: "batch/v1",
kind: "Job",
metadata: {
name: jobName
},
spec: {
template: {
spec: {
containers: [
{
name: "main",
image: "busybox",
command: ["echo", "Hello, World!"],
resources: {
limits: {
cpu: "200m", // Limit the CPU usage to 200 millicores
memory: "128Mi" // Limit the memory usage to 128 MiB
},
requests: {
cpu: "100m", // Request at least 100 millicores of CPU
memory: "64Mi" // Request at least 64 MiB of memory
}
}
}
],
restartPolicy: "Never"
}
},
backoffLimit: 4
}
};

const main = async () => {
try {
const createRes = await batchV1Api.createNamespacedJob(namespace, jobManifest);
console.log("Job created:", createRes.body.metadata.name);
} catch (err) {
console.error("Error creating job:", err);
}
};

main();
File renamed without changes.

0 comments on commit 9b358d6

Please sign in to comment.