-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore: k3s tf module & spectrum module cleanup && cilium l2 support #19
Changes from 11 commits
95c7d0a
4120a3c
832a546
e8d90a1
9550d2e
9f99172
bed45d5
0e1650a
67a5080
ce97b59
6bfaa54
4f9891a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
.direnv | ||
kubeconfig | ||
talosconfig | ||
provider_project/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Kubernetes cluster based on k3s | ||
|
||
This example deploys *k3s based* Kubernetes cluster on a specific host. | ||
|
||
### Requirements | ||
- installed [**Terraform**](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) on your laptop | ||
- installed [**autok3s**](https://github.com/cnrancher/autok3s?tab=readme-ov-file#quick-start-tldr) on your laptop | ||
- target server accessible via `ssh` | ||
|
||
### Instruction | ||
- Copy files in this directory to your Fluence related *provider* directory | ||
- Update values with your own in `config.tf` file | ||
``` | ||
locals { | ||
server_name = "example" | ||
server_ip_address = "1.1.1.1.1" | ||
ssh_key = "~/.ssh/key" | ||
ssh_user = "root" | ||
ssh_port = "22" | ||
} | ||
``` | ||
- deploy using `terraform` | ||
``` | ||
terraform init | ||
terraform apply | ||
``` | ||
- you can check your freshly installed cluster in [**autok3s UI**](https://github.com/cnrancher/autok3s?tab=readme-ov-file#quick-start-tldr) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
locals { | ||
server_name = "example" | ||
server_ip_address = "1.1.1.1.1" | ||
ssh_key = "~/.ssh/key" | ||
ssh_user = "root" | ||
ssh_port = "22" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module "k3s" { | ||
source = "github.com/fluencelabs/spectrum//terraform-modules/k3s" | ||
kubeconfigs_location = "${path.root}/secrets" | ||
server_name = local.server_name | ||
server_ip_address = local.server_ip_address | ||
ssh_key = local.ssh_key | ||
ssh_user = local.ssh_user | ||
ssh_port = local.ssh_port | ||
} | ||
|
||
provider "helm" { | ||
kubernetes { | ||
config_path = module.k3s.kubeconfig_file | ||
} | ||
} | ||
|
||
module "spectrum" { | ||
depends_on = [module.k3s] | ||
source = "github.com/fluencelabs/spectrum//terraform-modules/spectrum" | ||
cluster_flavour = "k3s" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
resources: | ||
- ./manifests.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
apiVersion: "cilium.io/v2alpha1" | ||
kind: CiliumL2AnnouncementPolicy | ||
metadata: | ||
name: fluence-l2 | ||
namespace: kube-system | ||
spec: | ||
serviceSelector: | ||
matchLabels: | ||
fluence: cloudless.dev | ||
externalIPs: true | ||
loadBalancerIPs: true | ||
--- | ||
apiVersion: "cilium.io/v2alpha1" | ||
kind: CiliumLoadBalancerIPPool | ||
metadata: | ||
name: fluence-l2 | ||
namespace: kube-system | ||
spec: | ||
serviceSelector: | ||
matchLabels: | ||
fluence: cloudless.dev | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
resource "terraform_data" "k3s-init" { | ||
|
||
input = var.server_name | ||
provisioner "local-exec" { | ||
command = <<EOT | ||
autok3s create --provider native --docker-script https://get.docker.com --k3s-channel stable --k3s-install-script https://get.k3s.io \ | ||
--master-extra-args '--disable servicelb,traefik --flannel-backend none --disable-kube-proxy --disable-network-policy' \ | ||
--name ${var.server_name} --rollback --ssh-key-path ${var.ssh_key} --ssh-port ${var.ssh_port} --ssh-user ${var.ssh_user} --master-ips ${var.server_ip_address} \ | ||
--enable explorer | ||
EOT | ||
|
||
} | ||
|
||
provisioner "local-exec" { | ||
when = destroy | ||
command = <<EOT | ||
autok3s delete -p native --name ${self.input} -f | ||
EOT | ||
|
||
} | ||
} | ||
|
||
resource "terraform_data" "k3s-gen-kubeconfig" { | ||
depends_on = [ | ||
terraform_data.k3s-init | ||
] | ||
input = "${var.kubeconfigs_location}/kubeconfig.yaml" | ||
provisioner "local-exec" { | ||
command = <<EOT | ||
mkdir -p ${var.kubeconfigs_location} && \ | ||
autok3s kubectl config use-context ${var.server_name} && \ | ||
autok3s kubectl config view --minify=true --raw > ${var.kubeconfigs_location}/kubeconfig.yaml | ||
EOT | ||
|
||
} | ||
|
||
provisioner "local-exec" { | ||
when = destroy | ||
command = <<EOT | ||
rm -rf ${self.input}.yaml | ||
EOT | ||
} | ||
} | ||
|
||
resource "terraform_data" "os-init" { | ||
|
||
connection { | ||
type = "ssh" | ||
user = var.ssh_user | ||
port = var.ssh_port | ||
private_key = file(var.ssh_key) | ||
host = var.server_ip_address | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
"curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash" | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "kubeconfig_file" { | ||
description = "kubeconfig file location" | ||
value = "${terraform_data.k3s-gen-kubeconfig.input}" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
variable "kubeconfigs_location" { | ||
default = "./secrets" | ||
} | ||
|
||
variable "server_name" { | ||
} | ||
|
||
variable "server_ip_address" { | ||
} | ||
|
||
variable "ssh_key" { | ||
} | ||
|
||
variable "ssh_port" { | ||
default = "22" | ||
} | ||
|
||
variable "ssh_user" { | ||
default = "root" | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,11 @@ rollOutCiliumPods: true | |
envoy.rollOutPods: true | ||
|
||
k8sServiceHost: localhost | ||
%{ if cluster_flavour == "talos" } | ||
k8sServicePort: 7445 | ||
%{ else } | ||
k8sServicePort: 6443 | ||
%{ endif } | ||
|
||
ipam: | ||
mode: kubernetes | ||
|
@@ -37,6 +41,7 @@ cgroup: | |
enabled: false | ||
hostRoot: /sys/fs/cgroup | ||
|
||
%{ if hubble_enabled } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. had to do it, otherwise it fails if hubble disabled |
||
hubble: | ||
enabled: ${hubble_enabled} | ||
relay: | ||
|
@@ -45,16 +50,10 @@ hubble: | |
ui: | ||
enabled: true | ||
rollOutPods: true | ||
%{ endif } | ||
|
||
%{ if l2_enabled } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed, will always add this features |
||
l2announcements: | ||
enabled: true | ||
|
||
externalIPs: | ||
enabled: true | ||
|
||
devices: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed, devices not required. But if we decide to have it - will be managed at fcli manifests |
||
%{ for device in devices } | ||
- ${device} | ||
%{ endfor } | ||
%{ endif } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nahsi pls note this. As discussed maybe we should move
talos
to 6443 as well