2025-06-06 23:49:38 +02:00
|
|
|
resource "kubernetes_namespace" "samba" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "samba"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_service_account" "samba" {
|
|
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
|
name = "samba-sa"
|
|
|
|
|
namespace = kubernetes_namespace.samba.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
automount_service_account_token = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_secret" "samba_secrets" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "samba-credentials"
|
|
|
|
|
namespace = kubernetes_namespace.samba.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data = {
|
|
|
|
|
USERNAME = var.samba_username
|
|
|
|
|
PASSWORD = var.samba_password
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 22:35:35 +02:00
|
|
|
resource "kubernetes_config_map" "samba_config" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "samba-config"
|
|
|
|
|
namespace = kubernetes_namespace.samba.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data = {
|
|
|
|
|
"smb.conf" = local.samba_config
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-06 23:49:38 +02:00
|
|
|
resource "kubernetes_deployment" "samba" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "samba"
|
|
|
|
|
namespace = kubernetes_namespace.samba.metadata[0].name
|
|
|
|
|
labels = {
|
|
|
|
|
samba = "samba"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
replicas = 1
|
|
|
|
|
|
|
|
|
|
selector {
|
|
|
|
|
match_labels = {
|
|
|
|
|
samba = "samba"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strategy {
|
2025-10-13 22:35:35 +02:00
|
|
|
type = "RollingUpdate"
|
2025-06-06 23:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template {
|
|
|
|
|
metadata {
|
|
|
|
|
labels = {
|
|
|
|
|
samba = "samba"
|
|
|
|
|
}
|
2025-11-18 18:19:42 +01:00
|
|
|
annotations = {
|
|
|
|
|
"smb_conf_checksum" = local.samba_config_hash
|
|
|
|
|
}
|
2025-06-06 23:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
service_account_name = kubernetes_service_account.samba.metadata[0].name
|
|
|
|
|
automount_service_account_token = false
|
|
|
|
|
|
|
|
|
|
container {
|
|
|
|
|
name = "samba"
|
|
|
|
|
image = "dockurr/samba:${local.samba_version}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
security_context {
|
|
|
|
|
allow_privilege_escalation = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
port {
|
|
|
|
|
name = "smb-1"
|
|
|
|
|
container_port = 445
|
2025-10-13 22:35:35 +02:00
|
|
|
host_port = var.host_port_enabled ? 445 : null
|
2025-06-06 23:49:38 +02:00
|
|
|
protocol = "TCP"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
port {
|
|
|
|
|
name = "smb-2"
|
|
|
|
|
container_port = 139
|
2025-10-13 22:35:35 +02:00
|
|
|
host_port = var.host_port_enabled ? 139 : null
|
2025-06-06 23:49:38 +02:00
|
|
|
protocol = "TCP"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
env {
|
|
|
|
|
name = "USER"
|
|
|
|
|
value_from {
|
|
|
|
|
secret_key_ref {
|
|
|
|
|
name = kubernetes_secret.samba_secrets.metadata[0].name
|
|
|
|
|
key = "USERNAME"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
env {
|
|
|
|
|
name = "PASS"
|
|
|
|
|
value_from {
|
|
|
|
|
secret_key_ref {
|
|
|
|
|
name = kubernetes_secret.samba_secrets.metadata[0].name
|
|
|
|
|
key = "PASSWORD"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
volume_mount {
|
2025-10-13 22:35:35 +02:00
|
|
|
name = "samba-config"
|
|
|
|
|
mount_path = "/etc/samba/smb.conf"
|
|
|
|
|
sub_path = "smb.conf"
|
|
|
|
|
read_only = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dynamic "volume_mount" {
|
|
|
|
|
for_each = var.shares
|
|
|
|
|
content {
|
|
|
|
|
name = lower("samba-share-${volume_mount.value.name}")
|
|
|
|
|
mount_path = "/host/${volume_mount.value.path}"
|
|
|
|
|
}
|
2025-06-06 23:49:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
volume {
|
2025-10-13 22:35:35 +02:00
|
|
|
name = "samba-config"
|
|
|
|
|
config_map {
|
|
|
|
|
name = kubernetes_config_map.samba_config.metadata[0].name
|
|
|
|
|
items {
|
|
|
|
|
key = "smb.conf"
|
|
|
|
|
path = "smb.conf"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dynamic "volume" {
|
|
|
|
|
for_each = var.shares
|
|
|
|
|
content {
|
|
|
|
|
name = lower("samba-share-${volume.value.name}")
|
|
|
|
|
host_path {
|
|
|
|
|
path = volume.value.path
|
|
|
|
|
type = "DirectoryOrCreate"
|
|
|
|
|
}
|
2025-06-06 23:49:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-16 23:19:25 +02:00
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
|
ignore_changes = [spec[0].template[0].metadata[0].annotations["kubectl.kubernetes.io/restartedAt"]]
|
|
|
|
|
}
|
2025-06-06 23:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-13 22:35:35 +02:00
|
|
|
resource "kubernetes_service" "smb" {
|
2025-06-06 23:49:38 +02:00
|
|
|
metadata {
|
2025-10-13 22:35:35 +02:00
|
|
|
name = "smb"
|
2025-06-06 23:49:38 +02:00
|
|
|
namespace = kubernetes_namespace.samba.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
selector = {
|
|
|
|
|
samba = "samba"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
port {
|
|
|
|
|
name = "smb"
|
|
|
|
|
port = 445
|
|
|
|
|
target_port = 445
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 22:35:35 +02:00
|
|
|
type = "ClusterIP"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
|
ignore_changes = [
|
|
|
|
|
metadata[0].annotations
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_service" "netbios" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "netbios"
|
|
|
|
|
namespace = kubernetes_namespace.samba.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
selector = {
|
|
|
|
|
samba = "samba"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
port {
|
|
|
|
|
name = "netbios"
|
|
|
|
|
port = 139
|
|
|
|
|
target_port = 139
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type = "ClusterIP"
|
2025-06-06 23:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
|
ignore_changes = [
|
|
|
|
|
metadata[0].annotations
|
|
|
|
|
]
|
|
|
|
|
}
|
2025-10-13 22:35:35 +02:00
|
|
|
|
2025-06-06 23:49:38 +02:00
|
|
|
}
|