configured portainer
This commit is contained in:
1 parent
e4b3455dd5
commit
f1e71fa1e9
6 files changed
+170
-28
No files matched your search
+13
-19
@@ -53,11 +53,11 @@ let
|
|||||||
# Docker's `local` driver calls mount(2) itself, so it cannot resolve a
|
# Docker's `local` driver calls mount(2) itself, so it cannot resolve a
|
||||||
# `host:/path` device: the server belongs in `o = addr=...` (the daemon
|
# `host:/path` device: the server belongs in `o = addr=...` (the daemon
|
||||||
# resolves that name) and `device` must be the bare `:/export/path`.
|
# resolves that name) and `device` must be the bare `:/export/path`.
|
||||||
nfsVolume = subpath: {
|
nfsVolume = exportPath: {
|
||||||
driver_opts = {
|
driver_opts = {
|
||||||
type = "nfs";
|
type = "nfs";
|
||||||
o = "addr=tnas1.lab.internal,rw,nfsvers=4.0,nolock,hard,noatime";
|
o = "addr=tnas1.lab.internal,rw,nfsvers=4.0,nolock,hard,noatime";
|
||||||
device = ":/mnt/SmallG/buzz/${subpath}";
|
device = ":${exportPath}";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
# Buzz management CLI — upstream deploy/compose/run.sh ported to this
|
# Buzz management CLI — upstream deploy/compose/run.sh ported to this
|
||||||
@@ -91,7 +91,7 @@ in
|
|||||||
skyg.networkDrives = {
|
skyg.networkDrives = {
|
||||||
enable = true;
|
enable = true;
|
||||||
};
|
};
|
||||||
services.tailscale.enable = true;
|
services.tailscale.enable = false;
|
||||||
services.tailscale.disableTaildrop = true;
|
services.tailscale.disableTaildrop = true;
|
||||||
services.tailscale.useRoutingFeatures = "both";
|
services.tailscale.useRoutingFeatures = "both";
|
||||||
services.tailscale.openFirewall = true;
|
services.tailscale.openFirewall = true;
|
||||||
@@ -108,11 +108,15 @@ in
|
|||||||
# Audiobookshelf — containerised, own macvlan IP, reachable as
|
# Audiobookshelf — containerised, own macvlan IP, reachable as
|
||||||
# http://audiobooks.app.internal
|
# http://audiobooks.app.internal
|
||||||
skyg.nixos.common.container-services.audiobookshelf = {
|
skyg.nixos.common.container-services.audiobookshelf = {
|
||||||
enable = false;
|
enable = true;
|
||||||
autoUpdate.enable = true;
|
autoUpdate.enable = true;
|
||||||
|
|
||||||
networks.lan = config.skyg.nixos.common.containers.networks.ipvlanLab.compose;
|
networks.lan = config.skyg.nixos.common.containers.networks.ipvlanLab.compose;
|
||||||
|
|
||||||
|
volumes = {
|
||||||
|
books = nfsVolume "/mnt/EightTerra/DownloadedTorrents/books";
|
||||||
|
};
|
||||||
|
|
||||||
services.audiobookshelf = {
|
services.audiobookshelf = {
|
||||||
image = audiobookshelf.image;
|
image = audiobookshelf.image;
|
||||||
networks.lan.ipv4_address = audiobookshelf.ip;
|
networks.lan.ipv4_address = audiobookshelf.ip;
|
||||||
@@ -123,7 +127,7 @@ in
|
|||||||
volumes = [
|
volumes = [
|
||||||
"${audiobookshelf.dataDir}/config:/config"
|
"${audiobookshelf.dataDir}/config:/config"
|
||||||
"${audiobookshelf.dataDir}/metadata:/metadata"
|
"${audiobookshelf.dataDir}/metadata:/metadata"
|
||||||
"${audiobookshelf.dataDir}/audiobooks:/audiobooks"
|
"books:/audiobooks"
|
||||||
"${audiobookshelf.dataDir}/podcasts:/podcasts"
|
"${audiobookshelf.dataDir}/podcasts:/podcasts"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
@@ -286,10 +290,10 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
volumes = {
|
volumes = {
|
||||||
buzz-postgres = nfsVolume "postgres";
|
buzz-postgres = nfsVolume "/mnt/SmallG/buzz/postgres";
|
||||||
buzz-redis = nfsVolume "redis";
|
buzz-redis = nfsVolume "/mnt/SmallG/buzz/redis";
|
||||||
s3 = nfsVolume "s3";
|
s3 = nfsVolume "/mnt/SmallG/buzz/s3";
|
||||||
buzz-git = nfsVolume "git";
|
buzz-git = nfsVolume "/mnt/SmallG/buzz/git";
|
||||||
};
|
};
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
@@ -466,16 +470,6 @@ in
|
|||||||
# Buzz management CLI.
|
# Buzz management CLI.
|
||||||
environment.systemPackages = [ buzz-manage ];
|
environment.systemPackages = [ buzz-manage ];
|
||||||
|
|
||||||
# Certbot TLS service
|
|
||||||
skyg.server.dns.certbot = {
|
|
||||||
enable = false;
|
|
||||||
email = "admin@skyg.ca";
|
|
||||||
publicDomains = [
|
|
||||||
".*skyg.ca"
|
|
||||||
".*home.sosnovsky.ca"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
# Firewall
|
# Firewall
|
||||||
networking.firewall.allowedUDPPorts = openPorts;
|
networking.firewall.allowedUDPPorts = openPorts;
|
||||||
networking.firewall.allowedTCPPorts = openPorts;
|
networking.firewall.allowedTCPPorts = openPorts;
|
||||||
|
|||||||
@@ -14,6 +14,16 @@
|
|||||||
enable = true;
|
enable = true;
|
||||||
envPath = "/opt/k3s/k3s.env";
|
envPath = "/opt/k3s/k3s.env";
|
||||||
};
|
};
|
||||||
|
# Portainer Edge Agent (k3s deployment)
|
||||||
|
age.secrets.portainer-agent-minipc3.file = ../secrets/portainer-agent-minipc3.age;
|
||||||
|
skyg.nixos.server.portainer = {
|
||||||
|
enable = true;
|
||||||
|
mode = "agent";
|
||||||
|
agent.k3s = {
|
||||||
|
enable = true;
|
||||||
|
edgeKeySecretName = "portainer-agent-minipc3";
|
||||||
|
};
|
||||||
|
};
|
||||||
# firmware updater
|
# firmware updater
|
||||||
services.fwupd.enable = true;
|
services.fwupd.enable = true;
|
||||||
# Bootloader.
|
# Bootloader.
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
systemd.services = lib.mkIf (cfg.enable && allNetworks != [ ]) {
|
systemd.services = lib.mkIf (cfg.enable && allNetworks != [ ]) {
|
||||||
container-networks = {
|
container-networks-setup = {
|
||||||
description = "Create configured container networks";
|
description = "Create configured container networks";
|
||||||
after = [ runtimeService "network-online.target" ];
|
after = [ runtimeService "network-online.target" ];
|
||||||
requires = [ runtimeService ];
|
requires = [ runtimeService ];
|
||||||
@@ -251,9 +251,6 @@ in
|
|||||||
RemainAfterExit = true;
|
RemainAfterExit = true;
|
||||||
};
|
};
|
||||||
script = ''
|
script = ''
|
||||||
# Prune unused networks so stale ones don't linger.
|
|
||||||
${runtimeBin} network prune -f 2>/dev/null || true
|
|
||||||
|
|
||||||
${lib.concatStringsSep "\n" (map (net: ''
|
${lib.concatStringsSep "\n" (map (net: ''
|
||||||
${runtimeBin} network inspect ${net.name} >/dev/null 2>&1 \
|
${runtimeBin} network inspect ${net.name} >/dev/null 2>&1 \
|
||||||
|| ${runtimeBin} ${createArgs net}
|
|| ${runtimeBin} ${createArgs net}
|
||||||
|
|||||||
@@ -4,6 +4,87 @@ with lib;
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.skyg.nixos.server.portainer;
|
cfg = config.skyg.nixos.server.portainer;
|
||||||
|
|
||||||
|
# Kubernetes manifest for the Portainer Agent (without the EDGE_KEY secret —
|
||||||
|
# that's created at runtime from the age secret).
|
||||||
|
agentManifest = pkgs.writeText "portainer-agent-k8s.yml" ''
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: portainer
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: portainer-agent
|
||||||
|
namespace: portainer
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: portainer-agent
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: cluster-admin
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: portainer-agent
|
||||||
|
namespace: portainer
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: portainer-agent
|
||||||
|
namespace: portainer
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: portainer-agent
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: portainer-agent
|
||||||
|
spec:
|
||||||
|
serviceAccountName: portainer-agent
|
||||||
|
containers:
|
||||||
|
- name: portainer-agent
|
||||||
|
image: portainer/agent:2.45.0
|
||||||
|
env:
|
||||||
|
- name: EDGE
|
||||||
|
value: "1"
|
||||||
|
- name: EDGE_INSECURE_POLL
|
||||||
|
value: "1"
|
||||||
|
- name: EDGE_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: portainer-agent-edge-key
|
||||||
|
key: EDGE_KEY
|
||||||
|
- name: EDGE_ID
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: portainer-agent-edge-key
|
||||||
|
key: EDGE_ID
|
||||||
|
- name: KUBERNETES_POD_IP
|
||||||
|
valueFrom:
|
||||||
|
fieldRef:
|
||||||
|
fieldPath: status.podIP
|
||||||
|
volumeMounts:
|
||||||
|
- name: data
|
||||||
|
mountPath: /data
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 9001
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 9001
|
||||||
|
volumes:
|
||||||
|
- name: data
|
||||||
|
emptyDir: {}
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.skyg.nixos.server.portainer = {
|
options.skyg.nixos.server.portainer = {
|
||||||
@@ -72,13 +153,28 @@ in
|
|||||||
Example: "portainer-agent-minipc1"
|
Example: "portainer-agent-minipc1"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
k3s = {
|
||||||
|
enable = mkEnableOption "deploy the Portainer Agent as a Kubernetes deployment on k3s";
|
||||||
|
|
||||||
|
edgeKeySecretName = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
Name of the age secret containing the EDGE_KEY for the k3s agent.
|
||||||
|
The corresponding age.secrets.<name>.file must be declared in the
|
||||||
|
host file. Example: "portainer-agent-minipc3"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
skyg.nixos.common.container-services.portainer =
|
# Server mode — Docker container via container-services
|
||||||
if cfg.mode == "server"
|
# Agent mode (Docker) — Docker container via container-services
|
||||||
then {
|
skyg.nixos.common.container-services.portainer = mkMerge [
|
||||||
|
(mkIf (cfg.mode == "server") {
|
||||||
enable = true;
|
enable = true;
|
||||||
autoUpdate.enable = true;
|
autoUpdate.enable = true;
|
||||||
services.portainer = {
|
services.portainer = {
|
||||||
@@ -104,8 +200,8 @@ in
|
|||||||
name = "portainer_data";
|
name = "portainer_data";
|
||||||
};
|
};
|
||||||
networks.lan = config.skyg.nixos.common.containers.networks.ipvlanLab.compose;
|
networks.lan = config.skyg.nixos.common.containers.networks.ipvlanLab.compose;
|
||||||
}
|
})
|
||||||
else {
|
(mkIf (cfg.mode == "agent" && !cfg.agent.k3s.enable) {
|
||||||
enable = true;
|
enable = true;
|
||||||
autoUpdate.enable = true;
|
autoUpdate.enable = true;
|
||||||
services.agent = {
|
services.agent = {
|
||||||
@@ -125,6 +221,50 @@ in
|
|||||||
volumes.portainer_agent_data = {
|
volumes.portainer_agent_data = {
|
||||||
name = "portainer_data";
|
name = "portainer_data";
|
||||||
};
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
# Agent mode — Kubernetes deployment on k3s
|
||||||
|
systemd.services.portainer-agent-k3s = mkIf (cfg.mode == "agent" && cfg.agent.k3s.enable) {
|
||||||
|
description = "Portainer Edge Agent on k3s";
|
||||||
|
after = [ "k3s.service" ];
|
||||||
|
wants = [ "k3s.service" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
Environment = "KUBECONFIG=/etc/rancher/k3s/k3s.yaml";
|
||||||
|
ExecStart = "${pkgs.kubectl}/bin/kubectl apply -f ${agentManifest}";
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.portainer-agent-k3s-secret = mkIf (cfg.mode == "agent" && cfg.agent.k3s.enable && cfg.agent.k3s.edgeKeySecretName != null) {
|
||||||
|
description = "Portainer Edge Agent k3s secret";
|
||||||
|
after = [ "k3s.service" ];
|
||||||
|
wants = [ "k3s.service" ];
|
||||||
|
before = [ "portainer-agent-k3s.service" ];
|
||||||
|
wantedBy = [ "portainer-agent-k3s.service" ];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
Environment = "KUBECONFIG=/etc/rancher/k3s/k3s.yaml";
|
||||||
|
};
|
||||||
|
script = ''
|
||||||
|
set -eu
|
||||||
|
EDGE_KEY_FILE="${config.age.secrets.${cfg.agent.k3s.edgeKeySecretName}.path}"
|
||||||
|
if [ ! -f "$EDGE_KEY_FILE" ]; then
|
||||||
|
echo "EDGE_KEY file not found: $EDGE_KEY_FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$EDGE_KEY_FILE"
|
||||||
|
${pkgs.kubectl}/bin/kubectl create namespace portainer --dry-run=client -o yaml | ${pkgs.kubectl}/bin/kubectl apply -f -
|
||||||
|
${pkgs.kubectl}/bin/kubectl delete secret portainer-agent-edge-key --namespace portainer --ignore-not-found
|
||||||
|
${pkgs.kubectl}/bin/kubectl create secret generic portainer-agent-edge-key \
|
||||||
|
--namespace portainer \
|
||||||
|
--from-literal="EDGE_KEY=$EDGE_KEY" \
|
||||||
|
--from-literal="EDGE_ID=$EDGE_ID" \
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -38,6 +38,7 @@ in
|
|||||||
# portainer agent envs
|
# portainer agent envs
|
||||||
"secrets/portainer-agent-bigbox1.age".publicKeys = [ ari bigbox1 ];
|
"secrets/portainer-agent-bigbox1.age".publicKeys = [ ari bigbox1 ];
|
||||||
"secrets/portainer-agent-minipc1.age".publicKeys = [ ari minipc1 ];
|
"secrets/portainer-agent-minipc1.age".publicKeys = [ ari minipc1 ];
|
||||||
|
"secrets/portainer-agent-minipc3.age".publicKeys = [ ari minipc3 ];
|
||||||
"secrets/lab-ca-key.age".publicKeys = [ ari ];
|
"secrets/lab-ca-key.age".publicKeys = [ ari ];
|
||||||
"secrets/buzz-tls-key.age".publicKeys = [ ari minipc1 ];
|
"secrets/buzz-tls-key.age".publicKeys = [ ari minipc1 ];
|
||||||
"secrets/portainer-tls-key.age".publicKeys = [ ari minipc2 ];
|
"secrets/portainer-tls-key.age".publicKeys = [ ari minipc2 ];
|
||||||
|
|||||||
Binary file not shown.
Reference in new issue
Block a user