Commit ab087939 by chenxx

init

0 parents
**/.terraform*
.terraform
.terraform.tfstate.lock.info
*.tfstate
*.tfstate.backup
# Web Service Module
This module provides an efficient way to create a Kubernetes deployment and service for a web service.
It will generate an access endpoint as output for your web service, allowing it to be accessed from other services or applications.
<!-- BEGIN_TF_DOCS -->
## Requirements
| Name | Version |
|------|---------|
| <a name="requirement_kubectl"></a> [kubectl](#requirement\_kubectl) | 1.14.0 |
## Providers
| Name | Version |
|------|---------|
| <a name="provider_kubectl"></a> [kubectl](#provider\_kubectl) | 1.14.0 |
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.19.0 |
## Modules
| Name | Source | Version |
|------|--------|---------|
| <a name="module_deployment"></a> [deployment](#module\_deployment) | terraform-iaac/deployment/kubernetes | 1.4.2 |
| <a name="module_service"></a> [service](#module\_service) | terraform-iaac/service/kubernetes | 1.0.4 |
## Resources
| Name | Type |
|------|------|
| [kubectl_manifest.ns](https://registry.terraform.io/providers/gavinbunney/kubectl/1.14.0/docs/resources/manifest) | resource |
| [kubernetes_service.service](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/service) | data source |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_env"></a> [env](#input\_env) | Name and value pairs to set as the environment variables | `map(string)` | `{}` | no |
| <a name="input_image"></a> [image](#input\_image) | Docker image name | `string` | n/a | yes |
| <a name="input_limit_cpu"></a> [limit\_cpu](#input\_limit\_cpu) | CPU limit. e.g. 0.5, 1, 2 | `string` | `""` | no |
| <a name="input_limit_memory"></a> [limit\_memory](#input\_limit\_memory) | Memory limit. e.g. 128Mi, 512Mi, 1Gi, 2Gi, 4Gi | `string` | `""` | no |
| <a name="input_name"></a> [name](#input\_name) | Name of the deployment resource. Auto-generated if empty. | `string` | `""` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace to deploy. Auto-generated if empty. | `string` | `""` | no |
| <a name="input_ports"></a> [ports](#input\_ports) | Service ports to expose | `list(number)` | <pre>[<br> 80<br>]</pre> | no |
| <a name="input_request_cpu"></a> [request\_cpu](#input\_request\_cpu) | CPU request. e.g. 0.5, 1, 2 | `string` | `"0.1"` | no |
| <a name="input_request_memory"></a> [request\_memory](#input\_request\_memory) | Memory request. e.g. 128Mi, 512Mi, 1Gi, 2Gi, 4Gi | `string` | `"128Mi"` | no |
## Outputs
| Name | Description |
|------|-------------|
| <a name="output_ports"></a> [ports](#output\_ports) | Service Ports |
| <a name="output_service_ip"></a> [service\_ip](#output\_service\_ip) | Service IP |
<!-- END_TF_DOCS -->
\ No newline at end of file \ No newline at end of file
terraform {
required_providers {
kubectl = {
source = "gavinbunney/kubectl"
version = "1.14.0"
}
}
}
module "deployment" {
# disable wait for all pods be ready.
#
wait_for_rollout = false
source = "terraform-iaac/deployment/kubernetes"
version = "1.4.2"
name = local.name
namespace = local.namespace
image = var.image
resources = {
request_cpu = var.request_cpu == "" ? null : var.request_cpu
limit_cpu = var.limit_cpu == "" ? null : var.limit_cpu
request_memory = var.request_memory == "" ? null : var.request_memory
limit_memory = var.limit_memory == "" ? null : var.limit_memory
}
env = var.env
labels = var.custom_labels
readiness_probe = {
http_get = {
path = "/"
port = var.probe_http_port
scheme = "HTTP"
}
success_threshold = 1
failure_threshold = 3
initial_delay_seconds = 10
period_seconds = 30
timeout_seconds = 3
}
volume_host_path = [
{
volume_name = var.volume_logs
path_on_node = "/data/java_log"
},
{
volume_name = var.app_path
path_on_node = "/app/soft/java_project"
}
]
}
module "service" {
source = "terraform-iaac/service/kubernetes"
version = "1.0.4"
app_name = local.name
app_namespace = local.namespace
type = "NodePort"
port_mapping = [for p in var.ports :
{
name = "port-${p}"
internal_port = p
external_port = p
protocol = "TCP"
}]
}
data "kubernetes_service" "service" {
depends_on = [module.service]
metadata {
name = local.name
namespace = local.namespace
}
}
locals {
name = coalesce(var.name, "${var.seal_metadata_service_name}")
namespace = coalesce(var.namespace, var.seal_metadata_namespace_name)
}
\ No newline at end of file \ No newline at end of file
output "service_ip" {
description = "Service IP"
value = data.kubernetes_service.service.spec.0.cluster_ip
}
output "ports" {
description = "Service Ports"
value = var.ports
}
\ No newline at end of file \ No newline at end of file
# @label "Image Name"
# @group "Basic"
variable "image" {
type = string
description = "Docker image name"
}
# @label "Ports"
# @group "Basic"
variable "ports" {
type = list(number)
description = "Service ports to expose"
default = [80]
}
# @label "Environment Variables"
# @group "Basic"
variable "env" {
type = map(string)
description = "Name and value pairs to set as the environment variables"
default = {}
}
# @group "Resources"
# @label "CPU Request"
variable "request_cpu" {
type = string
description = "CPU request. e.g. 0.5, 1, 2"
default = "0.1"
}
# @group "Resources"
# @label "Memory Request"
variable "request_memory" {
type = string
description = "Memory request. e.g. 128Mi, 512Mi, 1Gi, 2Gi, 4Gi"
default = "128Mi"
}
# @group "Resources"
# @label "CPU Limit"
variable "limit_cpu" {
type = string
description = "CPU limit. e.g. 0.5, 1, 2"
default = ""
}
# @group "Resources"
# @label "Memory Limit"
variable "limit_memory" {
type = string
description = "Memory limit. e.g. 128Mi, 512Mi, 1Gi, 2Gi, 4Gi"
default = ""
}
# @label "Namespace"
# @group "Advanced"
variable "namespace" {
type = string
description = "Namespace to deploy. Auto-generated if empty."
default = "default"
}
# @label "Deployment Name"
# @group "Advanced"
variable "name" {
type = string
description = "Name of the deployment resource. Auto-generated if empty."
default = ""
}
# @hidden
variable "seal_metadata_service_name" {
type = string
description = "Seal metadata service name."
default = ""
}
# @hidden
variable "seal_metadata_namespace_name" {
type = string
description = "Seal metadata namespace name."
default = ""
}
# @label "label"
# @group "Advanced"
variable "custom_labels" {
description = "(Optional) Add custom label to pods"
default = null
type = map(string)
}
# @label "probe_port"
# @group "Advanced"
variable "probe_http_port" {
description = "(Optional)http port for probe"
default = "80"
type = string
}
# @label "app_logs_path"
# @group "Advanced"
variable "volume_logs" {
default = "/data/java_log"
}
# @label "app_path"
# @group "Advanced"
variable "app_path" {
default = "/app/soft/java_project"
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!