Skip to content

Commit

Permalink
Cloud config
Browse files Browse the repository at this point in the history
  • Loading branch information
sergelogvinov committed Jun 27, 2022
1 parent ca09896 commit 9358b8a
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 46 deletions.
6 changes: 5 additions & 1 deletion openstack/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ ENDPOINT:=${shell terraform output -raw controlplane_endpoint_public 2>/dev/null
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)

create-lb: ## Create load balancer
terraform init
terraform apply -target=output.controlplane_endpoint_public --refresh -auto-approve

create-config: ## Genereate talos configs
talosctl gen config --output-dir _cfgs --with-docs=false --with-examples=false talos-k8s-openstack https://${ENDPOINT}:6443
talosctl --talosconfig _cfgs/talosconfig config endpoint ${ENDPOINT}
Expand All @@ -27,7 +31,7 @@ create-templates:
create-deployments:
helm template --namespace=kube-system --version=1.11.5 -f deployments/cilium.yaml cilium \
cilium/cilium > deployments/cilium-result.yaml
helm template --namespace=ingress-nginx --version=4.1.1 -f deployments/ingress.yaml ingress-nginx \
helm template --namespace=ingress-nginx --version=4.1.4 -f deployments/ingress.yaml ingress-nginx \
ingress-nginx/ingress-nginx > deployments/ingress-result.yaml

create-network: ## Create networks
Expand Down
6 changes: 3 additions & 3 deletions openstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ make create-network
Generate the default talos config

```shell
make create-config create-templates
make create-templates
```

Create the config file **terraform.tfvars** and add params.
Expand All @@ -92,8 +92,8 @@ ccm_password = "openstack-password"
# Number of kubernetes controlplane by zones
controlplane = {
"GRA9" = {
count = 1,
instance_type = "d2-4",
count = 1,
type = "d2-4",
},
}
Expand Down
2 changes: 1 addition & 1 deletion openstack/auth.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

provider "openstack" {
cloud = "openstack"
cloud = var.clouds
}
48 changes: 24 additions & 24 deletions openstack/deployments/ingress-result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ apiVersion: v1
kind: ServiceAccount
metadata:
labels:
helm.sh/chart: ingress-nginx-4.1.1
helm.sh/chart: ingress-nginx-4.1.4
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: "1.2.0"
app.kubernetes.io/version: "1.2.1"
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
Expand All @@ -20,10 +20,10 @@ apiVersion: v1
kind: ConfigMap
metadata:
labels:
helm.sh/chart: ingress-nginx-4.1.1
helm.sh/chart: ingress-nginx-4.1.4
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: "1.2.0"
app.kubernetes.io/version: "1.2.1"
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
Expand Down Expand Up @@ -66,10 +66,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
helm.sh/chart: ingress-nginx-4.1.1
helm.sh/chart: ingress-nginx-4.1.4
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: "1.2.0"
app.kubernetes.io/version: "1.2.1"
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/managed-by: Helm
name: ingress-nginx
Expand Down Expand Up @@ -135,10 +135,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
helm.sh/chart: ingress-nginx-4.1.1
helm.sh/chart: ingress-nginx-4.1.4
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: "1.2.0"
app.kubernetes.io/version: "1.2.1"
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/managed-by: Helm
name: ingress-nginx
Expand All @@ -156,10 +156,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
labels:
helm.sh/chart: ingress-nginx-4.1.1
helm.sh/chart: ingress-nginx-4.1.4
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: "1.2.0"
app.kubernetes.io/version: "1.2.1"
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
Expand Down Expand Up @@ -241,10 +241,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
helm.sh/chart: ingress-nginx-4.1.1
helm.sh/chart: ingress-nginx-4.1.4
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: "1.2.0"
app.kubernetes.io/version: "1.2.1"
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
Expand All @@ -265,10 +265,10 @@ kind: Service
metadata:
annotations:
labels:
helm.sh/chart: ingress-nginx-4.1.1
helm.sh/chart: ingress-nginx-4.1.4
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: "1.2.0"
app.kubernetes.io/version: "1.2.1"
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
Expand Down Expand Up @@ -302,10 +302,10 @@ apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
helm.sh/chart: ingress-nginx-4.1.1
helm.sh/chart: ingress-nginx-4.1.4
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: "1.2.0"
app.kubernetes.io/version: "1.2.1"
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
Expand Down Expand Up @@ -336,7 +336,7 @@ spec:
dnsPolicy: ClusterFirstWithHostNet
containers:
- name: controller
image: "k8s.gcr.io/ingress-nginx/controller:v1.2.0@sha256:d8196e3bc1e72547c5dec66d6556c0ff92a23f6d0919b206be170bc90d5f9185"
image: "registry.k8s.io/ingress-nginx/controller:v1.2.1@sha256:5516d103a9c2ecc4f026efbd4b40662ce22dc1f824fb129ed121460aaa5c47f8"
imagePullPolicy: IfNotPresent
lifecycle:
preStop:
Expand All @@ -349,12 +349,12 @@ spec:
- --controller-class=k8s.io/ingress-nginx
- --ingress-class=nginx
- --configmap=$(POD_NAMESPACE)/ingress-nginx-controller
securityContext:
securityContext:
capabilities:
drop:
- ALL
add:
- NET_BIND_SERVICE
drop:
- ALL
add:
- NET_BIND_SERVICE
runAsUser: 101
allowPrivilegeEscalation: true
env:
Expand Down Expand Up @@ -428,10 +428,10 @@ apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
labels:
helm.sh/chart: ingress-nginx-4.1.1
helm.sh/chart: ingress-nginx-4.1.4
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: "1.2.0"
app.kubernetes.io/version: "1.2.1"
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
Expand Down
17 changes: 17 additions & 0 deletions openstack/images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Upload images

Create the config file **terraform.tfvars** and add params.

```hcl
# Body of terraform.tfvars
# Regions to use
regions = ["GRA7", "GRA9"]
```

```shell
wget https://github.com/siderolabs/talos/releases/download/v1.1.0-beta.2/openstack-amd64.tar.gz
tar -xzf openstack-amd64.tar.gz

terraform init && terraform apply -auto-approve
```
2 changes: 1 addition & 1 deletion openstack/images/auth.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

provider "openstack" {
cloud = "openstack"
cloud = var.clouds
}
2 changes: 1 addition & 1 deletion openstack/images/images.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "openstack_images_image_v2" "talos" {
disk_format = "raw"
min_disk_gb = 5
min_ram_mb = 1
tags = ["talos-1.1.0-beta.0"]
tags = ["talos-1.1.0-beta.2"]

properties = {
hw_firmware_type = "uefi"
Expand Down
6 changes: 6 additions & 0 deletions openstack/images/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

variable "clouds" {
type = string
description = "The config section in clouds.yaml"
default = "openstack"
}

variable "regions" {
type = list(string)
description = "The id of the openstack region"
Expand Down
2 changes: 1 addition & 1 deletion openstack/instances-controlplane.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module "controlplane" {

instance_servergroup = openstack_compute_servergroup_v2.controlplane[each.key].id
instance_count = lookup(try(var.controlplane[each.key], {}), "count", 0)
instance_flavor = lookup(try(var.controlplane[each.key], {}), "instance_type", "d2-2")
instance_flavor = lookup(try(var.controlplane[each.key], {}), "type", "d2-2")
instance_image = data.openstack_images_image_v2.talos[each.key].id
instance_tags = concat(var.tags, ["infra"])
instance_secgroups = [local.network_secgroup[each.key].common, local.network_secgroup[each.key].controlplane]
Expand Down
2 changes: 1 addition & 1 deletion openstack/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ output "controlplane_endpoint" {

output "controlplane_endpoint_public" {
description = "Kubernetes controlplane endpoint public"
value = local.endpoint
value = try(local.endpoint[0], "127.0.0.1")
}

output "web_endpoint" {
Expand Down
2 changes: 1 addition & 1 deletion openstack/prepare/auth.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

provider "openstack" {
cloud = "openstack"
cloud = var.clouds
}
2 changes: 1 addition & 1 deletion openstack/prepare/network-gw.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ resource "openstack_compute_instance_v2" "router" {
region = each.key
name = "router-${lower(each.key)}"
image_id = data.openstack_images_image_v2.debian[each.key].id
flavor_name = "d2-2"
flavor_name = try(var.capabilities[each.key].peering_type, "d2-2")
key_pair = openstack_compute_keypair_v2.keypair[each.key].name

network {
Expand Down
9 changes: 9 additions & 0 deletions openstack/prepare/network-secgroup.tf
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ resource "openstack_networking_secgroup_v2" "router" {
description = "Security group for router/peering node"
}

resource "openstack_networking_secgroup_rule_v2" "router_icmp_ipv4" {
for_each = { for idx, name in var.regions : name => idx }
region = each.key
security_group_id = openstack_networking_secgroup_v2.router[each.key].id
direction = "ingress"
ethertype = "IPv4"
protocol = "icmp"
}

resource "openstack_networking_secgroup_rule_v2" "router_ssh_v4" {
for_each = { for idx, name in var.regions : name => idx }
region = each.key
Expand Down
6 changes: 3 additions & 3 deletions openstack/prepare/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ resource "openstack_networking_subnet_v2" "private_v6" {
}

resource "openstack_networking_subnet_route_v2" "public_v4" {
for_each = { for idx, name in var.regions : name => idx if try(var.capabilities[name].peering, false) }
for_each = { for idx, name in var.regions : name => idx if try(var.capabilities[name].gateway, false) }
subnet_id = openstack_networking_subnet_v2.public[each.key].id
destination_cidr = var.network_cidr
next_hop = try(var.capabilities[each.key].gateway, false) ? cidrhost(openstack_networking_subnet_v2.private[each.key].cidr, 2) : cidrhost(openstack_networking_subnet_v2.private[each.key].cidr, 1)
}

resource "openstack_networking_subnet_route_v2" "private_v4" {
for_each = { for idx, name in var.regions : name => idx if try(var.capabilities[name].peering, false) }
for_each = { for idx, name in var.regions : name => idx if try(var.capabilities[name].gateway, false) }
subnet_id = openstack_networking_subnet_v2.private[each.key].id
destination_cidr = var.network_cidr
next_hop = try(var.capabilities[each.key].gateway, false) ? cidrhost(openstack_networking_subnet_v2.private[each.key].cidr, 2) : cidrhost(openstack_networking_subnet_v2.private[each.key].cidr, 1)
}

resource "openstack_networking_subnet_route_v2" "private_v6" {
for_each = { for idx, name in var.regions : name => idx if try(var.capabilities[name].peering, false) }
for_each = { for idx, name in var.regions : name => idx if try(var.capabilities[name].gateway, false) }
subnet_id = openstack_networking_subnet_v2.private_v6[each.key].id
destination_cidr = local.network_cidr_v6
next_hop = cidrhost(openstack_networking_subnet_v2.private_v6[each.key].cidr, 1)
Expand Down
16 changes: 12 additions & 4 deletions openstack/prepare/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

variable "clouds" {
type = string
description = "The config section in clouds.yaml"
default = "openstack"
}

variable "project_id" {
type = string
description = "The project_id of the openstack"
Expand Down Expand Up @@ -42,12 +48,14 @@ variable "capabilities" {
type = map(any)
default = {
"GRA7" = {
gateway = false
peering = false
gateway = false
peering = false
peering_type = "d2-2"
},
"GRA9" = {
gateway = false
peering = false
gateway = false
peering = false
peering_type = "d2-2"
},
}
}
3 changes: 3 additions & 0 deletions openstack/templates/controlplane.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ machine:
net.core.somaxconn: 65535
net.core.netdev_max_backlog: 4096
cluster:
id: ${clusterID}
secret: ${clusterSecret}
controlPlane:
endpoint: https://${apiDomain}:6443
clusterName: ${clusterName}
network:
dnsDomain: ${domain}
podSubnets: ${format("%#v",split(",",podSubnets))}
Expand Down
14 changes: 10 additions & 4 deletions openstack/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

variable "clouds" {
type = string
description = "The config section in clouds.yaml"
default = "openstack"
}

data "terraform_remote_state" "prepare" {
backend = "local"
config = {
Expand Down Expand Up @@ -55,12 +61,12 @@ variable "controlplane" {
type = map(any)
default = {
"GRA7" = {
count = 0,
instance_type = "d2-2",
count = 0,
type = "d2-2",
},
"GRA9" = {
count = 0,
instance_type = "d2-2",
count = 0,
type = "d2-2",
},
}
}
Expand Down

0 comments on commit 9358b8a

Please sign in to comment.