Skip to content

Instantly share code, notes, and snippets.

@sparkprime
Created May 19, 2016 17:18
Show Gist options
  • Save sparkprime/0bb4562de3908f8977521d49472f8e4a to your computer and use it in GitHub Desktop.
Save sparkprime/0bb4562de3908f8977521d49472f8e4a to your computer and use it in GitHub Desktop.
rabbitmq kpm jsonnet
local resources = import "resources.libsonnet";
// "Top-level" function -- parameters can be overridden from the commandline.
// (Syntax is like Python)
function(
cookie="Dffds9342",
data_volume={
emptyDir: {
medium: "",
},
name: "varlibrabbitmq",
},
image="quay.io/ant31/kubernetes-rabbitmq",
namespace="default",
)
{
package: {
author: "Antoine Legrand",
description: "rabbitmq",
license: "MIT",
name: "rabbitmq/rabbitmq",
version: "3.5.6",
},
local all_shards = [1],
resources: [
resources.rabbitmq_svc("rabbitmq", shard_name) for shard_name in all_shards
] + [
resources.rabbitmq_all_svc("rabbitmq"),
resources.rabbitmq_management_svc("rabbitmq-mgt"),
] + [
resources.rabbitmq_rc("rabbitmq", shard_name, cookie, image, data_volume, all_shards) for shard_name in all_shards
],
deploy: {
name: "$self",
},
}
local port(name, num) = { name: name, port: num, targetPort: num };
local ports = {
erlang: port("erlang", 4369),
rabbitmq: port("rabbitmq", 5672),
cluster: port("cluster", 25672),
rabbitmq_manager: port("rabbitmq-manager", 15672),
};
{
local SelectorLabels = {
"k8s-app": "rabbitmq",
},
rabbitmq_all_svc(name):: {
apiVersion: "v1",
kind: "Service",
metadata: {
name: name,
labels: SelectorLabels,
},
spec: {
selector: SelectorLabels,
type: "ClusterIP",
ports: [ports.rabbitmq, ports.erlang, ports.cluster],
},
},
rabbitmq_svc(name, shard_name):: $.rabbitmq_all_svc(name) {
metadata+: {
name: "%s-%s" % [name, shard_name],
labels+: {
shard: shard_name,
},
},
spec+: {
selector+: {
shard: shard_name,
},
},
},
rabbitmq_rc(name, shard_name, cookie, image, data_volume, all_shards):: {
apiVersion: "v1",
kind: "ReplicationController",
metadata: {
name: name,
labels: SelectorLabels,
},
spec: {
replicas: 1,
selector: SelectorLabels {
shard: shard_name,
},
template: {
metadata: {
labels: SelectorLabels {
shard: shard_name,
},
},
spec: {
containers: [
{
name: name,
env: [
{
name: "RABBITMQ_CLUSTER_NODES",
value: std.toString(['rabbit@rabbitmq-%s' % shard for shard in all_shards]),
},
{
name: "RABBITMQ_ERLANG_COOKIE",
value: cookie,
},
{
name: "RABBITMQ_HOSTNAME",
value: "rabbitmq-%s" % name,
},
{
name: "RABBITMQ_NODENAME",
value: "rabbit@rabbitmq-%s" % name,
},
],
image: image,
ports: [ports.rabbitmq, ports.rabbitmq_manager, ports.erlang, ports.cluster],
resources: {
limits: {
cpu: "500m",
memory: "2G",
},
},
volumeMounts: [
{
mountPath: "/var/lib/rabbitmq",
name: data_volume.name,
},
],
},
],
volumes: [
data_volume,
],
},
},
},
},
rabbitmq_management_svc(name):: {
apiVersion: "v1",
kind: "Service",
metadata: {
name: name,
labels: SelectorLabels {
name: name,
},
},
spec: {
ports: [ports.rabbitmq_manager],
selector: SelectorLabels,
type: "NodePort",
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment