Added traefik/sonarr and ingress

Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
main
Tuan-Dat Tran 2024-07-22 19:47:23 +02:00
parent e3e10d3d67
commit bd56ee24c0
3 changed files with 379 additions and 44 deletions

254
sonarr.tf Normal file
View File

@ -0,0 +1,254 @@
resource "kubernetes_deployment" "sonarr" {
metadata {
name = "sonarr-deployment"
labels = {
name = "sonarr.k3s.seyshiro.de"
}
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
replicas = 1
selector {
match_labels = {
name = "sonarr.k3s.seyshiro.de"
}
}
template {
metadata {
labels = {
name = "sonarr.k3s.seyshiro.de"
}
}
spec {
container {
image = "lscr.io/linuxserver/sonarr:latest"
name = "sonarr-pod"
port {
container_port = 8989
}
resources {
limits = {
cpu = "0.5"
memory = "512Mi"
}
requests = {
cpu = "250m"
memory = "50Mi"
}
}
volume_mount {
name = kubernetes_persistent_volume.sonarr_config.metadata.0.name
mount_path = "/config"
}
volume_mount {
name = kubernetes_persistent_volume.sonarr_tv.metadata.0.name
mount_path = "/tv"
}
volume_mount {
name = kubernetes_persistent_volume.sonarr_downloads.metadata.0.name
mount_path = "/downloads"
}
}
volume {
name = kubernetes_persistent_volume.sonarr_config.metadata.0.name
persistent_volume_claim {
claim_name = kubernetes_persistent_volume.sonarr_config.metadata.0.name
}
}
volume {
name = kubernetes_persistent_volume.sonarr_tv.metadata.0.name
persistent_volume_claim {
claim_name = kubernetes_persistent_volume.sonarr_tv.metadata.0.name
}
}
volume {
name = kubernetes_persistent_volume.sonarr_downloads.metadata.0.name
persistent_volume_claim {
claim_name = kubernetes_persistent_volume.sonarr_downloads.metadata.0.name
}
}
}
}
}
}
resource "kubernetes_service" "sonarr" {
metadata {
name = "sonarr-service"
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
selector = {
name = kubernetes_deployment.sonarr.spec.0.template.0.metadata.0.labels.name
}
port {
port = 8989
target_port = 8989
}
type = "NodePort"
}
}
resource "kubernetes_persistent_volume_claim" "sonarr_config" {
metadata {
name = "sonarr-config"
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
access_modes = ["ReadWriteMany"]
resources {
requests = {
storage = "2Gi"
}
}
volume_name = kubernetes_persistent_volume.sonarr_config.metadata.0.name
storage_class_name = "local-path"
}
wait_until_bound = true
}
resource "kubernetes_persistent_volume" "sonarr_config" {
metadata {
name = "sonarr-config"
}
spec {
access_modes = ["ReadWriteMany"]
capacity = {
storage = "2Gi"
}
node_affinity {
required {
node_selector_term {
match_fields {
key = "metadata.name"
operator = "In"
values = ["sonarr"]
}
}
}
}
persistent_volume_source {
local {
path = "/home/tudattr/terraform/sonarr/config/"
}
}
storage_class_name = "local-path"
}
}
resource "kubernetes_persistent_volume_claim" "sonarr_tv" {
metadata {
name = "sonarr-tv"
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
access_modes = ["ReadWriteMany"]
resources {
requests = {
storage = "2Gi"
}
}
volume_name = kubernetes_persistent_volume.sonarr_tv.metadata.0.name
storage_class_name = "local-path"
}
wait_until_bound = true
}
resource "kubernetes_persistent_volume" "sonarr_tv" {
metadata {
name = "sonarr-tv"
}
spec {
access_modes = ["ReadWriteMany"]
capacity = {
storage = "2Gi"
}
node_affinity {
required {
node_selector_term {
match_fields {
key = "metadata.name"
operator = "In"
values = ["sonarr"]
}
}
}
}
persistent_volume_source {
local {
path = "/home/tudattr/terraform/sonarr/tv/"
}
}
storage_class_name = "local-path"
}
}
resource "kubernetes_persistent_volume_claim" "sonarr_downloads" {
metadata {
name = "sonarr-downloads"
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
access_modes = ["ReadWriteMany"]
resources {
requests = {
storage = "2Gi"
}
}
volume_name = kubernetes_persistent_volume.sonarr_downloads.metadata.0.name
storage_class_name = "local-path"
}
wait_until_bound = true
}
resource "kubernetes_persistent_volume" "sonarr_downloads" {
metadata {
name = "sonarr-downloads"
}
spec {
access_modes = ["ReadWriteMany"]
capacity = {
storage = "2Gi"
}
node_affinity {
required {
node_selector_term {
match_fields {
key = "metadata.name"
operator = "In"
values = ["sonarr"]
}
}
}
}
persistent_volume_source {
local {
path = "/home/tudattr/terraform/sonarr/downloads/"
}
}
storage_class_name = "local-path"
}
}

View File

@ -1,36 +1,125 @@
resource "kubernetes_deployment" "traefik" { resource "kubernetes_ingress_v1" "ingress" {
wait_for_load_balancer = true
metadata { metadata {
name = "traefik" name = "ingress"
labels = {
name = "traefik.k3s.seyshiro.de"
}
namespace = kubernetes_namespace.testing.metadata.0.name namespace = kubernetes_namespace.testing.metadata.0.name
} }
spec { spec {
replicas = 1 default_backend {
service {
name = kubernetes_service.ingress.metadata.0.name
port {
number = kubernetes_service.ingress.spec.0.port.0.port
}
}
}
rule {
host = "tooltoulto.seyshiro.de"
http {
path {
path = "/"
backend {
service {
name = kubernetes_service.ingress.metadata.0.name
port {
number = kubernetes_service.ingress.spec.0.port.0.port
}
}
}
}
}
}
rule {
host = "tooltoulto.seyshiro.de"
http {
path {
path = "/status"
backend {
service {
name = kubernetes_service.status.metadata.0.name
port {
number = kubernetes_service.status.spec.0.port.0.port
}
}
}
}
}
}
rule {
http {
path {
path = "/sonarr"
backend {
service {
name = kubernetes_service.sonarr.metadata.0.name
port {
number = kubernetes_service.sonarr.spec.0.port.0.port
}
}
}
}
}
}
tls {
secret_name = "tls-secret"
}
}
}
resource "kubernetes_service" "ingress" {
metadata {
name = "ingress-service"
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
selector = {
name = kubernetes_deployment.ingress.spec.0.template.0.metadata.0.labels.name
}
port {
port = 8080
target_port = 80
protocol = "TCP"
}
type = "NodePort"
}
}
resource "kubernetes_deployment" "ingress" {
metadata {
name = "ingress-deployment"
namespace = kubernetes_namespace.testing.metadata.0.name
labels = {
name = "status.k3s.seyshiro.de"
}
}
spec {
replicas = 1
selector { selector {
match_labels = { match_labels = {
name = "traefik.k3s.seyshiro.de" name = "nginx.k3s.seyshiro.de"
} }
} }
template { template {
metadata { metadata {
labels = { labels = {
name = "traefik.k3s.seyshiro.de" name = "nginx.k3s.seyshiro.de"
} }
} }
spec { spec {
container { container {
image = "traefik:v3.0" image = "nginx:1.7.9"
name = "traefik" name = "ingress-pod"
port {
container_port = 80
}
port { port {
container_port = 8080 container_port = 8080
@ -52,21 +141,13 @@ resource "kubernetes_deployment" "traefik" {
} }
} }
resource "kubernetes_service" "traefik" { # Display load balancer hostname (typically present in AWS)
metadata { output "load_balancer_hostname" {
name = "traefik" value = kubernetes_ingress_v1.ingress.status.0.load_balancer.0.ingress.0.hostname
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
selector = {
name = kubernetes_deployment.traefik.spec.0.template.0.metadata.0.labels.name
}
port {
port = 80
target_port = 80
}
type = "NodePort"
}
} }
# Display load balancer IP (typically present in GCP, or using Nginx ingress controller)
output "load_balancer_ip" {
value = kubernetes_ingress_v1.ingress.status.0.load_balancer.0.ingress.0.ip
}

View File

@ -1,6 +1,6 @@
resource "kubernetes_deployment" "status" { resource "kubernetes_deployment" "status" {
metadata { metadata {
name = "status" name = "status-deployment"
labels = { labels = {
name = "status.k3s.seyshiro.de" name = "status.k3s.seyshiro.de"
} }
@ -26,7 +26,7 @@ resource "kubernetes_deployment" "status" {
spec { spec {
container { container {
image = "louislam/uptime-kuma:1.23.6" image = "louislam/uptime-kuma:1.23.6"
name = "status" name = "status-pod"
port { port {
container_port = 3001 container_port = 3001
@ -43,12 +43,12 @@ resource "kubernetes_deployment" "status" {
} }
} }
volume_mount { volume_mount {
name = "volv" name = "storage"
mount_path = "/app/data" mount_path = "/app/data"
} }
} }
volume { volume {
name = "volv" name = "storage"
persistent_volume_claim { persistent_volume_claim {
claim_name = kubernetes_persistent_volume.status.metadata.0.name claim_name = kubernetes_persistent_volume.status.metadata.0.name
} }
@ -60,7 +60,7 @@ resource "kubernetes_deployment" "status" {
resource "kubernetes_service" "status" { resource "kubernetes_service" "status" {
metadata { metadata {
name = "status" name = "status-service"
namespace = kubernetes_namespace.testing.metadata.0.name namespace = kubernetes_namespace.testing.metadata.0.name
} }
@ -79,7 +79,7 @@ resource "kubernetes_service" "status" {
resource "kubernetes_persistent_volume_claim" "status" { resource "kubernetes_persistent_volume_claim" "status" {
metadata { metadata {
name = "status" name = "status-config"
namespace = kubernetes_namespace.testing.metadata.0.name namespace = kubernetes_namespace.testing.metadata.0.name
} }
@ -91,8 +91,8 @@ resource "kubernetes_persistent_volume_claim" "status" {
} }
} }
volume_name = kubernetes_persistent_volume.status.metadata.0.name volume_name = kubernetes_persistent_volume.status.metadata.0.name
storage_class_name = "local-path" storage_class_name = "local-path"
} }
wait_until_bound = true wait_until_bound = true
@ -100,7 +100,7 @@ resource "kubernetes_persistent_volume_claim" "status" {
resource "kubernetes_persistent_volume" "status" { resource "kubernetes_persistent_volume" "status" {
metadata { metadata {
name = "status" name = "status-config"
} }
spec { spec {
@ -112,17 +112,17 @@ resource "kubernetes_persistent_volume" "status" {
required { required {
node_selector_term { node_selector_term {
match_fields{ match_fields {
key = "metadata.name" key = "metadata.name"
operator = "In" operator = "In"
values = ["status"] values = ["status"]
} }
} }
} }
} }
persistent_volume_source { persistent_volume_source {
local { local {
path = "/home/tuan/terraform/status/" path = "/home/tudattr/terraform/status/"
} }
} }
storage_class_name = "local-path" storage_class_name = "local-path"