-
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.
Merge pull request #4 from xunleii/feat-remove-scp
Remove 'scp' dependency
- Loading branch information
Showing
10 changed files
with
194 additions
and
30 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,15 @@ | ||
# K3S example for Hetzner-Cloud | ||
|
||
Configuration in this directory creates a k3s cluster resources including network, subnet and instances. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. |
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,73 @@ | ||
resource "hcloud_ssh_key" "default" { | ||
name = "K3S terraform module - Provisionning SSH key" | ||
public_key = var.ssh_key | ||
} | ||
|
||
resource "hcloud_network" "k3s" { | ||
name = "k3s-network" | ||
ip_range = "10.0.0.0/8" | ||
} | ||
|
||
resource "hcloud_network_subnet" "k3s_nodes" { | ||
type = "server" | ||
network_id = hcloud_network.k3s.id | ||
network_zone = "eu-central" | ||
ip_range = "10.254.1.0/24" | ||
} | ||
|
||
resource "hcloud_network_subnet" "k3s_internal" { | ||
type = "server" | ||
network_id = hcloud_network.k3s.id | ||
network_zone = "eu-central" | ||
ip_range = "10.0.0.0/15" | ||
} | ||
|
||
data "hcloud_image" "ubuntu" { | ||
name = "ubuntu-18.04" | ||
} | ||
|
||
resource "hcloud_server" "master" { | ||
name = "k3s-master" | ||
|
||
image = data.hcloud_image.ubuntu.name | ||
server_type = "cx11-ceph" | ||
|
||
ssh_keys = [ | ||
hcloud_ssh_key.default.id | ||
] | ||
labels = { | ||
provisioner = "terraform", | ||
engine = "k3s", | ||
node_type = "master" | ||
} | ||
} | ||
|
||
resource "hcloud_server_network" "master_network" { | ||
server_id = hcloud_server.master.id | ||
network_id = hcloud_network.k3s.id | ||
ip = cidrhost(hcloud_network_subnet.k3s_nodes.ip_range, 1) | ||
} | ||
|
||
resource "hcloud_server" "minions" { | ||
count = var.minions_num | ||
name = "k3s-minion-${count.index}" | ||
|
||
image = data.hcloud_image.ubuntu.name | ||
server_type = "cx11-ceph" | ||
|
||
ssh_keys = [ | ||
hcloud_ssh_key.default.id | ||
] | ||
labels = { | ||
provisioner = "terraform", | ||
engine = "k3s", | ||
node_type = "minion" | ||
} | ||
} | ||
|
||
resource "hcloud_server_network" "minions_network" { | ||
count = length(hcloud_server.minions) | ||
server_id = hcloud_server.minions[count.index].id | ||
network_id = hcloud_network.k3s.id | ||
ip = cidrhost(hcloud_network_subnet.k3s_nodes.ip_range, count.index + 2) | ||
} |
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,31 @@ | ||
terraform { | ||
required_version = "~> 0.12.0" | ||
} | ||
|
||
provider "hcloud" {} | ||
|
||
module "k3s" { | ||
source = "xunleii/k3s/module" | ||
|
||
k3s_version = "latest" | ||
cluster_cidr = "10.0.0.0/16" | ||
cluster_service_cidr = "10.1.0.0/16" | ||
drain_timeout = "30s" | ||
|
||
master_node = { | ||
ip = hcloud_server_network.master_network.ip | ||
connection = { | ||
host = hcloud_server.master.ipv4_address | ||
} | ||
} | ||
|
||
minion_nodes = { | ||
for i in range(length(hcloud_server.minions)) : | ||
hcloud_server.minions[i].name => { | ||
ip = hcloud_server_network.minions_network[i].ip | ||
connection = { | ||
host = hcloud_server.minions[i].ipv4_address | ||
} | ||
} | ||
} | ||
} |
Empty file.
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 @@ | ||
variable "ssh_key" { | ||
description = "SSH public Key content needed to provision the instances." | ||
type = "string" | ||
} | ||
|
||
variable "minions_num" { | ||
description = "Number of minion nodes." | ||
default = 3 | ||
} |
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
terraform { | ||
required_version = ">= 0.12" | ||
required_version = "~> 0.12" | ||
} | ||
|
||
resource "random_string" "k3s_cluster_secret" { | ||
length = 48 | ||
special = false | ||
} |
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
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
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
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