Skip to content

Commit

Permalink
feat: remove hetzner load balancer in favour of metallb
Browse files Browse the repository at this point in the history
This gives great flexibility for using UDP ingress, required to run
the unifi controller in the cluster
  • Loading branch information
mrsimonemms committed Nov 16, 2024
1 parent e6508a2 commit ca2bf57
Show file tree
Hide file tree
Showing 25 changed files with 351 additions and 172 deletions.
16 changes: 16 additions & 0 deletions modules/hetzner/networks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ resource "hcloud_firewall" "firewall" {
]
protocol = "udp"
},
{
description = "Allow TCP access to port 80"
source_ips = [
local.global_ipv4_cidr,
local.global_ipv6_cidr,
]
port = 80
},
{
description = "Allow TCP access to port 443"
source_ips = [
local.global_ipv4_cidr,
local.global_ipv6_cidr,
]
port = 443
},
# Direct public access only allowed if single manager node
{
description = "Allow access to Kubernetes API"
Expand Down
1 change: 0 additions & 1 deletion modules/hetzner/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.


variable "firewall_allow_api_access" {
type = list(string)
description = "CIDR range to allow access to the Kubernetes API"
Expand Down
20 changes: 0 additions & 20 deletions modules/kubernetes/.terraform.lock.hcl

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

10 changes: 3 additions & 7 deletions modules/kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.14.0, < 3.0.0 |
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.31.0, < 3.0.0 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.6.2, < 4.0.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_helm"></a> [helm](#provider\_helm) | 2.14.1 |
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.31.0 |
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.2 |

## Modules

Expand All @@ -29,13 +27,14 @@ No modules.
| [helm_release.argocd](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.hcloud_ccm](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.hcloud_csi](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.ingress_nginx](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [kubernetes_config_map_v1.metallb](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/config_map_v1) | resource |
| [kubernetes_namespace_v1.argocd](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace_v1) | resource |
| [kubernetes_namespace_v1.external_secrets](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace_v1) | resource |
| [kubernetes_namespace_v1.metallb](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace_v1) | resource |
| [kubernetes_secret_v1.github_secret](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret_v1) | resource |
| [kubernetes_secret_v1.hcloud](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret_v1) | resource |
| [kubernetes_secret_v1.infisical](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret_v1) | resource |
| [random_integer.ingress_load_balancer_id](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) | resource |
| [kubernetes_nodes.cluster](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/nodes) | data source |

## Inputs

Expand All @@ -54,12 +53,9 @@ No modules.
| <a name="input_hetzner_csi_driver_version"></a> [hetzner\_csi\_driver\_version](#input\_hetzner\_csi\_driver\_version) | Tag of the CSI driver to use - defaults to latest | `string` | `null` | no |
| <a name="input_infisical_client_id"></a> [infisical\_client\_id](#input\_infisical\_client\_id) | Infisical client ID | `string` | n/a | yes |
| <a name="input_infisical_client_secret"></a> [infisical\_client\_secret](#input\_infisical\_client\_secret) | Infisical client secret | `string` | n/a | yes |
| <a name="input_ingress_nginx_version"></a> [ingress\_nginx\_version](#input\_ingress\_nginx\_version) | Version of Ingress Nginx to install - defaults to latest | `string` | `null` | no |
| <a name="input_k3s_cluster_cidr"></a> [k3s\_cluster\_cidr](#input\_k3s\_cluster\_cidr) | CIDR used for the k3s cluster | `string` | `"10.244.0.0/16"` | no |
| <a name="input_kube_context"></a> [kube\_context](#input\_kube\_context) | Kubernetes context to use | `string` | `"default"` | no |
| <a name="input_kubeconfig"></a> [kubeconfig](#input\_kubeconfig) | Kubeconfig for the cluster | `string` | n/a | yes |
| <a name="input_load_balancer_location"></a> [load\_balancer\_location](#input\_load\_balancer\_location) | Location to use for the load balancer | `string` | n/a | yes |
| <a name="input_load_balancer_type"></a> [load\_balancer\_type](#input\_load\_balancer\_type) | Type of load balancer to use | `string` | `"lb11"` | no |

## Outputs

Expand Down
16 changes: 0 additions & 16 deletions modules/kubernetes/files/ingress-nginx.yaml

This file was deleted.

47 changes: 0 additions & 47 deletions modules/kubernetes/ingress-nginx.tf

This file was deleted.

51 changes: 51 additions & 0 deletions modules/kubernetes/metallb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2024 Simon Emms <[email protected]>
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.

data "kubernetes_nodes" "cluster" {
depends_on = [
helm_release.hcloud_ccm,
helm_release.hcloud_csi,
]
}

resource "kubernetes_namespace_v1" "metallb" {
metadata {
name = "metallb-system"
}
}

resource "kubernetes_config_map_v1" "metallb" {
metadata {
name = "nodes"
namespace = kubernetes_namespace_v1.metallb.metadata[0].name
}

data = {
resource = yamlencode({
apiVersion = "metallb.io/v1beta1"
kind = "IPAddressPool"
metadata = {
name = "nodes"
namespace = kubernetes_namespace_v1.metallb.metadata[0].name
}
spec = {
addresses = [
for n in flatten(data.kubernetes_nodes.cluster.nodes[*].status[*].addresses) : "${n.address}/32" if n.type == "ExternalIP"
]
}
})
}

immutable = false
}
4 changes: 0 additions & 4 deletions modules/kubernetes/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ terraform {
source = "hashicorp/kubernetes"
version = ">= 2.31.0, < 3.0.0"
}
random = {
source = "hashicorp/random"
version = ">= 3.6.2, < 4.0.0"
}
}
}

Expand Down
17 changes: 0 additions & 17 deletions modules/kubernetes/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ variable "kube_context" {
default = "default"
}

variable "ingress_nginx_version" {
type = string
description = "Version of Ingress Nginx to install - defaults to latest"
default = null
}

variable "infisical_client_id" {
type = string
description = "Infisical client ID"
Expand All @@ -111,14 +105,3 @@ variable "infisical_client_secret" {
description = "Infisical client secret"
sensitive = true
}

variable "load_balancer_location" {
type = string
description = "Location to use for the load balancer"
}

variable "load_balancer_type" {
type = string
description = "Type of load balancer to use"
default = "lb11"
}
24 changes: 24 additions & 0 deletions registry/clusters/dev/components/ingress-nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: ingress-nginx-components
namespace: argocd
annotations:
argocd.argoproj.io/sync-wave: "20"
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: https://github.com/mrsimonemms/infrastructure
path: registry/components/ingress-nginx
targetRevision: HEAD
destination:
server: https://kubernetes.default.svc
namespace: ingress-nginx
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
24 changes: 24 additions & 0 deletions registry/clusters/dev/components/metallb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: metallb-components
namespace: argocd
annotations:
argocd.argoproj.io/sync-wave: "10"
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: https://github.com/mrsimonemms/infrastructure
path: registry/components/metallb
targetRevision: HEAD
destination:
server: https://kubernetes.default.svc
namespace: metallb-system
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
24 changes: 24 additions & 0 deletions registry/clusters/prod/components/ingress-nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: ingress-nginx-components
namespace: argocd
annotations:
argocd.argoproj.io/sync-wave: "20"
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: https://github.com/mrsimonemms/infrastructure
path: registry/components/ingress-nginx
targetRevision: HEAD
destination:
server: https://kubernetes.default.svc
namespace: ingress-nginx
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
24 changes: 24 additions & 0 deletions registry/clusters/prod/components/metallb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: metallb-components
namespace: argocd
annotations:
argocd.argoproj.io/sync-wave: "10"
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: https://github.com/mrsimonemms/infrastructure
path: registry/components/metallb
targetRevision: HEAD
destination:
server: https://kubernetes.default.svc
namespace: metallb-system
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
33 changes: 33 additions & 0 deletions registry/components/ingress-nginx/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: ingress-nginx
namespace: argocd
annotations:
argocd.argoproj.io/sync-wave: "10"
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
chart: ingress-nginx
repoURL: https://kubernetes.github.io/ingress-nginx
targetRevision: 4.11.3
helm:
valuesObject:
controller:
# Not strictly necessary, but feels safer running on all nodes
kind: DaemonSet
config:
use-proxy-protocol: false
extraArgs:
enable-ssl-passthrough: true
destination:
server: https://kubernetes.default.svc
namespace: ingress-nginx
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
5 changes: 5 additions & 0 deletions registry/components/ingress-nginx/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- application.yaml
- namespace.yaml
Loading

0 comments on commit ca2bf57

Please sign in to comment.