Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/deploy/terraform/tickerplant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ticker Plant Terraform Deployment

This Terraform module deploys the pub-sub ticker plant example `srv_pubsub.kg` to Kubernetes. The script is stored in a `ConfigMap` and executed using the `klongpy-app:latest` image from the Docker example.

## Usage

Ensure your Kubernetes context is configured and the `klongpy-app:latest` image is accessible by the cluster. Then run:

```bash
terraform init
terraform apply
```

The deployment creates the `klongpy` namespace, a `Deployment` running the ticker plant, and a `Service` exposing port `8888`.
112 changes: 112 additions & 0 deletions examples/deploy/terraform/tickerplant/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.28"
}
}
}

provider "kubernetes" {
config_path = var.kubeconfig
}

variable "kubeconfig" {
description = "Path to kubeconfig file"
type = string
default = "~/.kube/config"
}

resource "kubernetes_namespace" "klongpy" {
metadata {
name = "klongpy"
}
}

resource "kubernetes_config_map" "tickerplant_script" {
metadata {
name = "tickerplant-script"
namespace = kubernetes_namespace.klongpy.metadata[0].name
}

data = {
"srv_pubsub.kg" = file("../../../ipc/srv_pubsub.kg")
}
}

resource "kubernetes_deployment" "tickerplant" {
metadata {
name = "tickerplant"
namespace = kubernetes_namespace.klongpy.metadata[0].name
labels = {
app = "tickerplant"
}
}

spec {
replicas = 1

selector {
match_labels = {
app = "tickerplant"
}
}

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

spec {
container {
name = "tickerplant"
image = "klongpy-app:latest"

env {
name = "KG_FILE_PATH"
value = "/scripts/srv_pubsub.kg"
}

port {
container_port = 8888
}

volume_mount {
name = "script-volume"
mount_path = "/scripts"
}
}

volume {
name = "script-volume"

config_map {
name = kubernetes_config_map.tickerplant_script.metadata[0].name
}
}
}
}
}
}

resource "kubernetes_service" "tickerplant" {
metadata {
name = "tickerplant"
namespace = kubernetes_namespace.klongpy.metadata[0].name
}

spec {
selector = {
app = "tickerplant"
}

port {
port = 8888
target_port = 8888
}

type = "ClusterIP"
}
}