add terraform module
All checks were successful
Gitea/docker-artifact/pipeline/head This commit looks good
All checks were successful
Gitea/docker-artifact/pipeline/head This commit looks good
This commit is contained in:
parent
e16b11fe29
commit
bdbdd815f0
197
deploy/terraform/main.tf
Normal file
197
deploy/terraform/main.tf
Normal file
@ -0,0 +1,197 @@
|
||||
terraform {
|
||||
backend "local" {}
|
||||
required_version = ">= 0.13"
|
||||
required_providers {
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
version = "2.34.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable "namespace" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ingress_domain" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "image" {
|
||||
type = string
|
||||
default = "dockermirror:5000/dpedu/artifact"
|
||||
}
|
||||
|
||||
variable "database_url" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "s3_url" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "replicas" {
|
||||
type = number
|
||||
default = 2
|
||||
}
|
||||
|
||||
|
||||
resource "kubernetes_secret" "secret" {
|
||||
metadata {
|
||||
name = "artifact-web-env"
|
||||
namespace = var.namespace
|
||||
}
|
||||
|
||||
data = {
|
||||
DATABASE_URL = var.database_url
|
||||
S3_URL = var.s3_url
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_deployment" "artifact" {
|
||||
metadata {
|
||||
name = "artifact-web-deployment"
|
||||
namespace = var.namespace
|
||||
labels = {
|
||||
app = "artifact"
|
||||
}
|
||||
}
|
||||
|
||||
spec {
|
||||
replicas = var.replicas
|
||||
|
||||
selector {
|
||||
match_labels = {
|
||||
service = "artifact-web"
|
||||
app = "artifact"
|
||||
}
|
||||
}
|
||||
|
||||
template {
|
||||
metadata {
|
||||
labels = {
|
||||
service = "artifact-web"
|
||||
app = "artifact"
|
||||
}
|
||||
}
|
||||
|
||||
spec {
|
||||
container {
|
||||
name = "web"
|
||||
image = var.image
|
||||
|
||||
image_pull_policy = "Always"
|
||||
|
||||
env {
|
||||
name = "DATABASE_URL"
|
||||
value_from {
|
||||
secret_key_ref {
|
||||
name = kubernetes_secret.secret.metadata[0].name
|
||||
key = "DATABASE_URL"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
env {
|
||||
name = "S3_URL"
|
||||
value_from {
|
||||
secret_key_ref {
|
||||
name = kubernetes_secret.secret.metadata[0].name
|
||||
key = "S3_URL"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
readiness_probe {
|
||||
tcp_socket {
|
||||
port = 8080
|
||||
}
|
||||
initial_delay_seconds = 15
|
||||
period_seconds = 5
|
||||
failure_threshold = 1
|
||||
success_threshold = 2
|
||||
}
|
||||
|
||||
liveness_probe {
|
||||
tcp_socket {
|
||||
port = 8080
|
||||
}
|
||||
initial_delay_seconds = 15
|
||||
period_seconds = 5
|
||||
failure_threshold = 1
|
||||
success_threshold = 1
|
||||
}
|
||||
|
||||
resources {
|
||||
limits = {
|
||||
cpu = "2"
|
||||
memory = "1024Mi"
|
||||
}
|
||||
|
||||
requests = {
|
||||
cpu = "100m"
|
||||
memory = "128Mi"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_service" "svc" {
|
||||
metadata {
|
||||
name = "artifact-web-service"
|
||||
namespace = var.namespace
|
||||
labels = {
|
||||
app = "artifact"
|
||||
}
|
||||
}
|
||||
|
||||
spec {
|
||||
selector = {
|
||||
service = "artifact-web"
|
||||
app = "artifact"
|
||||
}
|
||||
|
||||
port {
|
||||
protocol = "TCP"
|
||||
port = 8080
|
||||
target_port = 8080
|
||||
}
|
||||
}
|
||||
|
||||
wait_for_load_balancer = false
|
||||
}
|
||||
|
||||
resource "kubernetes_ingress_v1" "ingress" {
|
||||
metadata {
|
||||
name = "artifact-web-ingress"
|
||||
namespace = var.namespace
|
||||
labels = {
|
||||
app = "artifact"
|
||||
}
|
||||
}
|
||||
|
||||
spec {
|
||||
rule {
|
||||
host = var.ingress_domain
|
||||
|
||||
http {
|
||||
path {
|
||||
path = "/"
|
||||
path_type = "Prefix"
|
||||
|
||||
backend {
|
||||
service {
|
||||
name = kubernetes_service.svc.metadata[0].name
|
||||
port {
|
||||
number = 8080
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
deploy/terraform/provider.tf
Normal file
1
deploy/terraform/provider.tf
Normal file
@ -0,0 +1 @@
|
||||
provider "kubernetes" {}
|
Loading…
x
Reference in New Issue
Block a user