Skip to content

Commit

Permalink
Adding Redis container
Browse files Browse the repository at this point in the history
  • Loading branch information
kachawla committed Jun 3, 2023
1 parent f9fe49c commit 13315d7
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
64 changes: 64 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0"
}
}
}

resource "kubernetes_deployment" "redis" {
metadata {
name = var.redis_cache_name
namespace = var.namespace
labels = {
app = "redis"
}
}

spec {
replicas = 1

selector {
match_labels = {
app = "redis"
}
}

template {
metadata {
labels = {
app = "redis"
}
}

spec {
container {
name = "redis"
image = "redis:latest"
port {
container_port = 6379
}
}
}
}
}
}

resource "kubernetes_service" "redis" {
metadata {
name = var.redis_cache_name
namespace = var.namespace
}

spec {
selector = {
app = "redis"
}

port {
port = 6379 # Service port
target_port = 6379 # Target port of the Redis deployment
}
}
}
11 changes: 11 additions & 0 deletions output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "host" {
value = "${kubernetes_service.redis.metadata[0].name}.${kubernetes_service.redis.metadata[0].namespace}.svc.cluster.local"
}

output "port" {
value = 6379
}

output "connectionString" {
value = "redis://${kubernetes_service.redis.metadata[0].name}.${kubernetes_service.redis.metadata[0].namespace}.svc.cluster.local:6379"
}
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "redis_cache_name" {
type = string
}

variable "namespace" {
description = "Namespace for deploying the Redis container"
type = string
default = "default"
}

0 comments on commit 13315d7

Please sign in to comment.