Skip to content

Commit 9a2b452

Browse files
committed
feat(example): devops-stack on scaleway
chore(scaleway): first example
1 parent c6db8ec commit 9a2b452

File tree

9 files changed

+504
-174
lines changed

9 files changed

+504
-174
lines changed

.gitignore

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
### Unwanted Terraform files when using the examples ###
2-
32
examples/*/.terraform
43
examples/*/terraform.tfstate
54
examples/*/terraform.tfstate.*
65
examples/*/.terraform.tfstate.lock.info
76
examples/*/*-config
87
examples/*/.terraform.lock.hcl
9-
8+
examples/*/secrets.yml
9+
examples/*/terraform.tfstate*
10+
examples/*/.terraform.lock.hcl
11+
examples/*/kubeconfig.yml
12+
examples/*/issue.txt
13+
examples/*/log.txt
14+
examples/*/*.png
15+
examples/*/*.html
16+
examples/*/issuers.yml
1017

1118
### Files and folders when building the website and documentation locally ###
1219

@@ -55,3 +62,5 @@ ehthumbs_vista.db
5562

5663
# Folder config file
5764
[Dd]esktop.ini
65+
.DS_STORE
66+
**/*.swp

examples/scaleway/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## Introduction
2+
The terraform project will instanciated a devops-stack on Scaleway.
3+
4+
## Installation
5+
6+
Add your credentials to launch the project. At least the following environement variables are required: `SCW_ACCESS_KEY,SCW_ACCESS_KEY,SCW_DEFAULT_ORGANIZATION_ID,SCW_DEFAULT_PROJECT_ID,SCW_DEFAULT_PROJECT_ID`.
7+
8+
We also use an environement variable for the variable PROJECT\_ID called `TF_VAR_PROJECT_ID`
9+
10+
Configure the stack by modifying `inputs.tfvars` (e.g: cluster\_name) and launch the terraform apply with:
11+
12+
If you want to create a Kapsule cluster, you will have to use the scaleway provider in version 2.33.0.
13+
14+
If you modify the base\_domain, be sure to add a new star record that points to the load balancer ip address created by the stack in your domain.
15+
16+
```bash
17+
terraform init
18+
terraform apply -var-file inputs.tfvars
19+
```
20+
21+
## Usage
22+
Get the kubeconfig file and the domain name with the following commands:
23+
24+
```bash
25+
terraform output -raw kubeconfig_file > kubeconfig.json
26+
terraform output base_domain
27+
```
28+
29+
Your application are available at the following address: $APP\_NAME.apps.$CLUSTER\_NAME.$BASE\_DOMAIN.
30+
e.g: prometheus.apps.devops-stack.51-51-52-52.np.io
31+
32+
For authentication on oidc, users and password are available in the output:
33+
```bash
34+
terraform output passwords
35+
```
36+

examples/scaleway/inputs.tfvars

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# ###################################################
2+
# Input for module which creates the scaleway cluster
3+
# ###################################################
4+
cluster_name = "devops-stack"
5+
cluster_description = "Devops-stack on cloud provider scaleway"
6+
cluster_tags = ["demo", "dev", "devops-stack", "test", ]
7+
cluster_type = "multicloud"
8+
kubernetes_version = "1.29.1"
9+
admission_plugins = ["PodNodeSelector", ]
10+
node_pools = {
11+
config1 = {
12+
node_type = "DEV1-L"
13+
size = 2
14+
min_size = 2
15+
max_size = 2
16+
autoscaling = true
17+
autohealing = true
18+
container_runtime = "containerd"
19+
wait_for_pool_ready = true
20+
}
21+
}
22+
23+
# #########################
24+
# Additional cluster config
25+
# #########################
26+
base_domain = "gs-fr-dev.camptocamp.com"
27+
lb_name = "devops-stack"
28+
zone = "fr-par-1"
29+
lb_type = "LB-S"
30+
31+
# Ingress
32+
ingress_enable_service_monitor = false
33+
34+
# Keycloak
35+
cluster_issuer = "ca-issuer"
36+
37+
# Cert-manager
38+
cert_manager_enable_service_monitor = false

examples/scaleway/loki.tf

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
data "scaleway_account_project" "devops_stack" {
2+
project_id = var.project_id
3+
}
4+
5+
resource "scaleway_object_bucket" "loki" {
6+
name = "devops-stack-loki-logs"
7+
tags = {
8+
line = "devops-stack"
9+
platform = "scw-devops-stack-example"
10+
}
11+
}
12+
13+
resource "scaleway_iam_application" "loki" {
14+
name = "devops-stack-example-loki"
15+
description = "Loki access to S3 buckets from Devops Stack example"
16+
}
17+
18+
resource "scaleway_iam_policy" "loki" {
19+
name = "devops-stack-example-loki"
20+
description = "Loki access to S3 buckets from Devops Stack example"
21+
application_id = scaleway_iam_application.loki.id
22+
23+
rule {
24+
project_ids = [data.scaleway_account_project.devops_stack.id]
25+
permission_set_names = [
26+
"ObjectStorageObjectsDelete",
27+
"ObjectStorageObjectsRead",
28+
"ObjectStorageObjectsWrite",
29+
"ObjectStorageBucketsRead",
30+
]
31+
}
32+
}
33+
34+
resource "scaleway_iam_api_key" "loki" {
35+
application_id = scaleway_iam_application.loki.id
36+
description = "Loki credentials for Devops Stack example"
37+
default_project_id = data.scaleway_account_project.devops_stack.id
38+
}
39+
40+
locals {
41+
loki_common_settings = {
42+
extraEnv = [
43+
{
44+
name = "AWS_ACCESS_KEY_ID"
45+
valueFrom = {
46+
secretKeyRef = {
47+
name = kubernetes_secret.credentials_loki_s3.metadata.0.name
48+
key = "AWS_ACCESS_KEY_ID"
49+
}
50+
}
51+
},
52+
{
53+
name = "AWS_SECRET_ACCESS_KEY"
54+
valueFrom = {
55+
secretKeyRef = {
56+
name = kubernetes_secret.credentials_loki_s3.metadata.0.name
57+
key = "AWS_SECRET_ACCESS_KEY"
58+
}
59+
}
60+
},
61+
]
62+
}
63+
}
64+
65+
module "loki" {
66+
source = "git::https://github.com/camptocamp/devops-stack-module-loki-stack.git?ref=v8.1.0"
67+
68+
app_autosync = {}
69+
70+
retention = "9000h"
71+
ingress = {
72+
hosts = ["loki.apps.${var.cluster_name}.${var.base_domain}"]
73+
cluster_issuer = var.cluster_issuer
74+
}
75+
76+
helm_values = [{
77+
loki-distributed = {
78+
loki = merge({
79+
structuredConfig = {
80+
auth_enabled = false
81+
compactor = {
82+
retention_delete_delay = "1h"
83+
retention_enabled = false
84+
}
85+
ingester = {
86+
lifecycler = {
87+
ring = {
88+
replication_factor = 1
89+
}
90+
}
91+
}
92+
}
93+
schemaConfig = {
94+
configs = [
95+
{
96+
from = "2023-04-28",
97+
store = "boltdb-shipper"
98+
object_store = "s3"
99+
schema = "v11"
100+
index = {
101+
prefix = "index_"
102+
period = "24h"
103+
}
104+
}
105+
]
106+
}
107+
storageConfig = {
108+
aws = {
109+
bucketnames = scaleway_object_bucket.loki.id
110+
endpoint = scaleway_object_bucket.loki.endpoint
111+
s3forcepathstyle = true
112+
#region = "fr-par"
113+
sse_encryption = false
114+
signature_version = "v2"
115+
}
116+
boltdb_shipper = {
117+
shared_store = "s3"
118+
cache_ttl = "24h"
119+
}
120+
}
121+
}, local.loki_common_settings)
122+
indexGateway = local.loki_common_settings
123+
ingester = merge({ replicas = 1 }, local.loki_common_settings)
124+
compactor = local.loki_common_settings
125+
queryFrontend = local.loki_common_settings
126+
querier = local.loki_common_settings
127+
distributor = local.loki_common_settings
128+
}
129+
promtail = {
130+
updateStrategy = {
131+
type = "RollingUpdate"
132+
rollingUpdate = {
133+
maxUnavailable = 3
134+
}
135+
}
136+
config = {
137+
clients = [
138+
{
139+
url = "http://loki-distributor:3100/loki/api/v1/push"
140+
#tenant_id = 1
141+
}
142+
]
143+
}
144+
}
145+
}]
146+
}
147+
148+
resource "kubernetes_secret" "credentials_loki_s3" {
149+
metadata {
150+
namespace = "loki-stack"
151+
name = "credentials-loki-s3"
152+
}
153+
154+
data = {
155+
AWS_ACCESS_KEY_ID = scaleway_iam_api_key.loki.access_key
156+
AWS_SECRET_ACCESS_KEY = scaleway_iam_api_key.loki.secret_key
157+
}
158+
159+
}

0 commit comments

Comments
 (0)