-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds 2 modules, deploy k8s-at-home helm charts and Treafik Ingress CRDs.
- Loading branch information
1 parent
d2b3906
commit 4acb775
Showing
12 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
resource "kubernetes_namespace" "namespace" { | ||
count = var.create_namespace ? 1 : 0 | ||
metadata { | ||
name = var.namespace | ||
} | ||
} | ||
|
||
locals { | ||
values = yamlencode( | ||
merge(tomap({ | ||
env = merge({ | ||
TZ = var.timezone, | ||
}, var.helm_envs) | ||
}), | ||
var.helm_values, | ||
)) | ||
} | ||
|
||
resource "helm_release" "k8s" { | ||
repository = "https://k8s-at-home.com/charts/" | ||
name = var.name | ||
chart = var.chart | ||
version = var.chart_version | ||
namespace = var.namespace | ||
|
||
values = [ | ||
local.values, | ||
] | ||
|
||
depends_on = [ | ||
kubernetes_namespace.namespace, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
variable "chart_version" { | ||
description = "The version of the helm chart to use. Note that this is different from the app/container version." | ||
type = string | ||
} | ||
|
||
variable "create_namespace" { | ||
description = "Create namespace or deploy to existing." | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "namespace" { | ||
description = "Which Kubernetes Namespace to deploy the chart into." | ||
type = string | ||
default = "default" | ||
} | ||
|
||
variable "name" { | ||
description = "Name of chart deployment." | ||
type = string | ||
} | ||
|
||
variable "chart" { | ||
description = "Name of k8s-at-home chart." | ||
type = string | ||
} | ||
|
||
variable "timezone" { | ||
description = "Timezone for the service." | ||
type = string | ||
default = "US/Pacific" | ||
} | ||
|
||
variable "helm_envs" { | ||
description = "Map of envs for helm chart. Merged with timezone." | ||
type = any | ||
default = {} | ||
} | ||
|
||
variable "helm_values" { | ||
description = "Additional helm values to pass in as a map. Timezone will be included already." | ||
type = any | ||
default = {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
kubernetes = { | ||
source = "hashicorp/kubernetes" | ||
version = "~> 1.0" | ||
} | ||
helm = { | ||
source = "hashicorp/helm" | ||
version = "~> 2.0" | ||
} | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 3.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
resource "helm_release" "k8s" { | ||
name = "${var.name}-traefik-ingress" | ||
chart = "${path.module}/traefik-ingress" | ||
namespace = var.namespace | ||
|
||
set { | ||
name = "namespace" | ||
value = var.namespace | ||
} | ||
set { | ||
name = "name" | ||
value = var.name | ||
} | ||
set { | ||
name = "certResolver" | ||
value = var.cert_resolver | ||
} | ||
set { | ||
name = "host" | ||
value = var.host | ||
} | ||
set { | ||
name = "serviceName" | ||
value = var.service | ||
} | ||
set { | ||
name = "servicePort" | ||
value = var.service_port | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Patterns to ignore when building packages. | ||
# This supports shell glob matching, relative path matching, and | ||
# negation (prefixed with !). Only one pattern per line. | ||
.DS_Store | ||
# Common VCS dirs | ||
.git/ | ||
.gitignore | ||
.bzr/ | ||
.bzrignore | ||
.hg/ | ||
.hgignore | ||
.svn/ | ||
# Common backup files | ||
*.swp | ||
*.bak | ||
*.tmp | ||
*~ | ||
# Various IDEs | ||
.project | ||
.idea/ | ||
*.tmproj | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
apiVersion: v2 | ||
name: traefik-ingress | ||
description: A Helm chart for Kubernetes | ||
type: application | ||
version: 0.0.4 | ||
appVersion: "2.6.0" |
32 changes: 32 additions & 0 deletions
32
modules/k8s/traefik-ingress/traefik-ingress/templates/_helpers.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{/* vim: set filetype=mustache: */}} | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "traefik-ingress.name" -}} | ||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} | ||
{{- end -}} | ||
|
||
{{/* | ||
Create a default fully qualified app name. | ||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | ||
If release name contains chart name it will be used as a full name. | ||
*/}} | ||
{{- define "traefik-ingress.fullname" -}} | ||
{{- if .Values.fullnameOverride -}} | ||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} | ||
{{- else -}} | ||
{{- $name := default .Chart.Name .Values.nameOverride -}} | ||
{{- if contains $name .Release.Name -}} | ||
{{- .Release.Name | trunc 63 | trimSuffix "-" -}} | ||
{{- else -}} | ||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{/* | ||
Create chart name and version as used by the chart label. | ||
*/}} | ||
{{- define "traefik-ingress.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} | ||
{{- end -}} |
10 changes: 10 additions & 0 deletions
10
modules/k8s/traefik-ingress/traefik-ingress/templates/ingress.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: {{ .Values.name }} | ||
annotations: | ||
kubernetes.io/ingress.class: traefik | ||
spec: | ||
rules: | ||
- host: {{ .Values.host }} |
17 changes: 17 additions & 0 deletions
17
modules/k8s/traefik-ingress/traefik-ingress/templates/ingressroute.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: traefik.containo.us/v1alpha1 | ||
kind: IngressRoute | ||
metadata: | ||
name: {{ .Values.name }} | ||
spec: | ||
entryPoints: | ||
- websecure | ||
tls: | ||
certResolver: {{ .Values.certResolver }} | ||
routes: | ||
- match: Host(`{{ .Values.host }}`) | ||
kind: Rule | ||
services: | ||
- name: {{ .Values.serviceName }} | ||
kind: Service | ||
namespace: {{ .Values.namespace }} | ||
port: {{ .Values.servicePort }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
variable "namespace" { | ||
description = "Which Kubernetes Namespace to deploy the traefik ingress CRDs into." | ||
type = string | ||
default = "default" | ||
} | ||
|
||
variable "name" { | ||
description = "Name to use for Traefik ingress release. Must be unique per namespace." | ||
type = string | ||
} | ||
|
||
variable "host" { | ||
description = "Traefik host match." | ||
type = string | ||
} | ||
|
||
variable "cert_resolver" { | ||
description = "Name of cert resolver to use to generate TLS cert for this hostname." | ||
type = string | ||
} | ||
|
||
variable "service" { | ||
description = "Kubernetes service name to route host match rule to." | ||
type = string | ||
} | ||
|
||
variable "service_port" { | ||
description = "Kubernetes service port to route to." | ||
type = number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
kubernetes = { | ||
source = "hashicorp/kubernetes" | ||
version = "~> 1.0" | ||
} | ||
helm = { | ||
source = "hashicorp/helm" | ||
version = "~> 2.0" | ||
} | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 3.0" | ||
} | ||
} | ||
} |