Giter Club home page Giter Club logo

terraform-kubernetes-expose-service-ingress's Introduction

Terraform Module for exposing a service through an Ingress

This module provides an easy way to deploy pods and to expose them to the Internet by configuring the proper service and ingresses. It has been designed to allow pods with only one container. See examples below.

This module has been designed to work on a K3S cluster with Traefik and files stored locally.

Supported Ingresses

Currently there is only one ingress supported. Feel free to open PR's to add support for others:

  • Traefik

Providers

Name Version
kubernetes n/a

Inputs

Name Description Type Default Required
image Image name and tag to deploy. string n/a yes
name Name used to identify deployed container and all related resources. string n/a yes
annotations Annotations added to some components. Only ingress supported at the moment.
object({
ingress = optional(map(string), {})
service = optional(map(string), {})
})
{
"ingress": {},
"service": {}
}
no
capabilities_add List of capabilities to add to the container. list(string) [] no
container_port Container port where to send to requests to. string "80" no
domains List of domains that should be configured to route traffic from. list(string) [] no
environment_variables Map with environment variables injected to the containers. map(any) {} no
host_port Host port where to send to requests to. string null no
http Whether to create an ingress for HTTP traffic. bool true no
https Whether to create an ingress for HTTPS traffic. bool true no
image_pull_secret Kubernetes secret storing registry credentials. string "" no
namespace Kubernetes namespace where resources must be created. string "default" no
node_selector Node selector to use when deploying the container. map(string) null no
paths Object mapping local paths to container paths map(any) {} no
pod_additional_ports List of additional ports to expose on the pod.
list(object({
name = string
container_port = string
host_port = string
protocol = string
}))
[] no
pvcs Object that contains the list of PVCs to mount in the container
list(object({
name = string
path = string
sub_path = optional(string, "")
read_only = optional(bool, false)
}))
[] no
resources Map with resources limits and requests.
object({
limits = map(string)
requests = map(string)
})
{
"limits": {},
"requests": {}
}
no
service_port Port configured on the service side to receive requests (routed to the container port). string "80" no
supplemental_groups List of supplemental groups to add to the container. list(string) [] no

Outputs

No outputs.

Examples

On the following example we are deploying Wordpress stack with:

  • 1 x Wordpress: All data is stored on a local folder.
  • 1 x MariaDB (MySQL) database. All data is stored on a local folder.
  • 1 x PHPMyAdmin
module "wordpress" {
  source  = "alemuro/expose-service-ingress/kubernetes"
  version = "1.1.0"

  name           = "wordpress-example"
  image          = "wordpress:5"
  domains        = ["wordpress-example.com", "wordpress.example.com"]
  container_port = "80"
  paths = {
    "/opt/k3s/wordpress-example" = "/var/www/html"
  }
  pvcs = {
    name = "pvc-name" 
    path = "/tmp/pvc-example"
  }
  environment_variables = {
    WORDPRESS_DB_HOST     = "database"
    WORDPRESS_DB_USER     = "wordpress-example"
    WORDPRESS_DB_PASSWORD = "r@ndomPa$$w0rd!"
    WORDPRESS_DB_NAME     = "wordpress-example"
  }
}

module "database" {
  source  = "alemuro/expose-service-ingress/kubernetes"
  version = "1.1.0"

  name           = "database"
  image          = "mariadb"
  container_port = "3306"
  service_port   = "3306"
  paths = {
    "/opt/k3s/database" = "/var/lib/mysql"
  }
  environment_variables = {
    MYSQL_ALLOW_EMPTY_PASSWORD = "true"
  }
}

module "phpmyadmin" {
  source  = "alemuro/expose-service-ingress/kubernetes"
  version = "1.1.0"

  name           = "phpmyadmin"
  image          = "phpmyadmin"
  domains        = ["phpmyadmin.wordpress-example.com"]
  container_port = "80"

  environment_variables = {
    PMA_HOST            = "database"
    PMA_PORT            = 3306
    MYSQL_ROOT_PASSWORD = "r@ndomPa$$w0rd!"
  }
}

terraform-kubernetes-expose-service-ingress's People

Contributors

alemuro avatar dgdelahera avatar github-actions[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

dgdelahera

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.