labels, nated nodes, lb

This commit is contained in:
Serge Logvinov
2022-06-23 13:29:07 +03:00
parent 2cbc969728
commit 960af5be7f
11 changed files with 260 additions and 104 deletions

View File

@@ -176,9 +176,9 @@ spec:
tolerations: tolerations:
- key: "node.cloudprovider.kubernetes.io/uninitialized" - key: "node.cloudprovider.kubernetes.io/uninitialized"
value: "true" value: "true"
effect: "NoSchedule" effect: NoSchedule
- key: "CriticalAddonsOnly" - key: "CriticalAddonsOnly"
operator: "Exists" operator: Exists
- key: "node-role.kubernetes.io/master" - key: "node-role.kubernetes.io/master"
effect: NoSchedule effect: NoSchedule
affinity: affinity:
@@ -223,7 +223,7 @@ spec:
memory: 32Mi memory: 32Mi
requests: requests:
cpu: 10m cpu: 10m
memory: 12Mi memory: 16Mi
securityContext: securityContext:
allowPrivilegeEscalation: false allowPrivilegeEscalation: false
capabilities: capabilities:
@@ -245,46 +245,6 @@ spec:
- effect: NoSchedule - effect: NoSchedule
key: node-role.kubernetes.io/control-plane key: node-role.kubernetes.io/control-plane
operator: Exists operator: Exists
--- - effect: NoSchedule
apiVersion: policy/v1beta1 key: node.cloudprovider.kubernetes.io/uninitialized
kind: PodSecurityPolicy operator: Exists
metadata:
annotations:
seccomp.security.alpha.kubernetes.io/allowedProfileNames: runtime/default
seccomp.security.alpha.kubernetes.io/defaultProfileName: runtime/default
labels:
app.kubernetes.io/instance: kubelet-serving-cert-approver
app.kubernetes.io/name: kubelet-serving-cert-approver
name: kubelet-serving-cert-approver
namespace: kubelet-serving-cert-approver
spec:
allowPrivilegeEscalation: false
forbiddenSysctls:
- '*'
fsGroup:
ranges:
- max: 65534
min: 65534
rule: MustRunAs
hostIPC: false
hostNetwork: false
hostPID: false
privileged: false
readOnlyRootFilesystem: true
requiredDropCapabilities:
- ALL
runAsUser:
ranges:
- max: 65534
min: 65534
rule: MustRunAs
seLinux:
rule: RunAsAny
supplementalGroups:
ranges:
- max: 65534
min: 65534
rule: MustRunAs
volumes:
- downwardAPI
- secret

View File

@@ -127,6 +127,9 @@ spec:
labels: labels:
k8s-app: metrics-server k8s-app: metrics-server
spec: spec:
nodeSelector:
kubernetes.io/os: linux
node-role.kubernetes.io/master: ""
tolerations: tolerations:
- key: "CriticalAddonsOnly" - key: "CriticalAddonsOnly"
operator: "Exists" operator: "Exists"
@@ -172,8 +175,6 @@ spec:
volumeMounts: volumeMounts:
- mountPath: /tmp - mountPath: /tmp
name: tmp-dir name: tmp-dir
nodeSelector:
kubernetes.io/os: linux
priorityClassName: system-cluster-critical priorityClassName: system-cluster-critical
serviceAccountName: metrics-server serviceAccountName: metrics-server
volumes: volumes:

View File

@@ -145,6 +145,7 @@ spec:
- --cloud-provider=scaleway - --cloud-provider=scaleway
- --leader-elect=true - --leader-elect=true
- --allow-untagged-cloud - --allow-untagged-cloud
- --controllers=cloud-node,cloud-node-lifecycle
resources: resources:
requests: requests:
cpu: 100m cpu: 100m

View File

@@ -26,7 +26,6 @@ resource "scaleway_instance_server" "controlplane" {
cloud-init = templatefile("${path.module}/templates/controlplane.yaml", cloud-init = templatefile("${path.module}/templates/controlplane.yaml",
merge(var.kubernetes, { merge(var.kubernetes, {
name = "master-${count.index + 1}" name = "master-${count.index + 1}"
type = "controlplane"
ipv4_vip = local.ipv4_vip ipv4_vip = local.ipv4_vip
ipv4_local = cidrhost(local.main_subnet, 11 + count.index) ipv4_local = cidrhost(local.main_subnet, 11 + count.index)
lbv4 = local.lbv4 lbv4 = local.lbv4
@@ -34,6 +33,7 @@ resource "scaleway_instance_server" "controlplane" {
labels = "${local.controlplane_labels},node.kubernetes.io/instance-type=${lookup(var.controlplane, "type", "DEV1-M")}" labels = "${local.controlplane_labels},node.kubernetes.io/instance-type=${lookup(var.controlplane, "type", "DEV1-M")}"
access = var.scaleway_access access = var.scaleway_access
secret = var.scaleway_secret secret = var.scaleway_secret
region = "fr-par"
project_id = var.scaleway_project_id project_id = var.scaleway_project_id
}) })
) )
@@ -48,6 +48,13 @@ resource "scaleway_instance_server" "controlplane" {
} }
} }
resource "scaleway_vpc_public_gateway_dhcp_reservation" "controlplane" {
count = lookup(var.controlplane, "count", 0)
gateway_network_id = scaleway_vpc_gateway_network.main.id
mac_address = scaleway_instance_server.controlplane[count.index].private_network.0.mac_address
ip_address = cidrhost(local.main_subnet, 11 + count.index)
}
resource "scaleway_instance_placement_group" "controlplane" { resource "scaleway_instance_placement_group" "controlplane" {
name = "controlplane" name = "controlplane"
policy_type = "max_availability" policy_type = "max_availability"

View File

@@ -1,29 +1,33 @@
# FIXME: does not work without enable_dynamic_ip locals {
web_labels = "topology.kubernetes.io/region=fr-par,topology.kubernetes.io/zone=${var.regions[0]},project.io/node-pool=web"
}
resource "scaleway_instance_server" "web" { resource "scaleway_instance_server" "web" {
count = lookup(var.instances, "web_count", 0) count = lookup(var.instances, "web_count", 0)
name = "web-${count.index + 1}" name = "web-${count.index + 1}"
image = data.scaleway_instance_image.talos.id image = data.scaleway_instance_image.talos.id
type = lookup(var.instances, "web_instance_type", "DEV1-M") type = lookup(var.instances, "web_type", "DEV1-M")
enable_ipv6 = true enable_ipv6 = true
enable_dynamic_ip = false enable_dynamic_ip = false
security_group_id = scaleway_instance_security_group.web.id security_group_id = scaleway_instance_security_group.web.id
tags = concat(var.tags, ["web"]) placement_group_id = scaleway_instance_placement_group.web.id
tags = concat(var.tags, ["web"])
private_network { private_network {
pn_id = scaleway_vpc_private_network.main.id pn_id = scaleway_vpc_private_network.main.id
} }
user_data = { user_data = {
cloud-init = templatefile("${path.module}/templates/web.yaml.tpl", cloud-init = templatefile("${path.module}/templates/worker.yaml.tpl",
merge(var.kubernetes, { merge(var.kubernetes, {
name = "web-${count.index + 1}" name = "web-${count.index + 1}"
type = "worker"
ipv4_vip = local.ipv4_vip ipv4_vip = local.ipv4_vip
ipv4 = cidrhost(local.main_subnet, 21 + count.index)
ipv4_gw = cidrhost(local.main_subnet, 1)
clusterDns = cidrhost(split(",", var.kubernetes["serviceSubnets"])[0], 10) clusterDns = cidrhost(split(",", var.kubernetes["serviceSubnets"])[0], 10)
nodeSubnets = local.main_subnet nodeSubnets = local.main_subnet
labels = "topology.kubernetes.io/region=fr-par" labels = "${local.web_labels},node.kubernetes.io/instance-type=${lookup(var.instances, "web_type", "DEV1-M")}"
}) })
) )
} }
@@ -36,3 +40,16 @@ resource "scaleway_instance_server" "web" {
] ]
} }
} }
resource "scaleway_instance_placement_group" "web" {
name = "web"
policy_type = "max_availability"
policy_mode = "enforced"
}
resource "scaleway_vpc_public_gateway_dhcp_reservation" "web" {
count = lookup(var.instances, "web_count", 0)
gateway_network_id = scaleway_vpc_gateway_network.main.id
mac_address = scaleway_instance_server.web[count.index].private_network.0.mac_address
ip_address = cidrhost(local.main_subnet, 21 + count.index)
}

View File

@@ -0,0 +1,48 @@
locals {
worker_labels = "topology.kubernetes.io/region=fr-par,topology.kubernetes.io/zone=${var.regions[0]},project.io/node-pool=worker"
}
resource "scaleway_instance_server" "worker" {
count = lookup(var.instances, "worker_count", 0)
name = "worker-${count.index + 1}"
image = data.scaleway_instance_image.talos.id
type = lookup(var.instances, "worker_type", "DEV1-M")
enable_ipv6 = true
enable_dynamic_ip = false
security_group_id = scaleway_instance_security_group.worker.id
tags = concat(var.tags, ["worker"])
private_network {
pn_id = scaleway_vpc_private_network.main.id
}
user_data = {
cloud-init = templatefile("${path.module}/templates/worker.yaml.tpl",
merge(var.kubernetes, {
name = "worker-${count.index + 1}"
ipv4_vip = local.ipv4_vip
ipv4 = cidrhost(local.main_subnet, 31 + count.index)
ipv4_gw = cidrhost(local.main_subnet, 1)
clusterDns = cidrhost(split(",", var.kubernetes["serviceSubnets"])[0], 10)
nodeSubnets = local.main_subnet
labels = "${local.worker_labels},node.kubernetes.io/instance-type=${lookup(var.instances, "worker_type", "DEV1-M")}"
})
)
}
lifecycle {
ignore_changes = [
image,
type,
user_data,
]
}
}
resource "scaleway_vpc_public_gateway_dhcp_reservation" "worker" {
count = lookup(var.instances, "worker_count", 0)
gateway_network_id = scaleway_vpc_gateway_network.main.id
mac_address = scaleway_instance_server.worker[count.index].private_network.0.mac_address
ip_address = cidrhost(local.main_subnet, 31 + count.index)
}

View File

@@ -29,12 +29,13 @@ resource "scaleway_lb_backend" "api" {
name = "api" name = "api"
forward_protocol = "tcp" forward_protocol = "tcp"
forward_port = "6443" forward_port = "6443"
server_ips = scaleway_instance_server.controlplane[*].private_ip server_ips = [for k in range(0, lookup(var.controlplane, "count", 0)) : cidrhost(local.main_subnet, 11 + k)]
health_check_timeout = "5s" health_check_timeout = "5s"
health_check_delay = "30s" health_check_delay = "30s"
health_check_https { health_check_https {
uri = "/readyz" uri = "/readyz"
code = 401
} }
} }
@@ -55,3 +56,96 @@ resource "scaleway_lb_frontend" "api" {
} }
} }
} }
resource "scaleway_lb_backend" "web" {
count = local.lb_enable ? 1 : 0
lb_id = scaleway_lb.lb[0].id
name = "web"
forward_protocol = "tcp"
forward_port = "80"
server_ips = [for k in range(0, lookup(var.instances, "web_count", 0)) : cidrhost(local.main_subnet, 21 + k)]
health_check_timeout = "5s"
health_check_delay = "30s"
health_check_http {
uri = "/healthz"
}
}
resource "scaleway_lb_backend" "web_https" {
count = local.lb_enable ? 1 : 0
lb_id = scaleway_lb.lb[0].id
name = "web"
forward_protocol = "tcp"
forward_port = "443"
server_ips = [for k in range(0, lookup(var.instances, "web_count", 0)) : cidrhost(local.main_subnet, 21 + k)]
health_check_timeout = "5s"
health_check_delay = "30s"
health_check_https {
uri = "/healthz"
}
}
resource "scaleway_lb_frontend" "http" {
count = local.lb_enable ? 1 : 0
lb_id = scaleway_lb.lb[0].id
backend_id = scaleway_lb_backend.web[0].id
name = "http"
inbound_port = "80"
acl {
name = "Allow controlplane IPs"
action {
type = "allow"
}
match {
ip_subnet = try(scaleway_instance_ip.controlplane[*].address, "0.0.0.0/0")
}
}
acl {
name = "Allow whitlist IPs"
action {
type = "allow"
}
match {
ip_subnet = concat(var.whitelist_web, var.whitelist_admins)
}
}
acl {
name = "Deny all"
action {
type = "deny"
}
match {
ip_subnet = ["0.0.0.0/0"]
}
}
}
resource "scaleway_lb_frontend" "https" {
count = local.lb_enable ? 1 : 0
lb_id = scaleway_lb.lb[0].id
backend_id = scaleway_lb_backend.web_https[0].id
name = "https"
inbound_port = "443"
acl {
name = "Allow whitlist IPs"
action {
type = "allow"
}
match {
ip_subnet = concat(var.whitelist_web, var.whitelist_admins)
}
}
acl {
name = "Deny all"
action {
type = "deny"
}
match {
ip_subnet = ["0.0.0.0/0"]
}
}
}

View File

@@ -4,37 +4,47 @@ resource "scaleway_instance_security_group" "controlplane" {
inbound_default_policy = "drop" inbound_default_policy = "drop"
outbound_default_policy = "accept" outbound_default_policy = "accept"
dynamic "inbound_rule" { inbound_rule {
for_each = ["50000", "6443", "2379", "2380"] action = "accept"
protocol = "ANY"
content { ip_range = local.main_subnet
action = "accept"
protocol = "TCP"
port = inbound_rule.value
}
} }
dynamic "inbound_rule" {
for_each = ["50000", "6443"]
content {
action = "accept"
protocol = "TCP"
port = inbound_rule.value
ip_range = "::/0"
}
}
inbound_rule { inbound_rule {
action = "accept" action = "accept"
protocol = "TCP" protocol = "TCP"
port = 4240 port = 4240
ip_range = "::/0" ip_range = "::/0"
} }
inbound_rule {
action = "accept" dynamic "inbound_rule" {
protocol = "ANY" for_each = var.whitelist_admins
ip_range = local.main_subnet
content {
action = "accept"
protocol = "TCP"
port = "6443"
ip_range = length(split("/", inbound_rule.value)) == 2 ? inbound_rule.value : "${inbound_rule.value}/32"
}
}
dynamic "inbound_rule" {
for_each = var.whitelist_admins
content {
action = "accept"
protocol = "TCP"
port = "50000"
ip_range = length(split("/", inbound_rule.value)) == 2 ? inbound_rule.value : "${inbound_rule.value}/32"
}
}
dynamic "inbound_rule" {
for_each = ["2379", "2380"]
content {
action = "accept"
protocol = "TCP"
port = inbound_rule.value
}
} }
# KubeSpan # KubeSpan
@@ -72,12 +82,6 @@ resource "scaleway_instance_security_group" "web" {
} }
} }
inbound_rule {
action = "accept"
protocol = "TCP"
port = 4240
ip_range = "::/0"
}
inbound_rule { inbound_rule {
action = "accept" action = "accept"
protocol = "ANY" protocol = "ANY"
@@ -97,6 +101,12 @@ resource "scaleway_instance_security_group" "web" {
ip_range = "::/0" ip_range = "::/0"
} }
inbound_rule {
action = "accept"
protocol = "TCP"
port = 4240
ip_range = "::/0"
}
inbound_rule { inbound_rule {
action = "accept" action = "accept"
protocol = "ICMP" protocol = "ICMP"
@@ -127,4 +137,16 @@ resource "scaleway_instance_security_group" "worker" {
port = 51820 port = 51820
ip_range = "::/0" ip_range = "::/0"
} }
inbound_rule {
action = "accept"
protocol = "TCP"
port = 4240
ip_range = "::/0"
}
inbound_rule {
action = "accept"
protocol = "ICMP"
ip_range = "::/0"
}
} }

View File

@@ -2,12 +2,11 @@ version: v1alpha1
debug: false debug: false
persist: true persist: true
machine: machine:
type: ${type} type: controlplane
certSANs: certSANs:
- "${lbv4}" - "${lbv4}"
- "${ipv4}" - "${ipv4}"
- "${ipv4_local}" - "${apiDomain}"
- "${ipv4_vip}"
kubelet: kubelet:
extraArgs: extraArgs:
node-ip: "${ipv4_local}" node-ip: "${ipv4_local}"
@@ -62,7 +61,7 @@ cluster:
id: ${clusterID} id: ${clusterID}
secret: ${clusterSecret} secret: ${clusterSecret}
controlPlane: controlPlane:
endpoint: https://${ipv4_vip}:6443 endpoint: https://${apiDomain}:6443
clusterName: ${clusterName} clusterName: ${clusterName}
discovery: discovery:
enabled: true enabled: true
@@ -83,6 +82,7 @@ cluster:
certSANs: certSANs:
- "${lbv4}" - "${lbv4}"
- "${ipv4}" - "${ipv4}"
- "${apiDomain}"
controllerManager: controllerManager:
extraArgs: extraArgs:
node-cidr-mask-size-ipv4: 24 node-cidr-mask-size-ipv4: 24
@@ -103,7 +103,7 @@ cluster:
SCW_ACCESS_KEY: ${base64encode(access)} SCW_ACCESS_KEY: ${base64encode(access)}
SCW_SECRET_KEY: ${base64encode(secret)} SCW_SECRET_KEY: ${base64encode(secret)}
SCW_DEFAULT_PROJECT_ID: ${base64encode(project_id)} SCW_DEFAULT_PROJECT_ID: ${base64encode(project_id)}
SCW_DEFAULT_REGION: ${base64encode("fr-par")} SCW_DEFAULT_REGION: ${base64encode(region)}
externalCloudProvider: externalCloudProvider:
enabled: true enabled: true
manifests: manifests:

View File

@@ -18,6 +18,7 @@ machine:
nodeIP: nodeIP:
validSubnets: ${format("%#v",split(",",nodeSubnets))} validSubnets: ${format("%#v",split(",",nodeSubnets))}
network: network:
hostname: "${name}"
interfaces: interfaces:
- interface: eth0 - interface: eth0
dhcp: true dhcp: true
@@ -27,7 +28,12 @@ machine:
- network: 169.254.42.42/32 - network: 169.254.42.42/32
metric: 1024 metric: 1024
- interface: eth1 - interface: eth1
dhcp: true addresses:
- ${ipv4}/24
routes:
- network: 0.0.0.0/0
gateway: ${ipv4_gw}
metric: 512
- interface: dummy0 - interface: dummy0
addresses: addresses:
- 169.254.2.53/32 - 169.254.2.53/32
@@ -53,7 +59,7 @@ cluster:
id: ${clusterID} id: ${clusterID}
secret: ${clusterSecret} secret: ${clusterSecret}
controlPlane: controlPlane:
endpoint: https://${ipv4_vip}:6443 endpoint: https://${apiDomain}:6443
clusterName: ${clusterName} clusterName: ${clusterName}
discovery: discovery:
enabled: false enabled: false

View File

@@ -61,10 +61,10 @@ variable "instances" {
description = "Map of instance properties" description = "Map of instance properties"
type = map(any) type = map(any)
default = { default = {
web_count = 0, web_count = 0,
web_instance_type = "DEV1-L", web_type = "DEV1-L",
worker_count = 0, worker_count = 0,
worker_instance_type = "DEV1-L", worker_type = "DEV1-L",
} }
} }