{"id":18808812,"url":"https://github.com/nimbolus/tf-k3s","last_synced_at":"2025-04-13T20:24:23.901Z","repository":{"id":38457491,"uuid":"324868345","full_name":"nimbolus/tf-k3s","owner":"nimbolus","description":"Deploy K3s clusters with terraform","archived":false,"fork":false,"pushed_at":"2024-04-19T14:29:11.000Z","size":216,"stargazers_count":13,"open_issues_count":2,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-19T15:34:08.893Z","etag":null,"topics":["hcloud","k3s","openstack","terraform","terraform-module"],"latest_commit_sha":null,"homepage":"https://nimbolus.de/terraform-modules/tf-k3s/","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nimbolus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-12-27T23:30:39.000Z","updated_at":"2024-04-05T04:25:57.000Z","dependencies_parsed_at":"2023-11-25T19:21:21.959Z","dependency_job_id":"4c43c481-3000-4222-8f21-519c8c8669ba","html_url":"https://github.com/nimbolus/tf-k3s","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nimbolus%2Ftf-k3s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nimbolus%2Ftf-k3s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nimbolus%2Ftf-k3s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nimbolus%2Ftf-k3s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nimbolus","download_url":"https://codeload.github.com/nimbolus/tf-k3s/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223602664,"owners_count":17171952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hcloud","k3s","openstack","terraform","terraform-module"],"created_at":"2024-11-07T23:14:22.141Z","updated_at":"2024-11-07T23:14:22.686Z","avatar_url":"https://github.com/nimbolus.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraform Modules for K3s\n\nProvisions K3s nodes and is able to build a cluster from multiple nodes.\n\nYou can use the [k3s](./k3s) module to template the necessary cloudinit files for creating a K3s cluster node.\nModules for [OpenStack](./k3s-openstack) and [Hetzner hcloud](./k3s-hcloud) that bundle all necessary resources are available.\n\n## Supported Cloud Providers\n- OpenStack\n- Hetzner Cloud (hcloud)\n\n## Modules\n### k3s\nThis module provides the templating of the user_data for use with cloud-init.\n\n```terraform\nmodule \"k3s_server\" {\n  source = \"git::https://github.com/nimbolus/tf-k3s.git//k3s\"\n\n  name          = \"k3s-server\"\n  cluster_token = \"abcdef\"\n  k3s_ip        = \"10.11.12.13\"\n  k3s_args = [\n    \"server\",\n    \"--disable\", \"traefik\",\n    \"--node-label\", \"az=ex1\",\n  ]\n}\n\noutput \"server_user_data\" {\n  value     = module.k3s_server.user_data\n  sensitive = true\n}\n```\n\n### k3s-openstack\nWith this module a single K3s node can be deployed with OpenStack. It internally uses the k3s module. Depending on the supplied parameters the node will initialize a new cluster or join an existing cluster as a server or agent.\n\n```terraform\nmodule \"server\" {\n  source = \"git::https://github.com/nimbolus/tf-k3s.git//k3s-openstack\"\n\n  name               = \"k3s-server\"\n  image_name         = \"ubuntu-20.04\"\n  flavor_name        = \"m1.small\"\n  availability_zone  = \"ex\"\n  keypair_name       = \"keypair\"\n  network_id         = var.network_id\n  subnet_id          = var.subnet_id\n  security_group_ids = [module.secgroup.id]\n\n  cluster_token = \"abcdef\"\n  k3s_args = [\n    \"server\",\n    \"--disable\", \"traefik\",\n    \"--node-label\", \"az=ex1\",\n    # if using bootstrap-auth include\n    \"--kube-apiserver-arg\", \"enable-bootstrap-token-auth\",\n  ]\n  bootstrap_token_id     = \"012345\"\n  bootstrap_token_secret = \"0123456789abcdef\"\n}\n```\n\n### k3s-openstack/security-group\nThe necessary security-group for the K3s cluster can be deployed with this module.\n\n```terraform\nmodule \"secgroup\" {\n  source = \"git::https://github.com/nimbolus/tf-k3s.git//k3s-openstack/security-group\"\n}\n```\n\n### k3s-hcloud\nWith this module a single K3s node can be deployed with hcloud. It internally uses the k3s module. Depending on the supplied parameters the node will initialize a new cluster or join an existing cluster as a server or agent.\n\n```terraform\nmodule \"server\" {\n  source = \"git::https://github.com/nimbolus/tf-k3s.git//k3s-hcloud\"\n\n  name          = \"k3s-server\"\n  keypair_name  = \"keypair\"\n  network_id    = var.network_id\n  network_range = var.ip_range\n\n  cluster_token = \"abcdef\"\n  k3s_args = [\n    \"server\",\n    \"--disable\", \"traefik\",\n    \"--node-label\", \"az=ex1\",\n    # if using bootstrap-auth include\n    \"--kube-apiserver-arg\", \"enable-bootstrap-token-auth\",\n  ]\n  bootstrap_token_id     = \"012345\"\n  bootstrap_token_secret = \"0123456789abcdef\"\n}\n```\n\n## bootstrap-auth\nTo access the cluster an optional bootstrap token can be installed on the cluster. To install the token specify the parameters `bootstrap_token_id` and `bootstrap_token_secret` on the server that initializes the cluster.\nFor ease of use the provider [nimbolus/k8sbootstrap](https://registry.terraform.io/providers/nimbolus/k8sbootstrap/latest) can be used to retrieve the CA certificate from the cluster. The provider can also output a kubeconfig with the bootstrap token.\n\n```terraform\ndata \"k8sbootstrap_auth\" \"auth\" {\n  // depends_on = [module.secgroup] // if using OpenStack\n  server = module.server1.k3s_external_url\n  token  = local.token\n}\n```\n\n## Examples\n- [basic](examples/basic/main.tf): basic usage of the k3s module with one server and one agent node\n- [ha-hcloud](examples/ha-hcloud/main.tf): 3 Servers and 1 Agent with bootstrap token on Hetzner Cloud\n- [ha-openstack](examples/ha-openstack/main.tf): 3 Servers and 1 Agent with bootstrap token on OpenStack\n\n## Tests\n### Basic\n```sh\ncd tests/basic\ngo test -count=1 -v\n```\n\n### OpenStack\n```sh\ncd tests/ha-openstack\ncp env.sample .env\n$EDITOR .env\nsource .env\ngo test -count=1 -v\n```\n\n### hcloud\n```sh\ncd tests/ha-hcloud\ncp env.sample .env\n$EDITOR .env\nsource .env\ngo test -count=1 -v\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnimbolus%2Ftf-k3s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnimbolus%2Ftf-k3s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnimbolus%2Ftf-k3s/lists"}