More K8s hacking

This commit is contained in:
Cyber MacGeddon 2024-09-07 12:47:56 +01:00
parent 583f11db0c
commit ee41fa1636
5 changed files with 79 additions and 71 deletions

View file

@ -12,7 +12,7 @@ local images = import "values/images.jsonnet";
local cfgVol = engine.configVolume( local cfgVol = engine.configVolume(
"prometheus-cfg", "./prometheus", "prometheus-cfg", "./prometheus",
{ {
"prometheus.cfg": importstr "prometheus/prometheus.yml", "prometheus.yml": importstr "prometheus/prometheus.yml",
} }
); );
@ -21,8 +21,9 @@ local images = import "values/images.jsonnet";
.with_image(images.prometheus) .with_image(images.prometheus)
.with_limits("0.5", "128M") .with_limits("0.5", "128M")
.with_reservations("0.1", "128M") .with_reservations("0.1", "128M")
// .with_command(["/bin/sh", "-c", "sleep 9999999"])
.with_port(9090, 9090, "http") .with_port(9090, 9090, "http")
.with_volume_mount(cfgVol, "/etc/prometheus") .with_volume_mount(cfgVol, "/etc/prometheus/")
.with_volume_mount(vol, "/prometheus"); .with_volume_mount(vol, "/prometheus");
local containerSet = engine.containers( local containerSet = engine.containers(
@ -48,16 +49,24 @@ local images = import "values/images.jsonnet";
local vol = engine.volume("grafana-storage").with_size("20G"); local vol = engine.volume("grafana-storage").with_size("20G");
local provVol = engine.configVolume( local provDashVol = engine.configVolume(
"provisioning", "./grafana/provisioning/", "prov-dash", "./grafana/provisioning/",
{ {
"dashboard.yml": "dashboard.yml":
importstr "grafana/provisioning/dashboard.yml", importstr "grafana/provisioning/dashboard.yml",
}
);
local provDataVol = engine.configVolume(
"prov-data", "./grafana/provisioning/",
{
"datasource.yml": "datasource.yml":
importstr "grafana/provisioning/datasource.yml", importstr "grafana/provisioning/datasource.yml",
} }
); );
local dashVol = engine.configVolume( local dashVol = engine.configVolume(
"dashboards", "./grafana/dashboards/", "dashboards", "./grafana/dashboards/",
{ {
@ -82,7 +91,10 @@ local images = import "values/images.jsonnet";
.with_port(3000, 3000, "cassandra") .with_port(3000, 3000, "cassandra")
.with_volume_mount(vol, "/var/lib/grafana") .with_volume_mount(vol, "/var/lib/grafana")
.with_volume_mount( .with_volume_mount(
provVol, "/etc/grafana/provisioning/dashboards/" provDashVol, "/etc/grafana/provisioning/dashboards/"
)
.with_volume_mount(
provDataVol, "/etc/grafana/provisioning/datasources/"
) )
.with_volume_mount( .with_volume_mount(
dashVol, "/var/lib/grafana/dashboards/" dashVol, "/var/lib/grafana/dashboards/"
@ -98,9 +110,11 @@ local images = import "values/images.jsonnet";
engine.resources([ engine.resources([
vol, vol,
provVol, provDashVol,
provDataVol,
dashVol, dashVol,
containerSet, containerSet,
service,
]) ])
}, },

View file

@ -13,13 +13,13 @@ local images = import "values/images.jsonnet";
local container = local container =
engine.container("pulsar") engine.container("pulsar")
.with_image(images.pulsar) .with_image(images.pulsar)
// .with_command(["bin/pulsar", "standalone"]) .with_command(["bin/pulsar", "standalone"])
.with_command(["bin/sh", "-c", "sleep 1000000"]) // .with_command(["/bin/sh", "-c", "sleep 9999999"])
.with_environment({ .with_environment({
"PULSAR_MEM": "-Xms700M -Xmx700M" "PULSAR_MEM": "-Xms700M -Xmx700M"
}) })
.with_limits("1.0", "900M") .with_limits("1.0", "1500M")
.with_reservations("0.5", "900M") .with_reservations("0.5", "1500M")
// .with_volume_mount(confVolume, "/pulsar/conf") // .with_volume_mount(confVolume, "/pulsar/conf")
.with_volume_mount(dataVolume, "/pulsar/data") .with_volume_mount(dataVolume, "/pulsar/data")
.with_port(6650, 6650, "bookie") .with_port(6650, 6650, "bookie")
@ -33,8 +33,8 @@ local images = import "values/images.jsonnet";
"-c", "-c",
"pulsar-admin --admin-url http://pulsar:8080 tenants create tg && pulsar-admin --admin-url http://pulsar:8080 namespaces create tg/flow && pulsar-admin --admin-url http://pulsar:8080 namespaces create tg/request && pulsar-admin --admin-url http://pulsar:8080 namespaces create tg/response && pulsar-admin --admin-url http://pulsar:8080 namespaces set-retention --size -1 --time 3m tg/response", "pulsar-admin --admin-url http://pulsar:8080 tenants create tg && pulsar-admin --admin-url http://pulsar:8080 namespaces create tg/flow && pulsar-admin --admin-url http://pulsar:8080 namespaces create tg/request && pulsar-admin --admin-url http://pulsar:8080 namespaces create tg/response && pulsar-admin --admin-url http://pulsar:8080 namespaces set-retention --size -1 --time 3m tg/response",
]) ])
.with_limits("0.5", "128M") .with_limits("0.1", "256M")
.with_reservations("0.1", "128M"); .with_reservations("0.1", "256M");
local containerSet = engine.containers( local containerSet = engine.containers(
"pulsar", "pulsar",
@ -59,5 +59,3 @@ local images = import "values/images.jsonnet";
} }

View file

@ -41,8 +41,8 @@ local prompts = import "prompts/mixtral.jsonnet";
"-m", "-m",
$["vertexai-model"], $["vertexai-model"],
]) ])
.with_limits("0.5", "128M") .with_limits("0.5", "256M")
.with_reservations("0.1", "128M") .with_reservations("0.1", "256M")
.with_volume_mount(cfgVol, "/vertexai"); .with_volume_mount(cfgVol, "/vertexai");
local containerSet = engine.containers( local containerSet = engine.containers(
@ -90,8 +90,8 @@ local prompts = import "prompts/mixtral.jsonnet";
"-o", "-o",
"non-persistent://tg/response/text-completion-rag-response", "non-persistent://tg/response/text-completion-rag-response",
]) ])
.with_limits("0.5", "128M") .with_limits("0.5", "256M")
.with_reservations("0.1", "128M") .with_reservations("0.1", "256M")
.with_volume_mount(cfgVol, "/vertexai"); .with_volume_mount(cfgVol, "/vertexai");
local containerSet = engine.containers( local containerSet = engine.containers(

View file

@ -30,17 +30,21 @@ local sc = {
volumeBindingMode: "Immediate", volumeBindingMode: "Immediate",
}; };
//patterns["pulsar"].create(engine)
// Extract resources usnig the engine // Extract resources usnig the engine
local resources = std.foldl( local resources = std.flattenArrays([
function(state, p) state + p.create(engine), p.create(engine) for p in std.objectValues(patterns)
std.objectValues(patterns), ]);
{}
);
local resourceList = { local resourceList = {
apiVersion: "v1", apiVersion: "v1",
kind: "List", kind: "List",
items: [ns, sc] + std.objectValues(resources.resources), items: [ns, sc] + resources,
}; };
std.manifestYamlDoc(resourceList, quote_keys=false)
resourceList

View file

@ -10,16 +10,6 @@
reservations: {}, reservations: {},
ports: [], ports: [],
volumes: [], volumes: [],
securityContext: {
fsGroup: 1234
// runAsUser: 65534
// runAsGroup: 65534
// runAsNonRoot: true
// runAsUser: 0,
// runAsGroup: 0,
// runAsNonRoot: true,
// readOnlyRootFilesystem: true,
},
with_image:: function(x) self + { image: x }, with_image:: function(x) self + { image: x },
@ -47,10 +37,9 @@
] ]
}, },
add:: function() { add:: function() [
resources +: { {
[container.name]: {
apiVersion: "apps/v1", apiVersion: "apps/v1",
kind: "Deployment", kind: "Deployment",
metadata: { metadata: {
@ -78,6 +67,16 @@
{ {
name: container.name, name: container.name,
image: container.image, image: container.image,
securityContext: {
// fsGroup: 1234
// runAsUser: 65534
// runAsGroup: 65534
// runAsNonRoot: true
runAsUser: 0,
runAsGroup: 0,
// runAsNonRoot: true,
// readOnlyRootFilesystem: true,
},
resources: { resources: {
requests: container.reservations, requests: container.reservations,
limits: container.limits limits: container.limits
@ -136,8 +135,7 @@
} }
} ]
}
}, },
@ -157,9 +155,10 @@
] ]
}, },
add:: function() { add:: function() [
resources +: {
[service.name + "-service"]: { {
apiVersion: "v1", apiVersion: "v1",
kind: "Service", kind: "Service",
metadata: { metadata: {
@ -180,8 +179,7 @@
], ],
} }
} }
} ],
}
}, },
@ -194,9 +192,10 @@
with_size:: function(size) self + { size: size }, with_size:: function(size) self + { size: size },
add:: function() { add:: function() [
resources +: {
[volume.name + "-pv"]: { {
apiVersion: "v1", apiVersion: "v1",
kind: "PersistentVolume", kind: "PersistentVolume",
metadata: { metadata: {
@ -211,12 +210,13 @@
storage: volume.size, storage: volume.size,
}, },
accessModes: [ "ReadWriteOnce" ], accessModes: [ "ReadWriteOnce" ],
persistentVolumeReclaimPolicy: "Delete",
hostPath: { hostPath: {
path: "/data/k8s/" + volume.name, path: "/data/k8s/" + volume.name,
} }
} }
}, },
[volume.name + "-pvc"]: { {
apiVersion: "v1", apiVersion: "v1",
kind: "PersistentVolumeClaim", kind: "PersistentVolumeClaim",
metadata: { metadata: {
@ -234,8 +234,7 @@
volumeName: volume.name, volumeName: volume.name,
} }
} }
} ],
},
volRef:: function() { volRef:: function() {
name: volume.name, name: volume.name,
@ -253,9 +252,8 @@
with_size:: function(size) self + { size: size }, with_size:: function(size) self + { size: size },
add:: function() { add:: function() [
resources +: { {
[volume.name + "-cm"]: {
apiVersion: "v1", apiVersion: "v1",
kind: "ConfigMap", kind: "ConfigMap",
metadata: { metadata: {
@ -264,12 +262,12 @@
}, },
data: parts data: parts
}, },
} ],
},
volRef:: function() { volRef:: function() {
name: volume.name, name: volume.name,
configMap: { name: volume.name + "-cm" }, configMap: { name: volume.name },
} }
}, },
@ -283,9 +281,8 @@
with_size:: function(size) self + { size: size }, with_size:: function(size) self + { size: size },
add:: function() { add:: function() [
resources +: { {
[volume.name + "-cm"]: {
apiVersion: "v1", apiVersion: "v1",
kind: "Secret", kind: "Secret",
metadata: { metadata: {
@ -297,12 +294,11 @@
for item in std.objectKeysValues(parts) for item in std.objectKeysValues(parts)
} }
}, },
} ],
},
volRef:: function() { volRef:: function() {
name: volume.name, name: volume.name,
secret: { secretName: volume.name + "-cm" }, secret: { secretName: volume.name },
} }
}, },
@ -315,20 +311,16 @@
name: name, name: name,
containers: containers, containers: containers,
add:: function() std.foldl( add:: function() std.flattenArrays(
function(state, c) state + c.add(), [ c.add() for c in cont.containers ]
cont.containers,
{}
), ),
}, },
resources:: function(res) resources:: function(res)
std.foldl( std.flattenArrays(
function(state, c) state + c.add(), [ c.add() for c in res ]
res,
{}
), ),
} }