Skip to content

walrus-catalog/terraform-kubernetes-containerservice

Repository files navigation

Kubernetes Container Service

Terraform module which deploys container service on Kubernetes.

Usage

module "example" {
  source = "..."

  infrastructure = {
    namespace = "default"
  }

  deployment = {
    timeout  = 30                     # in seconds
    replicas = 1
    rolling = {
      max_surge       = 0.25         # 0 < max_surge < 1
      max_unavailable = 0.25         # 0 < max_unavailable < 1
    }
  }

  containers = [
    {
      image     = "nginx:alpine"
      resources = {
        cpu    = 0.1
        memory = 100                 # in megabyte
      }
      ports = [
        {
          internal = 80
          external = 80
        }
      ]
      checks = [
        {
          delay = 10
          type  = "http"
          http = {
            port = 80
          }
        }
        {
          delay    = 10
          teardown = true
          type     = "http"
          http = {
            port = 80
          }
        }
      ]
    }
  ]
}

Examples

Contributing

Please read our contributing guide if you're interested in contributing to Walrus template.

Requirements

Name Version
terraform >= 1.0
kubernetes >= 2.23.0

Providers

Name Version
kubernetes >= 2.23.0
terraform n/a

Modules

No modules.

Resources

Name Type
kubernetes_config_map_v1.ephemeral_files resource
kubernetes_deployment_v1.deployment resource
kubernetes_service_v1.service resource
terraform_data.replacement resource
kubernetes_nodes.pool data source

Inputs

Name Description Type Default Required
containers Specify the container items to deploy.

Examples:
containers:
- profile: init/run
image: string
execute:
working_dir: string, optional
command: list(string), optional
args: list(string), optional
readonly_rootfs: bool, optional
as_user: number, optional
as_group: number, optional
privileged: bool, optional
resources:
cpu: number, optional # in oneCPU, i.e. 0.25, 0.5, 1, 2, 4
memory: number, optional # in megabyte
gpu: number, optional # in oneGPU, i.e. 1, 2, 4
envs:
- name: string
value: string, optional
value_refer:
schema: string
params: map(any)
files:
- path: string
mode: string, optional
accept_changed: bool, optional # accpet changed
content: string, optional
content_refer:
schema: string
params: map(any)
mounts:
- path: string
readonly: bool, optional
subpath: string, optional
volume: string, optional # shared between containers if named, otherwise exclusively by this container
volume_refer:
schema: string
params: map(any)
ports:
- internal: number
external: number, optional
protocol: tcp/udp
schema: string, optional
checks:
- type: execute/tcp/http/https
delay: number, optional
interval: number, optional
timeout: number, optional
retries: number, optional
teardown: bool, optional
execute:
command: list(string)
tcp:
port: number
http:
port: number
headers: map(string), optional
path: string, optional
https:
port: number
headers: map(string), optional
path: string, optional
list(object({
profile = optional(string, "run")
image = string
execute = optional(object({
working_dir = optional(string)
command = optional(list(string))
args = optional(list(string))
readonly_rootfs = optional(bool, false)
as_user = optional(number)
as_group = optional(number)
privileged = optional(bool, false)
}))
resources = optional(object({
cpu = optional(number, 0.25)
memory = optional(number, 256)
gpu = optional(number, 0)
}))
envs = optional(list(object({
name = string
value = optional(string)
value_refer = optional(object({
schema = string
params = map(any)
}))
})))
files = optional(list(object({
path = string
mode = optional(string, "0644")
accept_changed = optional(bool, false)
content = optional(string)
content_refer = optional(object({
schema = string
params = map(any)
}))
})))
mounts = optional(list(object({
path = string
readonly = optional(bool, false)
subpath = optional(string)
volume = optional(string)
volume_refer = optional(object({
schema = string
params = map(any)
}))
})))
ports = optional(list(object({
internal = number
external = optional(number)
protocol = optional(string, "tcp")
schema = optional(string)
})))
checks = optional(list(object({
type = string
delay = optional(number, 0)
interval = optional(number, 10)
timeout = optional(number, 1)
retries = optional(number, 1)
teardown = optional(bool, false)
execute = optional(object({
command = list(string)
}))
tcp = optional(object({
port = number
}))
http = optional(object({
port = number
headers = optional(map(string))
path = optional(string, "/")
}))
https = optional(object({
port = number
headers = optional(map(string))
path = optional(string, "/")
}))
})))
}))
n/a yes
context Receive contextual information. When Walrus deploys, Walrus will inject specific contextual information into this field.

Examples:
context:
project:
name: string
id: string
environment:
name: string
id: string
resource:
name: string
id: string
map(any) {} no
deployment Specify the deployment action, like scaling, scheduling, security and so on.

Examples:
deployment:
timeout: number, optional
replicas: number, optional
rolling:
max_surge: number, optional # in fraction, i.e. 0.25, 0.5, 1
max_unavailable: number, optional # in fraction, i.e. 0.25, 0.5, 1
fs_group: number, optional
sysctls:
- name: string
value: string
object({
timeout = optional(number, 300)
replicas = optional(number, 1)
rolling = optional(object({
max_surge = optional(number, 0.25)
max_unavailable = optional(number, 0.25)
}))
fs_group = optional(number)
sysctls = optional(list(object({
name = string
value = string
})))
})
{
"replicas": 1,
"rolling": {
"max_surge": 0.25,
"max_unavailable": 0.25
},
"timeout": 300
}
no
infrastructure Specify the infrastructure information for deploying.

Examples:
infrastructure:
namespace: string, optional
gpu_vendor: string, optional
domain_suffix: string, optional
service_type: string, optional
object({
namespace = optional(string)
gpu_vendor = optional(string, "nvidia.com")
domain_suffix = optional(string, "cluster.local")
service_type = optional(string, "NodePort")
})
{} no

Outputs

Name Description
address The address, a string only has host, might be a comma separated string or a single string.
connection The connection, a string combined host and port, might be a comma separated string or a single string.
context The input context, a map, which is used for orchestration.
endpoints The endpoints, a string map, the key is the name, and the value is the URL.
ports The port list of the service.
refer The refer, a map, including hosts, ports and account, which is used for dependencies or collaborations.

License

Copyright (c) 2023 Seal, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at LICENSE file for details.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.