Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable https and ambassador routing #80

Merged
merged 1 commit into from Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions ambassador_mappings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
apiVersion: getambassador.io/v2
kind: TCPMapping
metadata:
name: hono-http-adapter
spec:
port: 18080
service: hono-adapter-http-vertx:8080
---
apiVersion: getambassador.io/v2
kind: TCPMapping
metadata:
name: hono-mqtt-adapter
spec:
port: 1883
service: hono-adapter-mqtt-vertx:1883
---
apiVersion: getambassador.io/v2
kind: TCPMapping
metadata:
name: hono-device-registry
spec:
port: 28080
service: hono-service-device-registry-ext:28080
---
apiVersion: getambassador.io/v2
kind: TCPMapping
metadata:
name: hono-dispatch-router
spec:
port: 15671
service: hono-service-device-registry-ext:15671
---
apiVersion: getambassador.io/v2
kind: TCPMapping
metadata:
name: prometheus-grafana
spec:
port: 3000
prefix: /grafana/
host: smaddis.westeurope.cloudapp.azure.com
service: prometheus-grafana:3000
---
apiVersion: getambassador.io/v2
kind: TCPMapping
metadata:
name: jaeger-operator-jaeger-query
spec:
port: 16686
prefix: /jaeger/
host: smaddis.westeurope.cloudapp.azure.com
service: jaeger-operator-jaeger-query:16686
---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: acme-challenge-mapping
spec:
prefix: /.well-known/acme-challenge/
rewrite: ""
service: acme-challenge-service
---
apiVersion: v1
kind: Service
metadata:
name: acme-challenge-service
spec:
ports:
- port: 80
targetPort: 8089
selector:
acme.cert-manager.io/http01-solver: "true"
31 changes: 31 additions & 0 deletions modules/container_deployment/ambassador_values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
enableAES: false
replicaCount: 1
service:
ports:
- name: http
port: 80
targetPort: 8080
- name: https
port: 443
targetPort: 8443
- name: mqtt-adapter
port: 1883
targetPort: 1883
- name: http-adapter
port: 18080
targetPort: 18080
- name: device-registry
port: 28080
targetPort: 28080
- name: dispatch-router
port: 5671
targetPort: 15671
- name: grafana
port: 3000
targetPort: 3000
- name: jaeger
port: 16686
targetPort: 16686
- name: prometheus
port: 9090
targetPort: 9090
2 changes: 1 addition & 1 deletion modules/container_deployment/jaeger_values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jaeger:
create: true
metadata:
name: "simple"
name: "simple"
47 changes: 39 additions & 8 deletions modules/container_deployment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ resource "helm_release" "mongodb" {
name = "auth.username"
value = var.mongodb_username
}

}

# https://github.com/eclipse/packages/tree/83abeda25c0efd9446713aaa828ff4177ce4b27b/charts/hono
Expand All @@ -55,13 +54,17 @@ resource "helm_release" "hono" {
}
}

# https://github.com/kubernetes/ingress-nginx/tree/f5cfd5730c4b296c87fbc531c83a6e4f33483b75/charts/ingress-nginx
resource "helm_release" "ingress-nginx" {
name = "ingress-nginx"
# https://github.com/datawire/ambassador-chart/tree/c540b0d9e91f7def8a7d9b99217cb62cfe3014fb
resource "helm_release" "ambassador" {
name = "ambassador"

repository = "https://getambassador.io"
chart = "ambassador"
version = "~> 6.6.0"
values = [
file("${path.module}/ambassador_values.yaml")
]

repository = "https://kubernetes.github.io/ingress-nginx"
chart = "ingress-nginx"
version = "~> 3.29.0"
}
# https://github.com/jaegertracing/helm-charts/tree/72db111cf61e9d85f75b74a8398f2c98da0bc9d3/charts/jaeger-operator
resource "helm_release" "jaeger-operator" {
Expand All @@ -75,6 +78,20 @@ resource "helm_release" "jaeger-operator" {
]
}

# https://github.com/jetstack/cert-manager/tree/614438aed00e1060870b273f2238794ef69b60ab/deploy/charts/cert-manager
resource "helm_release" "cert-manager" {
name = "cert-manager"

repository = "https://charts.jetstack.io"
chart = "cert-manager"
version = "~> 1.3.1"

set {
name = "installCRDs"
value = "true"
}
}

# Import Hono dashboards to Grafana. Basically copied from Hono Helm charts.
# How to import dashboards: https://github.com/grafana/helm-charts/tree/3327b6c7e9417f345774fd5a5eb46dd639ebeeec/charts/grafana#import-dashboards
# Sidecar method: https://github.com/grafana/helm-charts/tree/3327b6c7e9417f345774fd5a5eb46dd639ebeeec/charts/grafana#sidecar-for-dashboards
Expand Down Expand Up @@ -108,4 +125,18 @@ resource "helm_release" "kube-prometheus-stack" {
values = [
file("${path.module}/prom_values.yaml")
]
}
}

/*
# Works if kubeconfig is properly configured (az aks get-credentials not needed after terraform apply is done)
# Move tls.yaml and ambassador_mappings.yaml to modules/container_deployment directory
# Terraform should apply them automatically after it's done creating the cluster
# If it fails, it doesn't affect anything and you can apply them manually
resource "null_resource" "kubectl_apply" {
triggers = {
k8s_yaml_contents = file("${path.module}/ambassador_mappings.yaml")
}
provisioner "local-exec" {
command = "kubectl apply -f ${path.module}/ambassador_mappings.yaml && kubectl apply -f ${path.module}/tls.yaml"
}
}*/
16 changes: 14 additions & 2 deletions modules/container_deployment/prom_values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
grafana:
service:
type: "ClusterIP"
ingress:
enabled: true
ingressClassName: nginx
hosts:
- smaddis.westeurope.cloudapp.azure.com
path: /grafana/
grafana.ini:
server:
domain: smaddis.westeurope.cloudapp.azure.com
root_url: "%(protocol)s://%(domain)s:%(http_port)s/grafana/"
serve_from_sub_path: true
http_port: 3000
dashboardProviders:
dashboardproviders.yaml:
apiVersion: 1
Expand All @@ -11,8 +25,6 @@ grafana:
editable: false
options:
path: /etc/secrets/dashboards/
service:
type: "LoadBalancer"
extraSecretMounts:
- name: dashboards-secret-mount
secretName: grafana-hono-dashboards
Expand Down
2 changes: 1 addition & 1 deletion modules/k8s/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ resource "kubernetes_persistent_volume_claim" "example" {
}
}

#resource "kubernetes_namespace" "hono" {
# resource "kubernetes_namespace" "hono" {
# metadata {
# name = "hono"
# }
Expand Down
61 changes: 61 additions & 0 deletions tls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: amb-ingress
annotations:
kubernetes.io/ingress.class: ambassador
spec:
tls:
- hosts:
- smaddis.westeurope.cloudapp.azure.com
secretName: ambassador-certs
rules:
- host: smaddis.westeurope.cloudapp.azure.com
http:
paths:
- path: /grafana/
pathType: Prefix
backend:
service:
name: prometheus-grafana
port:
number: 80
- path: /jaeger/
pathType: Prefix
backend:
service:
name: jaeger-operator-jaeger-query
port:
number: 16686
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
email: [email protected]
server: https://acme-v02.api.letsencrypt.org/directory
privateKeySecretRef:
name: letsencrypt-prod
solvers:
- http01:
ingress:
class: nginx
selector: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: ambassador-certs
# cert-manager will put the resulting Secret in the same Kubernetes
# namespace as the Certificate. You should create the certificate in
# whichever namespace you want to configure a Host.
namespace: default
spec:
secretName: ambassador-certs
issuerRef:
name: letsencrypt-prod
kind: ClusterIssuer
dnsNames:
- smaddis.westeurope.cloudapp.azure.com