diff --git a/rabbitmq/etc/rabbitmq/enabled_plugins b/base/etc/rabbitmq/enabled_plugins similarity index 100% rename from rabbitmq/etc/rabbitmq/enabled_plugins rename to base/etc/rabbitmq/enabled_plugins diff --git a/rabbitmq/etc/rabbitmq/rabbitmq.conf b/base/etc/rabbitmq/rabbitmq.conf similarity index 88% rename from rabbitmq/etc/rabbitmq/rabbitmq.conf rename to base/etc/rabbitmq/rabbitmq.conf index c96b303..58ad217 100644 --- a/rabbitmq/etc/rabbitmq/rabbitmq.conf +++ b/base/etc/rabbitmq/rabbitmq.conf @@ -1,21 +1,21 @@ -loopback_users.guest = false -listeners.tcp.default = 5672 -management.tcp.port = 15672 - -#mqtt.listeners.tcp.default = 1883 -## Default MQTT with TLS port is 8883 -# mqtt.listeners.ssl.default = 8883 - -# anonymous connections, if allowed, will use the default -# credentials specified here -#mqtt.allow_anonymous = true -#mqtt.default_user = guest -#mqtt.default_pass = guest - -#mqtt.vhost = / -mqtt.exchange = mqtt -# 24 hours by default -#mqtt.subscription_ttl = 86400000 -#mqtt.prefetch = 10 - +loopback_users.guest = false +listeners.tcp.default = 5672 +management.tcp.port = 15672 + +#mqtt.listeners.tcp.default = 1883 +## Default MQTT with TLS port is 8883 +# mqtt.listeners.ssl.default = 8883 + +# anonymous connections, if allowed, will use the default +# credentials specified here +#mqtt.allow_anonymous = true +#mqtt.default_user = guest +#mqtt.default_pass = guest + +#mqtt.vhost = / +mqtt.exchange = mqtt +# 24 hours by default +#mqtt.subscription_ttl = 86400000 +#mqtt.prefetch = 10 + load_definitions = /etc/rabbitmq/rmq_schema.json \ No newline at end of file diff --git a/rabbitmq/etc/rabbitmq/rmq_schema.json b/base/etc/rabbitmq/rmq_schema.json similarity index 94% rename from rabbitmq/etc/rabbitmq/rmq_schema.json rename to base/etc/rabbitmq/rmq_schema.json index 6662066..0c46e83 100644 --- a/rabbitmq/etc/rabbitmq/rmq_schema.json +++ b/base/etc/rabbitmq/rmq_schema.json @@ -1,40 +1,40 @@ -{ - "rabbit_version": "3.8.9", - "rabbitmq_version": "3.8.9", - "product_name": "RabbitMQ", - "product_version": "3.8.9", - "users": [ - { - "name": "guest", - "password_hash": "KzhdT8G04Hon/5BEAasW4KF9NVBpwo3MIKGBs0nJjz8KLBvq", - "hashing_algorithm": "rabbit_password_hashing_sha256", - "tags": "administrator" - } - ], - "vhosts": [ - { - "name": "/" - } - ], - "permissions": [ - { - "user": "guest", - "vhost": "/", - "configure": ".*", - "write": ".*", - "read": ".*" - } - ], - "policies": [], - "exchanges": [ - { - "name": "mqtt", - "vhost": "/", - "type": "topic", - "durable": true, - "auto_delete": false, - "internal": false, - "arguments": {} - } - ] +{ + "rabbit_version": "3.8.9", + "rabbitmq_version": "3.8.9", + "product_name": "RabbitMQ", + "product_version": "3.8.9", + "users": [ + { + "name": "guest", + "password_hash": "KzhdT8G04Hon/5BEAasW4KF9NVBpwo3MIKGBs0nJjz8KLBvq", + "hashing_algorithm": "rabbit_password_hashing_sha256", + "tags": "administrator" + } + ], + "vhosts": [ + { + "name": "/" + } + ], + "permissions": [ + { + "user": "guest", + "vhost": "/", + "configure": ".*", + "write": ".*", + "read": ".*" + } + ], + "policies": [], + "exchanges": [ + { + "name": "mqtt", + "vhost": "/", + "type": "topic", + "durable": true, + "auto_delete": false, + "internal": false, + "arguments": {} + } + ] } \ No newline at end of file diff --git a/base/kustomization.yaml b/base/kustomization.yaml new file mode 100644 index 0000000..d05822b --- /dev/null +++ b/base/kustomization.yaml @@ -0,0 +1,16 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - postgres.yaml + - rabbitmq.yaml + +configMapGenerator: + - name: rabbitmq-config + files: + - enabled_plugins=etc/rabbitmq/enabled_plugins + - rabbitmq.conf=etc/rabbitmq/rabbitmq.conf + - rmq_schema.json=etc/rabbitmq/rmq_schema.json + - name: postgres-dbinit + files: + - piccdb.sql \ No newline at end of file diff --git a/postgres/piccdb.sql b/base/piccdb.sql similarity index 97% rename from postgres/piccdb.sql rename to base/piccdb.sql index 21126a9..af43743 100644 --- a/postgres/piccdb.sql +++ b/base/piccdb.sql @@ -1,44 +1,44 @@ -BEGIN; - -DROP TABLE IF EXISTS picc_events; -DROP TABLE IF EXISTS picc_locations; - -CREATE TABLE picc_locations -( - id SERIAL PRIMARY KEY, - location_name TEXT NOT NULL - -- TODO: figure out PostGIS -); - -INSERT INTO picc_locations (id, location_name) -VALUES (0, 'Unknown'); -INSERT INTO picc_locations (id, location_name) -VALUES (1, 'Not Applicable'); - -DROP TABLE IF EXISTS picc_events; - -CREATE TABLE picc_events -( - id BIGSERIAL PRIMARY KEY, -- ID - log_time TIMESTAMP with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Time when event was logged - event_time TIMESTAMP with time zone, -- Optional: time when event was generated, can be different than log_time - event_location integer NOT NULL references picc_locations DEFAULT 0, -- Location associated with event --- sender text NOT NULL, -- Sender is implicit in whoever owns the endpoint - endpoint text - CONSTRAINT valid_endpoint CHECK ( endpoint ~ '^([A-Za-z0-9_-]+\.)*([A-Za-z0-9_-]+)$' ), -- Event endpoint - body jsonb NOT NULL -- Event body content -); - -CREATE INDEX idx_picc_events_endpoint ON picc_events (endpoint); - --- DROP TABLE IF EXISTS mqtt; --- --- CREATE TABLE picc_mqtt --- ( --- id BIGSERIAL PRIMARY KEY, --- receive_time TIMESTAMP, --- routing_key TEXT, --- payload TEXT --- ); - +BEGIN; + +DROP TABLE IF EXISTS picc_events; +DROP TABLE IF EXISTS picc_locations; + +CREATE TABLE picc_locations +( + id SERIAL PRIMARY KEY, + location_name TEXT NOT NULL + -- TODO: figure out PostGIS +); + +INSERT INTO picc_locations (id, location_name) +VALUES (0, 'Unknown'); +INSERT INTO picc_locations (id, location_name) +VALUES (1, 'Not Applicable'); + +DROP TABLE IF EXISTS picc_events; + +CREATE TABLE picc_events +( + id BIGSERIAL PRIMARY KEY, -- ID + log_time TIMESTAMP with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Time when event was logged + event_time TIMESTAMP with time zone, -- Optional: time when event was generated, can be different than log_time + event_location integer NOT NULL references picc_locations DEFAULT 0, -- Location associated with event +-- sender text NOT NULL, -- Sender is implicit in whoever owns the endpoint + endpoint text + CONSTRAINT valid_endpoint CHECK ( endpoint ~ '^([A-Za-z0-9_-]+\.)*([A-Za-z0-9_-]+)$' ), -- Event endpoint + body jsonb NOT NULL -- Event body content +); + +CREATE INDEX idx_picc_events_endpoint ON picc_events (endpoint); + +-- DROP TABLE IF EXISTS mqtt; +-- +-- CREATE TABLE picc_mqtt +-- ( +-- id BIGSERIAL PRIMARY KEY, +-- receive_time TIMESTAMP, +-- routing_key TEXT, +-- payload TEXT +-- ); + COMMIT; \ No newline at end of file diff --git a/postgres/postgres.yaml b/base/postgres.yaml similarity index 84% rename from postgres/postgres.yaml rename to base/postgres.yaml index f0ffff9..41ec7e0 100644 --- a/postgres/postgres.yaml +++ b/base/postgres.yaml @@ -1,51 +1,57 @@ -apiVersion: v1 -kind: Service -metadata: - name: postgres -spec: - type: LoadBalancer - selector: - app: postgres - ports: - - protocol: TCP - port: 5432 ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: postgres -spec: - selector: - matchLabels: - app: postgres - serviceName: "postgres" - template: - metadata: - labels: - app: postgres - spec: - containers: - - name: postgres - image: docker.io/postgres:13 - ports: - - containerPort: 5432 - name: db - env: - - name: POSTGRES_DB - value: picc - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - name: postgres-password - key: password - volumeMounts: - - name: postgres-data - mountPath: /var/lib/postgresql/data - volumeClaimTemplates: - - metadata: - name: postgres-data - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: +apiVersion: v1 +kind: Service +metadata: + name: postgres +spec: + type: LoadBalancer + selector: + app: postgres + ports: + - protocol: TCP + port: 5432 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: postgres +spec: + selector: + matchLabels: + app: postgres + serviceName: "postgres" + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: docker.io/postgres:13 + ports: + - containerPort: 5432 + name: db + env: + - name: POSTGRES_DB + value: picc + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: postgres-password + key: password + volumeMounts: + - name: postgres-data + mountPath: /var/lib/postgresql/data + - name: dbinit + mountPath: /docker-entrypoint-initdb.d + volumes: + - name: dbinit + configMap: + name: postgres-dbinit + volumeClaimTemplates: + - metadata: + name: postgres-data + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: storage: 100Mi \ No newline at end of file diff --git a/rabbitmq/rebbitmq.yaml b/base/rabbitmq.yaml similarity index 95% rename from rabbitmq/rebbitmq.yaml rename to base/rabbitmq.yaml index a562244..0101e2f 100644 --- a/rabbitmq/rebbitmq.yaml +++ b/base/rabbitmq.yaml @@ -1,53 +1,53 @@ -apiVersion: v1 -kind: Service -metadata: - name: rabbitmq -spec: - type: LoadBalancer - selector: - app: rabbitmq - ports: - - name: amqp - port: 5672 - - name: web - port: 15672 - - name: mqtt - port: 1883 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: rabbitmq - labels: - app: rabbitmq -spec: - replicas: 1 - selector: - matchLabels: - app: rabbitmq - template: - metadata: - labels: - app: rabbitmq - spec: - containers: - - name: rabbitmq - image: docker.io/rabbitmq:3 - ports: - - containerPort: 5672 - - containerPort: 15672 - - containerPort: 1883 - volumeMounts: - - mountPath: "/etc/rabbitmq" - name: config - volumes: - - name: config - configMap: - name: rabbitmq-config - items: - - key: "enabled_plugins" - path: "enabled_plugins" - - key: "rabbitmq.conf" - path: "rabbitmq.conf" - - key: "rmq_schema.json" - path: "rmq_schema.json" +apiVersion: v1 +kind: Service +metadata: + name: rabbitmq +spec: + type: LoadBalancer + selector: + app: rabbitmq + ports: + - name: amqp + port: 5672 + - name: web + port: 15672 + - name: mqtt + port: 1883 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: rabbitmq + labels: + app: rabbitmq +spec: + replicas: 1 + selector: + matchLabels: + app: rabbitmq + template: + metadata: + labels: + app: rabbitmq + spec: + containers: + - name: rabbitmq + image: docker.io/rabbitmq:3 + ports: + - containerPort: 5672 + - containerPort: 15672 + - containerPort: 1883 + volumeMounts: + - mountPath: "/etc/rabbitmq" + name: config + volumes: + - name: config + configMap: + name: rabbitmq-config + items: + - key: "enabled_plugins" + path: "enabled_plugins" + - key: "rabbitmq.conf" + path: "rabbitmq.conf" + - key: "rmq_schema.json" + path: "rmq_schema.json" diff --git a/overlay/development/kustomization.yaml b/overlay/development/kustomization.yaml new file mode 100644 index 0000000..f6184c3 --- /dev/null +++ b/overlay/development/kustomization.yaml @@ -0,0 +1,29 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: picc-dev + +resources: + - namespace.yaml + - ../../base + +secretGenerator: + - name: postgres-password + literals: + - password=piccpass + +patches: + - patch: |- + - op: add + path: /spec/loadBalancerIP + value: 192.168.2.201 + target: + kind: Service + name: postgres + - patch: |- + - op: add + path: /spec/loadBalancerIP + value: 192.168.2.200 + target: + kind: Service + name: rabbitmq \ No newline at end of file diff --git a/overlay/development/namespace.yaml b/overlay/development/namespace.yaml new file mode 100644 index 0000000..da37c65 --- /dev/null +++ b/overlay/development/namespace.yaml @@ -0,0 +1,6 @@ +kind: Namespace +apiVersion: v1 +metadata: + name: picc-dev + labels: + name: picc-dev \ No newline at end of file diff --git a/overlay/production/namespace.yaml b/overlay/production/namespace.yaml new file mode 100644 index 0000000..169f08f --- /dev/null +++ b/overlay/production/namespace.yaml @@ -0,0 +1,6 @@ +kind: Namespace +apiVersion: v1 +metadata: + name: picc-prod + labels: + name: picc-prod diff --git a/postgres/.gitignore b/postgres/.gitignore deleted file mode 100644 index 262dbfa..0000000 --- a/postgres/.gitignore +++ /dev/null @@ -1 +0,0 @@ -postgres_passsword.yaml \ No newline at end of file diff --git a/postgres/postgres_passsword.yaml.template b/postgres/postgres_passsword.yaml.template deleted file mode 100644 index 8f78102..0000000 --- a/postgres/postgres_passsword.yaml.template +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: postgres-password -data: - password: \ No newline at end of file diff --git a/rabbitmq/.gitignore b/rabbitmq/.gitignore deleted file mode 100644 index 335705c..0000000 --- a/rabbitmq/.gitignore +++ /dev/null @@ -1 +0,0 @@ -rabbitmq-config.yaml \ No newline at end of file diff --git a/rabbitmq/rabbitmq_config.jsonnet b/rabbitmq/rabbitmq_config.jsonnet deleted file mode 100644 index c54f8eb..0000000 --- a/rabbitmq/rabbitmq_config.jsonnet +++ /dev/null @@ -1,12 +0,0 @@ -{ -"rabbitmq-config.yaml": -{ - "apiVersion" : "v1", - "kind": "ConfigMap", - "metadata": {"name": "rabbitmq-config"}, - "data": { - "enabled_plugins": importstr "etc/rabbitmq/enabled_plugins", - "rabbitmq.conf": importstr "etc/rabbitmq/rabbitmq.conf", - "rmq_schema.json": importstr "etc/rabbitmq/rmq_schema.json" - } -}} \ No newline at end of file