-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# K3S example for Digital Ocean | ||
|
||
Configuration in this directory creates a k3s cluster resources instances. | ||
|
||
## Usage | ||
|
||
> [!warning] | ||
> **Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.** | ||
```bash | ||
$ export DIGITALOCEAN_TOKEN=... | ||
$ terraform init | ||
$ terraform apply | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module "k3s" { | ||
source = "./../.." | ||
|
||
depends_on_ = digitalocean_droplet.node_instances | ||
k3s_version = "latest" | ||
cluster_domain = "do_k3s" | ||
|
||
drain_timeout = "60s" | ||
managed_fields = ["label"] | ||
generate_ca_certificates = true | ||
|
||
global_flags = [for instance in digitalocean_droplet.node_instances : "--tls-san ${instance.ipv4_address}"] | ||
|
||
servers = { | ||
# The node name will be automatically provided by | ||
# the module using the field name... any usage of | ||
# --node-name in additional_flags will be ignored | ||
|
||
for instance in digitalocean_droplet.node_instances : | ||
instance.name => { | ||
ip = instance.ipv4_address_private | ||
connection = { | ||
timeout = "60s" | ||
type = "ssh" | ||
host = instance.ipv4_address | ||
private_key = trimspace(tls_private_key.ed25519_provisioning.private_key_pem) | ||
} | ||
|
||
labels = { "node.kubernetes.io/type" = "master" } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
data "digitalocean_image" "ubuntu" { | ||
slug = "ubuntu-22-04-x64" | ||
} | ||
|
||
resource "tls_private_key" "ed25519_provisioning" { | ||
algorithm = "ED25519" | ||
} | ||
|
||
resource "digitalocean_ssh_key" "default" { | ||
name = "K3S terraform module - Provisionning SSH key" | ||
public_key = trimspace(tls_private_key.ed25519_provisioning.public_key_openssh) | ||
} | ||
|
||
resource "digitalocean_droplet" "node_instances" { | ||
count = 3 | ||
|
||
image = data.digitalocean_image.ubuntu.slug | ||
name = "k3s-node-${count.index}" | ||
region = "ams3" | ||
size = "s-1vcpu-2gb" | ||
ssh_keys = [digitalocean_ssh_key.default.fingerprint] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
output "summary" { | ||
value = module.k3s.summary | ||
} | ||
|
||
output "kubeconfig" { | ||
value = module.k3s.kube_config | ||
sensitive = true | ||
} | ||
|
||
output "ssh_private_key" { | ||
description = "Generated SSH private key." | ||
value = tls_private_key.ed25519_provisioning.private_key_openssh | ||
sensitive = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
terraform { | ||
required_providers { | ||
digitalocean = { | ||
source = "digitalocean/digitalocean" | ||
version = "2.31.0" | ||
} | ||
} | ||
required_version = "~> 1.0" | ||
} |