aiwantaozi / terraform-kubernetes-containertask

Deploy containerized Task on Kubernetes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kubernetes Container Task

Terraform module which deploys container task on Kubernetes.

Usage

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

  infrastructure = {
    namespace = "default"
  }

  task = {
    type = periodic
    timeout: 30                              # in seconds
    periodic = {
      cron_expression = "*/1 * * * *"        # cron expression
    }
  }

  containers = [
    {
      image = "alpine"
      execute = {
        command = [
          "/bin/sh", "-c", "date"
        ]
      }
      resources = {
        cpu = 0.1
        memory = 100                         # in megabyte
      }
    }
  ]
}

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_cron_job_v1.task resource
kubernetes_job_v1.task resource
kubernetes_service_v1.tasks resource
terraform_data.replacement resource

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)
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)
}))
})))
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
infrastructure Specify the infrastructure information for deploying.

Examples:
infrastructure:
namespace: string, optional
gpu_vendor: string, optional
object({
namespace = optional(string)
gpu_vendor = optional(string, "nvidia.com")
})
{} no
task Specify the task action, like execution, security and so on.

Examples:
task:
mode: once/periodic
periodic:
cron_expression: string
timezone: string, optional # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
suspend: bool, optional
keep_unfinished: bool, optional # when set to true, if the previous task has not been completed, the new task will not be launched even when the scheduling time arrives
timeout: number, optional
completions: number, optional
parallelism: number, optional
retries: number, optional
cleanup_finished: bool, optional # cleanup the finished task after 5m
keep_failed_process: bool, optional # when set to true, the failed process will not be restarted
fs_group: number, optional
sysctls:
- name: string
value: string
object({
mode = optional(string, "once")
periodic = optional(object({
cron_expression = string
timezone = optional(string)
suspend = optional(bool, false)
keep_unfinished = optional(bool, false)
}))
timeout = optional(number, 300)
completions = optional(number)
parallelism = optional(number)
retries = optional(number, 6)
cleanup_finished = optional(bool, false)
keep_failed_process = optional(bool, true)
fs_group = optional(number)
sysctls = optional(list(object({
name = string
value = string
})))
})
{
"cleanup_finished": false,
"keep_failed_process": true,
"mode": "once",
"retries": 6,
"timeout": 300
}
no

Outputs

Name Description
context The input context, a map, which is used for orchestration.
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.

About

Deploy containerized Task on Kubernetes.

License:Apache License 2.0


Languages

Language:HCL 71.4%Language:Shell 27.0%Language:Makefile 1.6%