Skip to content

Instantly share code, notes, and snippets.

@jjo
Last active June 21, 2021 22:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjo/d6a74161ea5619d602e884367386f8f4 to your computer and use it in GitHub Desktop.
Save jjo/d6a74161ea5619d602e884367386f8f4 to your computer and use it in GitHub Desktop.
{
"kind": "Deployment",
"apiVersion": "apps/v1",
"metadata": {
"name": "jjo-nginx",
"creationTimestamp": null,
"labels": {
"app": "jjo-nginx"
}
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"app": "jjo-nginx"
}
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"app": "jjo-nginx"
}
},
"spec": {
"containers": [
{
"name": "nginx",
"image": "nginx",
"resources": {}
}
]
}
},
"strategy": {}
},
"status": {}
}
{
namespace:: 'default',
object(apiVersion, kind, name):: {
kind: kind,
apiVersion: apiVersion,
metadata: {
name: name,
labels: {
'app.kubernetes.io/name': name,
assert std.objectHas(self, "team"): "team label must be specified",
},
},
},
Resources(cpu, mem):: {
requests: {
cpu: cpu,
memory: mem,
},
limits: {
cpu: cpu,
memory: mem,
},
},
Deploy(name, image):: $.object('apps/v1', 'Deployment', name) {
metadata+: {
namespace: $.namespace,
labels+: {
app: name,
},
},
spec: {
replicas: 1,
selector: {
matchLabels: {
app: name,
},
},
template: {
metadata: {
labels: {
app: name,
},
},
spec: {
containers_:: {
default: {
name: name,
image: image,
resources: {},
},
},
containers: [self.containers_[k] for k in std.objectFields(self.containers_)],
},
},
strategy: {},
},
status: {},
},
Service(name):: {
},
}
local kube = import "kube.libsonnet";
//std.manifestYamlStream([
kube.Deploy('jjo-nginx', 'nginx') {
metadata+: {
labels+: {
team: 'sre',
},
},
spec+: {
replicas: 3,
template+: {
spec+: {
//containers[0]+: { resources: kube.Resources(1, '10Mi'),
containers_+: {
default+: {
resources+: kube.Resources(1, '10Mi'),
},
},
},
},
},
}
// kube.Deploy('foo-bar', 'node-exporter'),
//])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment