Files
alexandre.pires aee57a8b89 Refactor Gitea and SSH configurations, update backup scripts, and enhance Nginx settings
- Updated SSH configuration for Gitea to disable banner and TTY, and modified the AuthorizedKeysCommand.
- Simplified gitea-shell script to directly call the k8s_gitea_shell command with required parameters.
- Removed unused gitea-auth script from playbook_gitea.yml.
- Updated systools_version in playbook_systools.yml to 0.4.5.
- Enhanced ssh_locker_helper to copy redirect URL to clipboard based on OS.
- Added a new script test_imaps for IMAP testing.
- Updated Terraform configurations for various applications, including:
  - Added a backup script for MariaDB with retention policy.
  - Changed Gitea version to 1.24-rootless and adjusted SSH settings.
  - Updated Nginx configurations to log errors and access to stderr/stdout.
  - Refactored services to use ClusterIP type and adjusted security contexts for deployments.
  - Added temporary storage for applications using empty_dir.
  - Enhanced backup.sh scripts for better error handling and logging.
2025-09-20 21:34:33 +02:00

275 lines
6.2 KiB
Terraform

resource "kubernetes_namespace" "m3uproxy" {
metadata {
annotations = {
name = "m3uproxy"
}
labels = {
name = "m3uproxy"
}
name = "m3uproxy"
}
}
resource "kubernetes_secret" "m3uproxy_admin_credentials" {
metadata {
name = "m3uproxy-credentials"
namespace = kubernetes_namespace.m3uproxy.metadata[0].name
}
data = {
username = "tv_admin"
password = var.admin_password
}
type = "Opaque"
}
resource "kubernetes_service_account" "m3uproxy_service_account" {
metadata {
name = "m3uproxy-app-sa"
namespace = kubernetes_namespace.m3uproxy.metadata[0].name
}
automount_service_account_token = false
}
resource "kubernetes_secret" "m3uproxy_config" {
metadata {
name = "m3uproxy-config"
namespace = kubernetes_namespace.m3uproxy.metadata[0].name
}
data = {
"m3uproxy.json" = local.m3uproxy_config
}
type = "Opaque"
}
resource "kubernetes_config_map" "m3uproxy_playlist" {
metadata {
name = "m3uproxy-playlist"
namespace = kubernetes_namespace.m3uproxy.metadata[0].name
}
data = {
"playlist.json" = local.m3uproxy_playlist
}
}
resource "kubernetes_deployment" "m3uproxy" {
metadata {
name = "m3uproxy"
namespace = kubernetes_namespace.m3uproxy.metadata[0].name
}
spec {
replicas = 1
selector {
match_labels = {
app = "m3uproxy"
}
}
strategy {
type = "RollingUpdate"
}
template {
metadata {
labels = {
app = "m3uproxy"
}
annotations = {
"checksum/m3uproxy" = local.m3uproxy_config_checksum
"checksum/playlist" = local.m3uproxy_playlist_checksum
}
}
spec {
service_account_name = kubernetes_service_account.m3uproxy_service_account.metadata[0].name
container {
name = "m3uproxy"
image = "a13labs/m3uproxy:${local.m3uproxy_version}"
image_pull_policy = "Always"
resources {
requests = {
memory = "256Mi"
}
}
port {
container_port = 8080
name = "http"
}
readiness_probe {
http_get {
path = "/health"
port = "http"
}
initial_delay_seconds = 5
period_seconds = 10
failure_threshold = 10
}
env {
name = "LOG_LEVEL"
value = var.loglevel
}
env {
name = "USERNAME"
value_from {
secret_key_ref {
name = kubernetes_secret.m3uproxy_admin_credentials.metadata[0].name
key = "username"
}
}
}
env {
name = "PASSWORD"
value_from {
secret_key_ref {
name = kubernetes_secret.m3uproxy_admin_credentials.metadata[0].name
key = "password"
}
}
}
security_context {
allow_privilege_escalation = false
run_as_user = 1000
run_as_group = 1000
read_only_root_filesystem = true
}
volume_mount {
name = "m3uproxy-config"
mount_path = "/app/conf/m3uproxy.json"
sub_path = "m3uproxy.json"
read_only = true
}
volume_mount {
name = "m3uproxy-cache"
mount_path = "/app/cache"
}
volume_mount {
name = "m3uproxy-playlist"
mount_path = "/app/conf/playlist.json"
sub_path = "playlist.json"
read_only = true
}
volume_mount {
name = "m3uproxy-app-data"
mount_path = "/app/data"
}
volume_mount {
name = "geoip-db"
mount_path = "/app/GeoIP"
read_only = true
}
}
volume {
name = "m3uproxy-config"
secret {
secret_name = kubernetes_secret.m3uproxy_config.metadata[0].name
items {
key = "m3uproxy.json"
path = "m3uproxy.json"
}
}
}
volume {
name = "m3uproxy-cache"
empty_dir {
}
}
volume {
name = "m3uproxy-playlist"
config_map {
name = kubernetes_config_map.m3uproxy_playlist.metadata[0].name
items {
key = "playlist.json"
path = "playlist.json"
}
}
}
volume {
name = "m3uproxy-app-data"
host_path {
path = local.m3uproxy_data_path
}
}
volume {
name = "geoip-db"
host_path {
path = local.geoip_path
}
}
}
}
}
lifecycle {
ignore_changes = [spec[0].template[0].metadata[0].annotations["kubectl.kubernetes.io/restartedAt"]]
}
}
resource "kubernetes_service" "m3uproxy" {
metadata {
name = "http"
namespace = kubernetes_namespace.m3uproxy.metadata[0].name
}
spec {
selector = {
app = "m3uproxy"
}
port {
port = 8080
target_port = "http"
}
type = "ClusterIP"
# cluster_ip = "None"
}
}
resource "kubernetes_ingress_v1" "m3uproxy_ingress_http" {
metadata {
name = "m3uproxy-ingress"
namespace = kubernetes_namespace.m3uproxy.metadata[0].name
annotations = {
"kubernetes.io/ingress.class" = "public"
"cert-manager.io/cluster-issuer" = "letsencrypt-prod"
"kubernetes.io/tls-acme" = "true"
"nginx.ingress.kubernetes.io/ssl-redirect" = "true"
}
}
spec {
tls {
hosts = [local.m3uproxy_fqdn]
secret_name = "m3uproxy-tls"
}
rule {
host = local.m3uproxy_fqdn
http {
path {
backend {
service {
name = "http"
port {
number = 8080
}
}
}
}
}
}
}
}