refactoring

This commit is contained in:
Serge Logvinov
2021-09-03 10:33:26 +03:00
parent 863fe85be7
commit 864caeb138
10 changed files with 55 additions and 34 deletions

View File

@@ -1,17 +1,19 @@
prepare-image:
ssh-keygen -f /.ssh/terraform -N '' -t rsa
ENDPOINT:=${shell terraform output -raw controlplane_endpoint 2>/dev/null}
cd prepare
help:
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
prepare:
@[ -f ~/.ssh/terraform ] || ssh-keygen -f ~/.ssh/terraform -N '' -t rsa
create-lb: ## Create load balancer
terraform init
terraform apply -auto-approve
terraform apply -auto-approve -target=output.controlplane_endpoint
terraform output controlplane_endpoint
create-lb:
terraform init
terraform apply -auto-approve -target=hcloud_load_balancer.api
create-config:
talosctl gen config --output-dir _cfgs --with-docs=false --with-examples=false talos-k8s-hezner https://127.0.0.1:6443
create-config: ## Genereate talos configs
./talosctl gen config --output-dir _cfgs --with-docs=false --with-examples=false talos-k8s-hezner https://${ENDPOINT}:6443
create-templates:
@yq ea -P '. as $$item ireduce ({}; . * $$item )' _cfgs/controlplane.yaml templates/controlplane.yaml.tpl > templates/controlplane.yaml
@@ -25,9 +27,12 @@ create-templates:
@yq eval -j '{"kubernetes": .}' _cfgs/tfstate.vars > terraform.tfvars.json
create-controlplane:
terraform apply -target=null_resource.controlplane
create-controlplane: ## Bootstrap first controlplane node
terraform apply -target=hcloud_server.controlplane
create-infrastructure:
create-infrastructure: ## Bootstrap all nodes
cd modules/worker && terraform init
terraform apply
create-kubeconfig:
talosctl --talosconfig _cfgs/talosconfig --nodes 172.16.0.11 kubeconfig

View File

@@ -60,8 +60,6 @@ spec:
app: local-path-provisioner
spec:
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
- key: "node-role.kubernetes.io/master"
effect: NoSchedule
serviceAccountName: local-path-provisioner-service-account
@@ -108,12 +106,12 @@ metadata:
data:
config.json: |-
{
"nodePathMap":[
{
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
"paths":["/var/local-path-provisioner"]
}
]
"nodePathMap":[
{
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
"paths":["/var/local-path-provisioner"]
}
]
}
setup: |-
#!/bin/sh

View File

@@ -19,7 +19,7 @@ resource "hcloud_server" "controlplane" {
merge(var.kubernetes, {
name = "master-${count.index + 1}"
type = count.index == 0 ? "init" : "controlplane"
ipv4_vip = local.ipv4_vip
ipv4_vip = count.index == 0 ? local.ipv4_vip : cidrhost(hcloud_network_subnet.core.ip_range, 11)
ipv4_local = cidrhost(hcloud_network_subnet.core.ip_range, 11 + count.index)
lbv4_local = local.lbv4_local
lbv4 = local.lbv4
@@ -40,8 +40,9 @@ resource "hcloud_server" "controlplane" {
}
#
# Local floating ip
# Local floating ip assign to controlplane[0]
#
resource "hcloud_server_network" "controlplane" {
count = lookup(var.controlplane, "count", 0) > 0 ? 1 : 0
server_id = hcloud_server.controlplane[0].id
@@ -51,14 +52,14 @@ resource "hcloud_server_network" "controlplane" {
}
resource "hcloud_load_balancer_target" "api" {
count = local.lb_enable ? 1 : 0
count = local.lb_enable ? lookup(var.controlplane, "count", 0) : 0
type = "server"
load_balancer_id = hcloud_load_balancer.api[0].id
server_id = hcloud_server.controlplane[count.index].id
}
#
# Secure push talos config to the node
# Secure push talos config to the controlplane
#
# resource "local_file" "controlplane" {

View File

@@ -16,10 +16,6 @@ resource "hcloud_load_balancer" "api" {
location = var.regions[0]
load_balancer_type = lookup(var.controlplane, "type_lb", "lb11")
labels = merge(var.tags, { type = "infra" })
provisioner "local-exec" {
command = "echo LB: ${self.ipv4}"
}
}
resource "hcloud_load_balancer_network" "api" {

21
hetzner/outputs.tf Normal file
View File

@@ -0,0 +1,21 @@
output "controlplane_endpoint" {
description = "Kubernetes controlplane endpoint"
value = local.lbv4
depends_on = [hcloud_load_balancer.api]
}
output "controlplane_nodes" {
description = "Kubernetes controlplane nodes"
value = [
for s in hcloud_server.controlplane[*] :
{
name = s.name
ipv4_address = s.ipv4_address
ipv6_address = s.ipv6_address
zone = "hetzner"
location = s.location
params = ""
}
]
}

View File

@@ -18,8 +18,6 @@ machine:
interfaces:
- interface: eth1
dhcp: true
addresses:
- ${ipv4_vip}
- interface: dummy0
addresses:
- 169.254.2.53/32
@@ -30,6 +28,11 @@ machine:
net.core.somaxconn: 65535
net.core.netdev_max_backlog: 4096
systemDiskEncryption:
state:
provider: luks2
keys:
- nodeID: {}
slot: 0
ephemeral:
provider: luks2
keys:
@@ -56,11 +59,8 @@ cluster:
- "${lbv4_local}"
- "${ipv4_local}"
- "${ipv4_vip}"
extraArgs:
feature-gates: IPv6DualStack=true
controllerManager:
extraArgs:
feature-gates: IPv6DualStack=true
node-cidr-mask-size-ipv4: 24
node-cidr-mask-size-ipv6: 112
scheduler: {}