Skip to content

Commit

Permalink
deploy with nfs provisioned volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codes committed Aug 18, 2023
1 parent 093cc62 commit eda6a7c
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 95 deletions.
3 changes: 2 additions & 1 deletion .nxignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apps/k8s
apps/frigate
apps/docker-registry
apps/infrastructure*
apps/infrastructure*
apps/crowdsec
31 changes: 4 additions & 27 deletions apps/crowdsec/deployment/index.jsonnet
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
local lib = import '../../../packages/deployment-utils/dist/index.libsonnet';
local k = import 'github.com/jsonnet-libs/k8s-libsonnet/1.24/main.libsonnet';

local volume1 = k.core.v1.persistentVolume.new('crowdsec-config-pv')
+ k.core.v1.persistentVolume.metadata.withLabels({ type: 'local' })
+ k.core.v1.persistentVolume.spec.withAccessModes('ReadWriteOnce')
+ k.core.v1.persistentVolume.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolume.spec.withCapacity({ storage: '100Mi' })
+ k.core.v1.persistentVolume.spec.hostPath.withPath('/mnt/data/crowdsec-config-pv')
local volume1 = lib.volume.persistentVolume.new('crowdsec-config', '100Mi')
;
local volume2 = k.core.v1.persistentVolume.new('crowdsec-db-pv')
+ k.core.v1.persistentVolume.metadata.withLabels({ type: 'local' })
+ k.core.v1.persistentVolume.spec.withAccessModes('ReadWriteOnce')
+ k.core.v1.persistentVolume.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolume.spec.withCapacity({ storage: '80Gi' })
+ k.core.v1.persistentVolume.spec.hostPath.withPath('/mnt/data/crowdsec-db-pv')
;

local claim1 = k.core.v1.persistentVolumeClaim.new('crowdsec-config-pvc')
+ k.core.v1.persistentVolumeClaim.metadata.withLabels({ type: 'local' })
+ k.core.v1.persistentVolumeClaim.spec.withAccessModes('ReadWriteOnce')
+ k.core.v1.persistentVolumeClaim.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolumeClaim.spec.resources.withRequests({ storage: '100Mi' })
;

local claim2 = k.core.v1.persistentVolumeClaim.new('crowdsec-db-pvc')
+ k.core.v1.persistentVolumeClaim.metadata.withLabels({ type: 'local' })
+ k.core.v1.persistentVolumeClaim.spec.withAccessModes('ReadWriteOnce')
+ k.core.v1.persistentVolumeClaim.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolumeClaim.spec.resources.withRequests({ storage: '80Gi' })
local volume2 = lib.volume.persistentVolume.new('crowdsec-db', '80Gi')
;

local dbInit = {
Expand Down Expand Up @@ -74,4 +51,4 @@ local apiService = k.core.v1.service.new('crowdsec-api', {
;

[dashboardService, apiService]
+ [volume1, volume2, claim1, claim2]
+ volume1 + volume2
2 changes: 1 addition & 1 deletion apps/crowdsec/deployment/patch.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local agentPatch = {
{
name: 'logstash-log-files',
persistentVolumeClaim: {
claimName: 'elk-stack-logstash-output-pv-claim',
claimName: 'elk-stack-logstash-output-pvc',
},
},
],
Expand Down
44 changes: 14 additions & 30 deletions apps/elk-stack/deployment/index.jsonnet
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local lib = import '../../../packages/deployment-utils/dist/index.libsonnet';
local k = import 'github.com/jsonnet-libs/k8s-libsonnet/1.24/main.libsonnet';

local elasticSearch = {
Expand Down Expand Up @@ -29,14 +30,14 @@ local elasticSearch = {
},
spec: {
accessModes: [
'ReadWriteOnce',
'ReadWriteMany',
],
resources: {
requests: {
storage: '350Gi',
},
},
storageClassName: 'manual',
storageClassName: 'nfs-client',
},
}],
podTemplate: {
Expand Down Expand Up @@ -65,14 +66,14 @@ local elasticSearch = {
},
spec: {
accessModes: [
'ReadWriteOnce',
'ReadWriteMany',
],
resources: {
requests: {
storage: '350Gi',
},
},
storageClassName: 'manual',
storageClassName: 'nfs-client',
},
}],
podTemplate: {
Expand Down Expand Up @@ -226,7 +227,7 @@ local logStash = {
],
},
},
k.core.v1.volume.fromPersistentVolumeClaim('logstash-output', 'elk-stack-logstash-output-pv-claim'),
k.core.v1.volume.fromPersistentVolumeClaim('logstash-output', 'elk-stack-logstash-output-pvc'),
],
},
},
Expand All @@ -243,17 +244,7 @@ local logStashService = k.core.v1.service.new('logstash', {
}, [logStashNodePort]) +
k.core.v1.service.spec.withType('NodePort',)
;
local logstashOutput = k.core.v1.persistentVolume.new('elk-stack-logstash-output-pv-volume')
+ k.core.v1.persistentVolume.metadata.withLabels({ type: 'local' })
+ k.core.v1.persistentVolume.spec.withAccessModes('ReadWriteMany')
+ k.core.v1.persistentVolume.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolume.spec.withCapacity({ storage: '100Gi' })
+ k.core.v1.persistentVolume.spec.hostPath.withPath('/mnt/data/elk-stack-logstash-output-pv-volume')
;
local logstashOutputClaim = k.core.v1.persistentVolumeClaim.new('elk-stack-logstash-output-pv-claim')
+ k.core.v1.persistentVolumeClaim.spec.withAccessModes('ReadWriteMany')
+ k.core.v1.persistentVolumeClaim.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolumeClaim.spec.resources.withRequests({ storage: '100Gi' })
local logStashVolume = lib.volume.persistentVolume.new('elk-stack-logstash-output', '100Gi')
;

local config = |||
Expand Down Expand Up @@ -356,23 +347,16 @@ local logStashConfigMap = {
// }
// ;
local volume1 = k.core.v1.persistentVolume.new('elk-stack-pv-volume-1')
+ k.core.v1.persistentVolume.metadata.withLabels({ type: 'local' })
+ k.core.v1.persistentVolume.spec.withAccessModes('ReadWriteOnce')
+ k.core.v1.persistentVolume.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolume.spec.withCapacity({ storage: '350Gi' })
+ k.core.v1.persistentVolume.spec.hostPath.withPath('/mnt/data/elk-stack-pv-volume-1')
local volume1 = lib.volume.persistentVolume.new('elk-stack-1', '350Gi')
;
local volume2 = k.core.v1.persistentVolume.new('elk-stack-pv-volume-2')
+ k.core.v1.persistentVolume.metadata.withLabels({ type: 'local' })
+ k.core.v1.persistentVolume.spec.withAccessModes('ReadWriteOnce')
+ k.core.v1.persistentVolume.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolume.spec.withCapacity({ storage: '350Gi' })
+ k.core.v1.persistentVolume.spec.hostPath.withPath('/mnt/data/elk-stack-pv-volume-2')
local volume2 = lib.volume.persistentVolume.new('elk-stack-2', '350Gi')
;
[]
+ [elasticSearch, elasticSearchService, volume1, volume2]
+ volume1
+ volume2
+ [elasticSearch, elasticSearchService]
+ [kibana, kibanaService]
+ [logStashConfigMap, logstashOutput, logstashOutputClaim, logStash, logStashService]
+ logStashVolume
+ [logStashConfigMap, logStash, logStashService]
2 changes: 1 addition & 1 deletion apps/frigate/deployment/index.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ local deployment = lib.deployment.new(std.extVar('name'), std.extVar('image'), s
+ lib.deployment.withInitContainer('mqtt-is-ready', std.extVar('registryHostname') + '/mqtt-client:latest', { env: [secrets['mqtt/username'], secrets['mqtt/password']], command: ['sh'], args: ['-c', 'timeout 10 sub -h mqtt -t "\\$SYS/#" -C 1 -u $MQTT_USERNAME -P $MQTT_PASSWORD | grep -v Error || exit 1'] })
+ lib.deployment.withSecurityContext(0, { privileged: true, allowPrivilegeEscalation: true },);

local volume = lib.volume.persistentVolume.new('frigate-media', '300Gi', '/mnt/data/frigate');
local volume = lib.volume.persistentVolume.new('frigate-media', '300Gi');

volume + std.objectValues(deployment)
2 changes: 1 addition & 1 deletion apps/game-library-db/deployment/index.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ local deployment = lib.deployment.new('game-library-db', std.extVar('image'), ''
+ lib.deployment.withPersistentVolume('game-library-db')
+ lib.deployment.withVolumeMount(0, k.core.v1.volumeMount.new('game-library-db', '/data/db',));

local gameLibraryDbVolume = lib.volume.persistentVolume.new('game-library-db', '60Gi', '/mnt/data/game-library-db');
local gameLibraryDbVolume = lib.volume.persistentVolume.new('game-library-db', '60Gi');

gameLibraryDbVolume + std.objectValues(deployment)
2 changes: 1 addition & 1 deletion apps/gaming-assets-shared-volume/deployment/index.jsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local lib = import '../../../packages/deployment-utils/dist/index.libsonnet';

local assetLibraryDbVolume = lib.volume.persistentVolume.new('game-assets', '100Gi', '/mnt/data/game-assets');
local assetLibraryDbVolume = lib.volume.persistentVolume.new('game-assets', '100Gi');

assetLibraryDbVolume
2 changes: 1 addition & 1 deletion apps/guest-db/deployment/index.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ local deployment = lib.deployment.new('guest-db', std.extVar('image'), '', '', '
+ lib.deployment.withPersistentVolume('guest-db')
+ lib.deployment.withVolumeMount(0, k.core.v1.volumeMount.new('guest-db', '/data/db',));

local gameLibraryDbVolume = lib.volume.persistentVolume.new('guest-db', '5Gi', '/mnt/data/guest-db');
local gameLibraryDbVolume = lib.volume.persistentVolume.new('guest-db', '5Gi');

std.objectValues(deployment) + gameLibraryDbVolume
6 changes: 3 additions & 3 deletions apps/home-assistant/deployment/index.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ local postgresService = k.core.v1.service.new('home-assistant-postgres', { name:
protocol: 'TCP',
targetPort: 'db',
}],);
local postgresVolume = lib.volume.persistentVolume.new('home-assistant-postgres-db', '40Gi', '/mnt/data/home-assistant-postgres');
local haVolume = lib.volume.persistentVolume.new('home-assistant', '10Gi', '/mnt/data/home-assistant');
local haVolumeNewConfig = lib.volume.persistentVolume.new('home-assistant-new-config', '7Gi', '/mnt/data/home-assistant-new-config');
local postgresVolume = lib.volume.persistentVolume.new('home-assistant-postgres-db', '40Gi');
local haVolume = lib.volume.persistentVolume.new('home-assistant', '10Gi');
local haVolumeNewConfig = lib.volume.persistentVolume.new('home-assistant-new-config', '7Gi');

haVolume + haVolumeNewConfig + postgresVolume + [postgresDeployment, postgresService] + std.objectValues(deployment)
4 changes: 2 additions & 2 deletions apps/influxdb/deployment/index.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local deployment = lib.deployment.new(std.extVar('name'), std.extVar('image'), s
+ lib.deployment.withVolumeMount(0, k.core.v1.volumeMount.new('influxdb', '/var/lib/influxdb2',))
+ lib.deployment.withVolumeMount(0, k.core.v1.volumeMount.new('influxdb-config', '/etc/influxdb2',));

local volumeData = lib.volume.persistentVolume.new('influxdb', '150Gi', '/mnt/data/influxdb');
local volumeConfig = lib.volume.persistentVolume.new('influxdb-config', '30Gi', '/mnt/data/influxdb-config');
local volumeData = lib.volume.persistentVolume.new('influxdb', '150Gi');
local volumeConfig = lib.volume.persistentVolume.new('influxdb-config', '30Gi');

volumeData + volumeConfig + std.objectValues(deployment)
2 changes: 1 addition & 1 deletion apps/mqtt/deployment/index.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ local deployment = lib.deployment.new(std.extVar('name'), std.extVar('image'), s
+ lib.deployment.withVolumeMount(0, k.core.v1.volumeMount.new('mosquitto-config', '/mosquitto/config/mosquitto.conf') + k.core.v1.volumeMount.withSubPath('mosquitto.conf'));

local configMap = lib.volume.configMapVolume.new('mosquitto-config', mosquittoConfigMap);
local volume = lib.volume.persistentVolume.new('mosquitto', '5Gi', '/mnt/data/mosquitto');
local volume = lib.volume.persistentVolume.new('mosquitto', '5Gi');

volume + configMap + std.objectValues(deployment)
2 changes: 2 additions & 0 deletions apps/nfs-provisioner/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const run = async (
),
)

sh.exec(`helm uninstall nfs-subdir-external-provisioner`)

const nfsIp = await configurationApi.get("nfs/ip")
const nfsSharePath = await configurationApi.get("nfs/share-path")
throwIfError(
Expand Down
12 changes: 6 additions & 6 deletions apps/paperless/deployment/index.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ local deployment = lib.deployment.new(std.extVar('name'), std.extVar('image'), s
,)
;

local paperlessVolumeData = lib.volume.persistentVolume.new('paperless-data', '300Gi', '/mnt/data/paperless-data');
local paperlessVolumeMedia = lib.volume.persistentVolume.new('paperless-media', '400Gi', '/mnt/data/paperless-media');
local paperlessVolumeExport = lib.volume.persistentVolume.new('paperless-export', '100Gi', '/mnt/data/paperless-export');
local paperlessVolumeConsume = lib.volume.persistentVolume.new('paperless-consume', '100Gi', '/mnt/data/paperless-consume');
local paperlessVolumeData = lib.volume.persistentVolume.new('paperless-data', '300Gi');
local paperlessVolumeMedia = lib.volume.persistentVolume.new('paperless-media', '400Gi');
local paperlessVolumeExport = lib.volume.persistentVolume.new('paperless-export', '100Gi');
local paperlessVolumeConsume = lib.volume.persistentVolume.new('paperless-consume', '100Gi');

local postgresVolume = lib.volume.persistentVolume.new('paperless-postgres-db', '200Gi', '/mnt/data/paperless-postgres-db');
local redisVolume = lib.volume.persistentVolume.new('paperless-redis', '80Gi', '/mnt/data/paperless-redis');
local postgresVolume = lib.volume.persistentVolume.new('paperless-postgres-db', '200Gi');
local redisVolume = lib.volume.persistentVolume.new('paperless-redis', '80Gi');


paperlessVolumeData + paperlessVolumeMedia + paperlessVolumeExport + paperlessVolumeConsume + postgresVolume + redisVolume + std.objectValues(deployment)
10 changes: 5 additions & 5 deletions apps/photoprism/deployment/index.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ local deployment = lib.deployment.new(std.extVar('name'), std.extVar('image'), s
+ lib.deployment.withVolumeMount(0, k.core.v1.volumeMount.new('photoprism-storage', '/photoprism/storage',))
;

local originalsVolume = lib.volume.persistentVolume.new('originals', '600Gi', '/mnt/data/photoprism-originals');
local photoprismVolumeImport = lib.volume.persistentVolume.new('photoprism-import', '150Gi', '/mnt/data/photoprism-import');
local photoprismVolumeExport = lib.volume.persistentVolume.new('photoprism-export', '150Gi', '/mnt/data/photoprism-export');
local photoprismStorageVolume = lib.volume.persistentVolume.new('photoprism-storage', '100Gi', '/mnt/data/storage');
local originalsVolume = lib.volume.persistentVolume.new('originals', '600Gi');
local photoprismVolumeImport = lib.volume.persistentVolume.new('photoprism-import', '150Gi');
local photoprismVolumeExport = lib.volume.persistentVolume.new('photoprism-export', '150Gi');
local photoprismStorageVolume = lib.volume.persistentVolume.new('photoprism-storage', '100Gi');

local dbContainer = k.core.v1.container.new(name='photoprismdb', image=std.extVar('dbImage'))
+ k.core.v1.container.withImagePullPolicy('Always')
Expand Down Expand Up @@ -74,7 +74,7 @@ local dbService = k.core.v1.service.new('photoprism-db', { name: 'photoprism-db'
targetPort: 'db',
}],)
;
local dbVolume = lib.volume.persistentVolume.new('photoprism-db', '200Gi', '/mnt/data/photoprism-db');
local dbVolume = lib.volume.persistentVolume.new('photoprism-db', '200Gi');


originalsVolume + photoprismVolumeImport + photoprismVolumeExport + photoprismStorageVolume + dbVolume + [dbDeployment, dbService] + std.objectValues(deployment)
17 changes: 15 additions & 2 deletions apps/uptime-kuma/deployment/index.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ local deployment = lib.deployment.new(std.extVar('name'), std.extVar('image'), s
+ lib.deployment.withPersistentVolume('uptime-kuma')
+ lib.deployment.withVolumeMount(0, k.core.v1.volumeMount.new('uptime-kuma', '/app/data',));

local volume = lib.volume.persistentVolume.new('uptime-kuma', '10Gi', '/mnt/data/uptime-kuma');
local volume = k.core.v1.persistentVolume.new('uptime-kuma-pv')
+ k.core.v1.persistentVolume.metadata.withLabels({ type: 'local' })
+ k.core.v1.persistentVolume.spec.withAccessModes('ReadWriteMany')
+ k.core.v1.persistentVolume.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolume.spec.withCapacity({ storage: '10Gi' })
+ k.core.v1.persistentVolume.spec.hostPath.withPath('/mnt/data/uptime-kuma')
;
local volumeClaim = k.core.v1.persistentVolumeClaim.new('uptime-kuma-pvc')
+ k.core.v1.persistentVolumeClaim.spec.withAccessModes('ReadWriteMany')
+ k.core.v1.persistentVolumeClaim.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolumeClaim.spec.resources.withRequests({ storage: '10Gi' })
;

volume + std.objectValues(deployment)
[]
+ [volume, volumeClaim]
+ std.objectValues(deployment)
2 changes: 1 addition & 1 deletion apps/uptime-kuma/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
}
},
"tags": [],
"implicitDependencies": []
"implicitDependencies": ["nfs-provisioner"]
}
2 changes: 1 addition & 1 deletion apps/zwavejs/deployment/index.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ local deployment = lib.deployment.new(std.extVar('name'), std.extVar('image'), s
+ lib.deployment.withPersistentVolume('zwave')
+ lib.deployment.withVolumeMount(0, k.core.v1.volumeMount.new('zwave', '/usr/src/app/store',));

local zwaveVolume = lib.volume.persistentVolume.new('zwave', '5Gi', '/mnt/data/zwave');
local zwaveVolume = lib.volume.persistentVolume.new('zwave', '5Gi');

zwaveVolume + std.objectValues(deployment)
15 changes: 4 additions & 11 deletions packages/deployment-utils/dist/index.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ local k = import 'github.com/jsonnet-libs/k8s-libsonnet/1.24/main.libsonnet';
template+: {
spec+: {
volumes+: [
k.core.v1.volume.fromPersistentVolumeClaim(name, name + '-pv-claim'),
k.core.v1.volume.fromPersistentVolumeClaim(name, name + '-pvc'),
],
},
},
Expand All @@ -288,18 +288,11 @@ local k = import 'github.com/jsonnet-libs/k8s-libsonnet/1.24/main.libsonnet';
},

persistentVolume+: {
new(name, capacity, path)::
new(name, capacity)::
[
k.core.v1.persistentVolume.new(name + '-pv-volume')
+ k.core.v1.persistentVolume.metadata.withLabels({ type: 'local' })
+ k.core.v1.persistentVolume.spec.withAccessModes('ReadWriteMany')
+ k.core.v1.persistentVolume.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolume.spec.withCapacity({ storage: capacity })
+ k.core.v1.persistentVolume.spec.hostPath.withPath(path),

k.core.v1.persistentVolumeClaim.new(name + '-pv-claim')
k.core.v1.persistentVolumeClaim.new(name + '-pvc')
+ k.core.v1.persistentVolumeClaim.spec.withAccessModes('ReadWriteMany')
+ k.core.v1.persistentVolumeClaim.spec.withStorageClassName('manual')
+ k.core.v1.persistentVolumeClaim.spec.withStorageClassName('nfs-client')
+ k.core.v1.persistentVolumeClaim.spec.resources.withRequests({ storage: capacity }),
],
},
Expand Down

0 comments on commit eda6a7c

Please sign in to comment.