Sonarr manages TV shows and anime using indexers and popular download clients to download media, rename files and folders, and manage metadata which can be used by media servers such as Jellyfin or Plex.
GitHub - Sonarr/Sonarr: Smart PVR for newsgroup and bittorrent users.
Sonarr can be deployed as a Kubernetes Deployment with Terraform using the following configuration. Just like Radarr, you need to mount any host paths or NFS/SMB drives to the container so that Sonarr can manage your existing media, and move files from your download clients to the root folders that you configured.
Sonarr also requires a PVC to manage its local database and configuration files. This can be provisioned with Rancher's local-path
provisioner.
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.13.1"
}
}
}
resource "kubernetes_deployment" "sonarr" {
metadata {
name = "sonarr"
namespace = var.namespace
labels = {
"servarr.app" = "sonarr"
}
}
spec {
replicas = 1
selector {
match_labels = {
"servarr.app" = "sonarr"
}
}
template {
metadata {
labels = {
"servarr.app" = "sonarr"
}
}
spec {
container {
image = "lscr.io/linuxserver/sonarr:latest"
name = "sonarr"
env_from {
config_map_ref {
name = kubernetes_config_map.sonarr_env.metadata.0.name
}
}
port {
container_port = 8989
}
volume_mount {
name = "data"
mount_path = "/config"
}
volume_mount {
name = "tv"
mount_path = "/tv"
}
volume_mount {
name = "import"
mount_path = "/import"
}
volume_mount {
name = "downloads"
mount_path = "/downloads"
}
}
volume {
name = "data"
persistent_volume_claim {
claim_name = "sonarr-data"
}
}
volume {
name = "tv"
host_path {
path = "/mnt/media/library/tv"
type = "Directory"
}
}
volume {
name = "import"
host_path {
path = "/mnt/media/library/import/tv"
type = "Directory"
}
}
volume {
name = "downloads"
host_path {
path = "/mnt/media/torrents/downloads"
type = "Directory"
}
}
}
}
}
}
resource "kubernetes_persistent_volume_claim" "sonarr_data" {
metadata {
name = "sonarr-data"
namespace = var.namespace
}
spec {
access_modes = ["ReadWriteOnce"]
resources {
requests = {
storage = "10Gi"
}
}
storage_class_name = "local-path"
}
}
resource "kubernetes_service" "sonarr" {
metadata {
name = "sonarr"
namespace = var.namespace
}
spec {
type = "ClusterIP"
selector = {
"servarr.app" = "sonarr"
}
port {
port = 8989
}
}
depends_on = [
kubernetes_deployment.sonarr
]
}
resource "kubernetes_config_map" "sonarr_env" {
metadata {
name = "sonarr-env"
namespace = var.namespace
}
data = {
"PUID" = 1000
"PGID" = 1000
"TZ" = "Europe/Zurich"
}
}
By default the LoadBalancer
service type will expose port 8989
to the local network. You can use a Kubernetes Ingress or Traefik's Ingress CRD to expose the Radarr service with a public domain, and switch to a ClusterIP service type to avoid exposing too many ports.
Making Sonarr publicly accessible means anyone with your domain/hostname can access the application. Enable authentication in Sonarr first, under Settings > General, enable Authencation with "Forms" and set a username and password.