Skip to content

Commit

Permalink
feat: add eks demo app (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-acosta authored Dec 23, 2024
1 parent 5ce9853 commit 610fe26
Show file tree
Hide file tree
Showing 23 changed files with 411 additions and 1 deletion.
13 changes: 13 additions & 0 deletions nuon/components/certificate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name = "certificate"
type = "terraform_module"
terraform_version = "1.7.5"
[public_repo]
repo = "nuonco/guides"
directory = "aws-eks-tutorial/components/certificate"
branch = "main"
[[var]]
name = "domain_name"
value = "{{.nuon.install.inputs.service_name}}.{{.nuon.install.sandbox.outputs.public_domain.name}}"
[[var]]
name = "zone_id"
value = "{{.nuon.install.sandbox.outputs.public_domain.zone_id}}"
12 changes: 12 additions & 0 deletions nuon/components/helm_chart.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name = "helm_chart"
type = "helm_chart"
chart_name = "httpbin"
[public_repo]
repo = "nuonco/guides"
directory = "aws-eks-tutorial/components/helm-chart"
branch = "main"
[values]
"image.repository" = "{{.nuon.components.httpbin.image.repository.uri}}"
"image.tag" = "{{.nuon.components.httpbin.image.tag}}"
"api.nlbs.public_domain_certificate" = "{{.nuon.components.certificate.outputs.public_domain_certificate_arn}}"
"api.nlbs.public_domain" = "{{.nuon.install.inputs.service_name}}.{{.nuon.install.sandbox.outputs.public_domain.name}}"
3 changes: 2 additions & 1 deletion nuon/installer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ post_install_markdown = """
apps = [
'appp8wgwu816ypus1aadcg875s',
'apparhowpzogsf4emsproqbutc',
'ecs-demo'
'ecs-demo',
'eks-demo'
]
27 changes: 27 additions & 0 deletions nuon/nuon.eks-demo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#:schema https://api.nuon.co/v1/general/config-schema

version = "v1"
description = "Deploy an app to EKS in it's own VPC."
display_name = "Stand-Alone EKS Deployment"

[inputs]
source = "app_inputs.toml"

[runner]
runner_type = "aws-eks"

[sandbox]
terraform_version = "1.7.5"
[sandbox.public_repo]
directory = "aws-eks"
repo = "nuonco/sandboxes"
branch = "main"

[[components]]
source = "components/container_image.toml"

[[components]]
source = "components/certificate.toml"

[[components]]
source = "components/helm_chart.toml"
25 changes: 25 additions & 0 deletions src/certificate/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/certificate/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module "certificate" {
source = "terraform-aws-modules/acm/aws"
version = "~> 4.0"

domain_name = var.domain_name
zone_id = var.zone_id
validation_method = "DNS"
wait_for_validation = false
}
3 changes: 3 additions & 0 deletions src/certificate/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "public_domain_certificate_arn" {
value = module.certificate.acm_certificate_arn
}
1 change: 1 addition & 0 deletions src/certificate/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
provider "aws" {}
7 changes: 7 additions & 0 deletions src/certificate/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "domain_name" {
type = string
}

variable "zone_id" {
type = string
}
12 changes: 12 additions & 0 deletions src/certificate/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_version = ">= 1.7.5"

backend "s3" {}

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0"
}
}
}
9 changes: 9 additions & 0 deletions src/helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: v2
name: api
description: A helm chart for running an HTTPS API.
type: application
version: v0.0.1
appVersion: "0.0.1"

dependencies: []
44 changes: 44 additions & 0 deletions src/helm-chart/templates/api_alb.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "common.fullname" . }}-api
namespace: {{ .Release.Namespace }}
labels:
{{- include "common.apiLabels" . | nindent 4 }}
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}]'
alb.ingress.kubernetes.io/certificate-arn: {{ .Values.api.nlbs.public_domain_certificate }}
alb.ingress.kubernetes.io/aws-load-balancer-ssl-ports: https
alb.ingress.kubernetes.io/healthcheck-path: /livez
external-dns.alpha.kubernetes.io/hostname: {{ .Values.api.nlbs.public_domain }}
spec:
ingressClassName: alb
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ include "common.fullname" . }}-api
port:
name: http
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "common.fullname" . }}-api
namespace: {{ .Release.Namespace }}
labels:
{{- include "common.apiLabels" . | nindent 4 }}
spec:
selector:
{{- include "common.apiSelectorLabels" . | nindent 4 }}
type: ClusterIP
ports:
- name: http
port: {{ .Values.api.port }}
targetPort: http
44 changes: 44 additions & 0 deletions src/helm-chart/templates/api_deployment.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "common.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "common.apiLabels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "common.apiSelectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "common.apiSelectorLabels" . | nindent 8 }}
spec:
serviceAccountName: {{ .Values.serviceAccount.name }}
automountServiceAccountToken: true
containers:
- name: {{ include "common.fullname" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
ports:
- name: http
containerPort: {{ .Values.api.port }}
protocol: TCP
readinessProbe:
httpGet:
path: {{ .Values.api.readiness_probe}}
port: http
livenessProbe:
httpGet:
path: {{ .Values.api.liveness_probe}}
port: http
resources:
limits:
cpu: 100m
memory: 256Mi
requests:
cpu: 100m
memory: 256Mi
envFrom:
- configMapRef:
name: {{ include "common.fullname" . }}
28 changes: 28 additions & 0 deletions src/helm-chart/templates/api_hpa.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "common.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "common.apiLabels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "common.fullname" . }}
minReplicas: {{ .Values.api.autoscaling.minReplicas | default 1 }}
maxReplicas: {{ .Values.api.autoscaling.maxReplicas | default 3 }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.api.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.api.autoscaling.targetMemoryUtilizationPercentage }}
11 changes: 11 additions & 0 deletions src/helm-chart/templates/cluster_role.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.serviceAccount.name }}
labels:
{{- include "common.labels" . | nindent 4 }}
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
10 changes: 10 additions & 0 deletions src/helm-chart/templates/config_map.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "common.fullname" . }}
namespace: {{ .Release.Namespace | quote | default "default"}}
labels:
{{- include "common.labels" . | nindent 4 }}
data:
{{- .Values.env | toYaml | nindent 2 }}
14 changes: 14 additions & 0 deletions src/helm-chart/templates/lib/_api_labels.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- define "common.apiLabels" -}}
app: {{ .Release.Name }}
helm.sh/chart: {{ include "common.chart" . }}
{{ include "common.apiSelectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{- define "common.apiSelectorLabels" -}}
app.kubernetes.io/name: {{ include "common.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
12 changes: 12 additions & 0 deletions src/helm-chart/templates/lib/_labels.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- define "common.labels" -}}
app: {{ .Release.Name | quote }}
helm.sh/chart: {{ include "common.chart" . }}
{{ include "common.selectorLabels" . }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{- define "common.selectorLabels" -}}
app.kubernetes.io/name: {{ include "common.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
42 changes: 42 additions & 0 deletions src/helm-chart/templates/lib/_names.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "common.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "common.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | 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 "common.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 the name of the service account to use
*/}}
{{- define "common.serviceAccountName" -}}
{{- if .Values.serviceAccount.enabled }}
{{- default (include "common.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
8 changes: 8 additions & 0 deletions src/helm-chart/templates/namespace.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: api
namespace: {{ .Release.Namespace }}
labels:
{{- include "common.labels" . | nindent 4 }}
11 changes: 11 additions & 0 deletions src/helm-chart/templates/role.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.serviceAccount.name }}
labels:
{{- include "common.labels" . | nindent 4 }}
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
Loading

0 comments on commit 610fe26

Please # to comment.