Skip to content

Commit

Permalink
feat(kubernetes): install cilium to the cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Jun 25, 2024
1 parent cc5f67e commit 3b7d4bd
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 3 deletions.
20 changes: 20 additions & 0 deletions modules/kubernetes/.terraform.lock.hcl

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

11 changes: 9 additions & 2 deletions modules/kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@
| Name | Version |
|------|---------|
| <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 |

## Providers

No providers.
| Name | Version |
|------|---------|
| <a name="provider_helm"></a> [helm](#provider\_helm) | 2.14.0 |

## Modules

No modules.

## Resources

No resources.
| Name | Type |
|------|------|
| [helm_release.cilium](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_cilium_version"></a> [cilium\_version](#input\_cilium\_version) | Version of Cilium to use - 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 |

Expand Down
35 changes: 35 additions & 0 deletions modules/kubernetes/cilium.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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.

resource "helm_release" "cilium" {
chart = "cilium"
name = "cilium"
atomic = true
cleanup_on_fail = true
namespace = "kube-system"
repository = "https://helm.cilium.io"
reset_values = true
version = var.cilium_version
wait = true

set {
name = "ipv4NativeRoutingCIDR"
value = var.k3s_cluster_cidr
}

set {
name = "ipam.mode"
value = "kubernetes"
}
}
13 changes: 13 additions & 0 deletions modules/kubernetes/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,26 @@
terraform {
required_version = ">= 1.0.0"
required_providers {
helm = {
source = "hashicorp/helm"
version = ">= 2.14.0, < 3.0.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.31.0, < 3.0.0"
}
}
}

provider "helm" {
kubernetes {
host = local.kubeconfig_by_context[var.kube_context].server
client_certificate = base64decode(local.kubeconfig_by_context[var.kube_context].client-certificate-data)
client_key = base64decode(local.kubeconfig_by_context[var.kube_context].client-key-data)
cluster_ca_certificate = base64decode(local.kubeconfig_by_context[var.kube_context].certificate-authority-data)
}
}

provider "kubernetes" {
host = local.kubeconfig_by_context[var.kube_context].server
client_certificate = base64decode(local.kubeconfig_by_context[var.kube_context].client-certificate-data)
Expand Down
13 changes: 13 additions & 0 deletions modules/kubernetes/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.


variable "cilium_version" {
type = string
description = "Version of Cilium to use - defaults to latest"
default = null
}

variable "k3s_cluster_cidr" {
type = string
description = "CIDR used for the k3s cluster"
default = "10.244.0.0/16"
}

variable "kubeconfig" {
type = string
description = "Kubeconfig for the cluster"
Expand Down
20 changes: 20 additions & 0 deletions stacks/dev/kubernetes/.terraform.lock.hcl

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

3 changes: 2 additions & 1 deletion stacks/dev/kubernetes/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ dependency "hetzner" {
}

inputs = {
kubeconfig = dependency.hetzner.outputs.kubeconfig
k3s_cluster_cidr = dependency.hetzner.outputs.k3s_cluster_cidr
kubeconfig = dependency.hetzner.outputs.kubeconfig
}

0 comments on commit 3b7d4bd

Please sign in to comment.