Skip to content

Commit 60931e3

Browse files
committed
Add Scaleway Kapsule module
1 parent 8cc57d8 commit 60931e3

30 files changed

Lines changed: 907 additions & 1 deletion

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ validate: .init
6262
test: validate
6363
docker exec \
6464
test-container-$(GIT_SHA) \
65-
entrypoint tofu apply --target module.aks_zero --target module.eks_zero --target module.gke_zero --input=false --auto-approve
65+
entrypoint tofu apply --target module.aks_zero --target module.eks_zero --target module.gke_zero --target module.scw_zero --input=false --auto-approve
6666
docker exec \
6767
test-container-$(GIT_SHA) \
6868
entrypoint tofu apply --target module.eks_zero_nginx --input=false --auto-approve
@@ -95,6 +95,7 @@ shell: .check-container
9595
-e KBST_AUTH_AWS \
9696
-e KBST_AUTH_AZ \
9797
-e KBST_AUTH_GCLOUD \
98+
-e KBST_AUTH_SCW \
9899
-e HOME=/infra/tests/.user \
99100
--workdir /infra/tests \
100101
ghcr.io/kbst/terraform-kubestack/dev:test-$(GIT_SHA)-${DOCKER_TARGET} \

oci/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ RUN echo "GOOGLE_CLOUD_SDK_VERSION: ${GOOGLE_CLOUD_SDK_VERSION}" \
9797
RUN /opt/google/bin/gcloud components install gke-gcloud-auth-plugin
9898

9999

100+
#
101+
#
102+
# Scaleway builder
103+
FROM builder AS scw-builder
104+
105+
ARG TARGETARCH
106+
107+
# https://github.com/scaleway/scaleway-cli/releases
108+
ARG SCALEWAY_CLI_VERSION=2.35.0
109+
110+
RUN echo "SCALEWAY_CLI_VERSION: ${SCALEWAY_CLI_VERSION}" \
111+
&& curl -LO https://github.com/scaleway/scaleway-cli/releases/download/v${SCALEWAY_CLI_VERSION}/scaleway-cli_${SCALEWAY_CLI_VERSION}_linux_${TARGETARCH} \
112+
&& mv scaleway-cli_${SCALEWAY_CLI_VERSION}_linux_${TARGETARCH} /opt/bin/scw \
113+
&& chmod +x /opt/bin/scw \
114+
&& /opt/bin/scw version
115+
116+
100117
#
101118
#
102119
# Azure builder
@@ -231,6 +248,15 @@ COPY --from=azure-builder /opt/azure /opt/azure
231248
ENV PATH=$PATH:/opt/azure/bin
232249

233250

251+
#
252+
#
253+
# Scaleway variant
254+
FROM final-base AS scw
255+
256+
# Scaleway
257+
COPY --from=scw-builder /opt/bin/scw /opt/bin/scw
258+
259+
234260
#
235261
#
236262
# Default (multi-cloud) variant
@@ -247,3 +273,6 @@ ENV PATH=$PATH:/opt/google/bin
247273
# Azure
248274
COPY --from=azure-builder /opt/azure /opt/azure
249275
ENV PATH=$PATH:/opt/azure/bin
276+
277+
# Scaleway
278+
COPY --from=scw-builder /opt/bin/scw /opt/bin/scw
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module "scw_zero" {
2+
source = "github.com/kbst/terraform-kubestack//scaleway/cluster?ref={{version}}"
3+
4+
configuration = {
5+
# apps environment
6+
apps = {
7+
# Set name_prefix used to generate the cluster name
8+
# [name_prefix]-[workspace]-[region]
9+
# e.g. name_prefix = kbst becomes: `kbst-apps-fr-par`
10+
# for small orgs the name works well,
11+
# for bigger orgs consider department or team names
12+
name_prefix = ""
13+
14+
# Set the base_domain used to generate the FQDN of the cluster
15+
# [cluster_name].[provider_name].[base_domain]
16+
# e.g. kbst-apps-fr-par.scw.infra.example.com
17+
# The domain must be registered with Scaleway Domains and DNS
18+
base_domain = ""
19+
20+
# The Scaleway region to deploy the clusters in
21+
# e.g. "fr-par", "nl-ams", "pl-waw"
22+
region = ""
23+
24+
# Kubernetes version for the cluster
25+
# Use a minor version string to allow patch upgrades, e.g. "1.32"
26+
cluster_version = "1.32"
27+
28+
# Container Network Interface plugin
29+
# Options: "cilium", "calico", "weave", "flannel", "kilo"
30+
cni = "cilium"
31+
32+
# Whether to delete additional resources (load-balancers, block volumes,
33+
# the private network if empty) created in Kubernetes when deleting the cluster.
34+
# Set to true only if you want these resources cleaned up automatically on destroy.
35+
delete_additional_resources = false
36+
37+
# Default node pool configuration
38+
default_node_pool = {
39+
# Commercial node type — see `scw k8s node-pool list-available-types`
40+
node_type = "DEV1-M"
41+
42+
# Initial number of nodes in the pool
43+
size = 1
44+
45+
# Minimum and maximum size for autoscaling
46+
min_size = 1
47+
max_size = 1
48+
49+
# Enable Scaleway's cluster autoscaler for this pool
50+
autoscaling = false
51+
52+
# Enable automatic node replacement on failure
53+
autohealing = true
54+
}
55+
}
56+
57+
# ops environment, inherits from apps
58+
ops = {}
59+
}
60+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
provider "scaleway" {
2+
# region is read from SCW_DEFAULT_REGION environment variable
3+
# or can be set explicitly, e.g.:
4+
# region = "fr-par"
5+
}
6+
7+
provider "kustomization" {
8+
alias = "scw_zero"
9+
kubeconfig_raw = module.scw_zero.kubeconfig
10+
}
11+
12+
locals {
13+
scw_zero_kubeconfig = yamldecode(module.scw_zero.kubeconfig)
14+
}
15+
16+
provider "kubernetes" {
17+
alias = "scw_zero"
18+
19+
host = local.scw_zero_kubeconfig["clusters"][0]["cluster"]["server"]
20+
token = local.scw_zero_kubeconfig["users"][0]["user"]["token"]
21+
cluster_ca_certificate = base64decode(
22+
local.scw_zero_kubeconfig["clusters"][0]["cluster"]["certificate-authority-data"]
23+
)
24+
}

quickstart/src/configurations/multi-cloud/versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ terraform {
77
kustomization = {
88
source = "kbst/kustomization"
99
}
10+
11+
scaleway = {
12+
source = "scaleway/scaleway"
13+
}
1014
}
1115

1216
required_version = ">= 0.15"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Local .terraform directories
2+
**/.terraform/*
3+
4+
# .tfstate files
5+
*.tfstate
6+
*.tfstate.*
7+
8+
# .user home directory
9+
.user/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM {{image_name}}:{{image_tag}}-scw
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM {{image_name}}:{{image_tag}}-kind
2+
3+
ARG UID
4+
ARG GID
5+
6+
RUN mkdir -p /infra/terraform.tfstate.d &&\
7+
chown ${UID}:${GID} -R /infra
8+
9+
COPY manifests /infra/manifests
10+
COPY *.tf *.tfvars /infra/
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Welcome to Kubestack
2+
3+
This repository uses [Kubestack][1]. Kubestack is the open source GitOps framework for teams that want to automate infrastructure, not reinvent automation.
4+
5+
- Cluster infrastructure and cluster services are defined using Terraform modules.
6+
- Popular cluster services are available from the Terraform module [catalog][2].
7+
- Both cluster and cluster service modules follow the Kubestack [inheritance model][3] to prevent configuration drift between environments.
8+
- All changes follow the same four-step process.
9+
10+
Full [framework documentation][4] is available online.
11+
12+
## Making changes
13+
14+
To make changes to the Kubernetes cluster(s), supporting infrastructure or the Kubernetes services defined in this repository follow the Kubestack [GitOps process][5]. The GitOps process ensures that changes are safely applied by first reviewing the proposed changes, then validating the changes against the _ops_ environment and finally promoting the changes to be applied against the _apps_ environment by setting a tag.
15+
16+
To accelerate the developer workflow an auto-updating [development environment][6] can be run on localhost using the `kbst local apply` command.
17+
18+
1. Change
19+
20+
Make changes to the configuration in a new branch. Commit the changed configuration and push your branch. The pipeline runs `terraform plan` against the _ops_ workspace.
21+
22+
```shell
23+
# checkout a new branch from main
24+
git checkout -b examplechange main
25+
26+
# make your changes
27+
28+
# commit your changes
29+
git commit # write a meaningful commit message
30+
31+
# push your changes
32+
git push origin examplechange
33+
```
34+
35+
1. Review
36+
37+
Request a peer review of your changes. Team members review the changes and the Terraform plan. If reviewers require changes, make additional commits in the branch.
38+
39+
```shell
40+
# make sure you're in the correct branch
41+
git checkout examplechange
42+
43+
# make changes required by the review
44+
45+
# commit and push the required changes
46+
git commit # write a meaningful commit message
47+
git push origin examplechange
48+
```
49+
50+
1. Merge
51+
52+
If approved, merge your changes to main, to apply them against the _ops_ environment. After applying to _ops_ was successful, the pipeline runs Terraform plan against the _apps_ environment.
53+
54+
```shell
55+
# you can merge on the commandline
56+
# or by merging a pull request
57+
git checkout main
58+
git merge examplechange
59+
git push origin main
60+
```
61+
62+
1. Promote
63+
64+
Review the previous _apps_ environment plan and tag the merge commit to promote the same changes to the _apps_ environment.
65+
66+
```shell
67+
# make sure you're on the correct commit
68+
git checkout main
69+
git pull
70+
git log -1
71+
72+
# if correct, tag the current commit
73+
# any tag prefixed with `apps-deploy-`
74+
# will trigger the pipeline
75+
git tag apps-deploy-$(date -I)-0
76+
77+
# in case of multiple deploys on the same day,
78+
# increase the counter
79+
# e.g. git tag apps-deploy-2020-05-14-1
80+
```
81+
82+
## Manual operations
83+
84+
In case of the automation being unavailable, upgrades requiring manual steps or in disaster recovery scenarios run Terraform and the cloud CLI locally. Kubestack provides container images bundling all dependencies to use for both automated and manual operations.
85+
86+
1. Exec into container
87+
88+
```shell
89+
# Build the container image
90+
docker build -t kubestack .
91+
92+
# Exec into the container image
93+
# add docker socket mount for local dev
94+
# -v /var/run/docker.sock:/var/run/docker.sock
95+
docker run --rm -ti \
96+
-v `pwd`:/infra \
97+
kubestack
98+
```
99+
100+
1. Authenticate providers
101+
102+
Credentials are cached inside the `.user` directory. The directory is excluded from Git by the default `.gitignore`.
103+
104+
```shell
105+
# for Scaleway
106+
scw init
107+
```
108+
109+
1. Select desired environment
110+
111+
```shell
112+
# for ops
113+
terraform workspace select ops
114+
115+
# or for apps
116+
terraform workspace select apps
117+
```
118+
119+
1. Run Terraform commands
120+
121+
```shell
122+
# run terraform init
123+
terraform init
124+
125+
# run, e.g. terraform plan
126+
terraform plan
127+
```
128+
129+
[1]: https://www.kubestack.com
130+
[2]: https://www.kubestack.com/catalog
131+
[3]: https://www.kubestack.com/framework/documentation/inheritance-model
132+
[4]: https://www.kubestack.com/framework/documentation
133+
[5]: https://www.kubestack.com/framework/documentation/gitops-process
134+
[6]: https://www.kubestack.com/framework/documentation/tutorial-develop-locally#provision-local-clusters
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module "scw_zero" {
2+
source = "github.com/kbst/terraform-kubestack//scaleway/cluster?ref={{version}}"
3+
4+
configuration = {
5+
# apps environment
6+
apps = {
7+
# Set name_prefix used to generate the cluster name
8+
# [name_prefix]-[workspace]-[region]
9+
# e.g. name_prefix = kbst becomes: `kbst-apps-fr-par`
10+
# for small orgs the name works well,
11+
# for bigger orgs consider department or team names
12+
name_prefix = ""
13+
14+
# Set the base_domain used to generate the FQDN of the cluster
15+
# [cluster_name].[provider_name].[base_domain]
16+
# e.g. kbst-apps-fr-par.scw.infra.example.com
17+
# The domain must be registered with Scaleway Domains and DNS
18+
base_domain = ""
19+
20+
# The Scaleway region to deploy the cluster in
21+
# e.g. "fr-par", "nl-ams", "pl-waw"
22+
region = ""
23+
24+
default_node_pool = {
25+
# Commercial node type — must be available in every zone listed below.
26+
# Run `scw k8s node-pool list-available-types` to list types per zone.
27+
node_type = "PRO2-XXS"
28+
29+
# Availability zones to distribute the default node pool across.
30+
# One pool is created per zone. Must be explicitly specified.
31+
# e.g. fr-par: ["fr-par-1", "fr-par-2", "fr-par-3"]
32+
# e.g. nl-ams: ["nl-ams-1", "nl-ams-2", "nl-ams-3"]
33+
# e.g. pl-waw: ["pl-waw-1", "pl-waw-2", "pl-waw-3"]
34+
zones = []
35+
36+
min_size = 1
37+
max_size = 2
38+
}
39+
}
40+
41+
# ops environment, inherits from apps
42+
ops = {}
43+
}
44+
}

0 commit comments

Comments
 (0)