Skip to content

Commit

Permalink
Update starters to new directory layout and modules
Browse files Browse the repository at this point in the history
  • Loading branch information
pst committed Jun 4, 2021
1 parent 2f00fcd commit f767ed6
Show file tree
Hide file tree
Showing 42 changed files with 540 additions and 312 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,28 @@ jobs:
working-directory: ./kubestack-starter-${{ matrix.starter }}
run: |
# ALL: set name_prefix
sed -i 's/name_prefix = ""/name_prefix = "test"/g' config.auto.tfvars
sed -i 's/name_prefix = ""/name_prefix = "test"/g' *_cluster.tf
# ALL: set base_domain
sed -i 's/base_domain = ""/base_domain = "infra.serverwolken.de"/g' config.auto.tfvars
sed -i 's/base_domain = ""/base_domain = "infra.serverwolken.de"/g' *_cluster.tf
# AKS: set resource_group
sed -i 's/resource_group = ""/resource_group = "terraform-kubestack-testing"/g' config.auto.tfvars
sed -i 's/resource_group = ""/resource_group = "terraform-kubestack-testing"/g' aks_zero_cluster.tf || true
# EKS: set region
sed -i 's/region = ""/region = "eu-west-1"/g' providers.tf || true
sed -i 's/region = ""/region = "eu-west-1"/g' eks_zero_providers.tf || true
# EKS: set cluster_availability_zones
sed -i 's/cluster_availability_zones = ""/cluster_availability_zones = "eu-west-1a,eu-west-1b"/g' config.auto.tfvars
sed -i 's/cluster_availability_zones = ""/cluster_availability_zones = "eu-west-1a,eu-west-1b"/g' eks_zero_cluster.tf || true
# GKE: set project_id
sed -i 's/project_id = ""/project_id = "terraform-kubestack-testing"/g' config.auto.tfvars
sed -i 's/project_id = ""/project_id = "terraform-kubestack-testing"/g' gke_zero_cluster.tf || true
# GKE: set region
sed -i 's/region = ""/region = "europe-west1"/g' config.auto.tfvars
sed -i 's/region = ""/region = "europe-west1"/g' gke_zero_cluster.tf || true
# GKE: set cluster_node_locations
sed -i 's/cluster_node_locations = ""/cluster_node_locations = "europe-west1-b,europe-west1-c,europe-west1-d"/g' config.auto.tfvars
sed -i 's/cluster_node_locations = ""/cluster_node_locations = "europe-west1-b,europe-west1-c,europe-west1-d"/g' gke_zero_cluster.tf || true
- name: 'Terraform init'
working-directory: ./kubestack-starter-${{ matrix.starter }}
Expand Down Expand Up @@ -177,7 +177,7 @@ jobs:
-v `pwd`:/infra \
-v /var/run/docker.sock:/var/run/docker.sock \
test-image:${{ github.sha }} \
terraform plan
terraform plan --target module.aks_zero --target module.eks_zero --target module.gke_zero
publish-image:
runs-on: ubuntu-latest
Expand Down
9 changes: 5 additions & 4 deletions quickstart/build_artifacts/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


def replace_template(dist_path, file_name, context):
# Replace templated variable with version in clusters.tf
jinja = Environment(loader=FileSystemLoader(dist_path))
template = jinja.get_template(file_name)
data = template.render(context)
Expand All @@ -38,9 +37,11 @@ def dist(version, image_name, configuration):
copytree(configuration_src, configuration_dist)
copytree(manifests_src, manifests_dist)

# Replace templated version variable in clusters.tf
replace_template(configuration_dist, 'clusters.tf',
{'version': version})
# Replace templated version variables in *.tf files
for tf_file in [n for n in listdir(configuration_dist)
if n.endswith('.tf')]:
replace_template(configuration_dist, tf_file,
{'version': version})

# Replace templated variables in Dockerfiles
dockerfiles = ['Dockerfile', 'Dockerfile.loc']
Expand Down
177 changes: 88 additions & 89 deletions quickstart/src/configurations/_shared/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,141 +2,140 @@

This repository uses [Kubestack][1]. Kubestack is the open source GitOps framework for teams that want to automate infrastructure, not reinvent automation.

* Infrastructure is defined using Terraform configuration
* Cluster manifests are defined using Kustomize bases and overlays
* Bases and overlays can be bespoke, or consumed from the [catalog][2].
* Both infrastructure and manifests follow the Kubestack [inheritance model][3] to prevent configuration drift between the *ops* and *apps* environments
* All changes follow the same four step process.
- Cluster infrastructure and cluster services are defined using Terraform modules.
- Popular cluster services are available from the Terraform module [catalog][2].
- Both cluster and cluster service modules follow the Kubestack [inheritance model][3] to prevent configuration drift between environments.
- All changes follow the same four-step process.

Full [framework documentation][4] is available online.

## Making changes

All changes to the Kubernetes cluster, supporting infrastructure and the services defined as part of the manifests 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 only then promoting the changes to be applied against the *apps* environment by setting a tag.
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.

To accelerate the developer workflow, a [development environment][6], can be run on localhost.
To accelerate the developer workflow an auto-updating [development environment][6] can be run on localhost using the `kbst local apply` command.

1. Change
1. Change

Make changes to the configuration in a new branch. Commit the changed configuration. Validate your changes by pushing the new branch. The pipeline runs `terraform plan` against the *ops* workspace.
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.

```shell
# checkout a new branch from master
git checkout -b examplechange master
```shell
# checkout a new branch from main
git checkout -b examplechange main

# make your changes
# make your changes

# commit your changes
git commit # write a meaningful commit message
# commit your changes
git commit # write a meaningful commit message

# push your changes
git push origin examplechange
```
# push your changes
git push origin examplechange
```

1. Review
1. Review

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.
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.

```shell
# make sure you're in the correct branch
git checkout examplechange
```shell
# make sure you're in the correct branch
git checkout examplechange

# make changes required by the review
# make changes required by the review

# commit and push the required changes
git commit # write a meaningful commit message
git push origin examplechange
```
# commit and push the required changes
git commit # write a meaningful commit message
git push origin examplechange
```

1. Merge
1. Merge

If approved, merge your changes to master, to apply them against the *ops* environment. After applying to *ops* was successful, the pipeline runs Terraform plan against the *apps* environment.
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.

```shell
# you can merge on the commandline
# or by merging a pull request
git checkout master
git merge examplechange
git push origin master
```
```shell
# you can merge on the commandline
# or by merging a pull request
git checkout main
git merge examplechange
git push origin main
```

1. Promote
1. Promote

Review the previous *apps* environment plan and tag the merge commit to promote the same changes to the *apps* environment.
Review the previous _apps_ environment plan and tag the merge commit to promote the same changes to the _apps_ environment.

```shell
# make sure you're on the correct commit
git checkout master
git pull
git log -1
```shell
# make sure you're on the correct commit
git checkout main
git pull
git log -1

# if correct, tag the current commit
# any tag prefixed with `apps-deploy-`
# will trigger the pipeline
git tag apps-deploy-$(date -I)-0
# if correct, tag the current commit
# any tag prefixed with `apps-deploy-`
# will trigger the pipeline
git tag apps-deploy-$(date -I)-0

# in case of multiple deploys on the same day,
# increase the counter
# e.g. git tag apps-deploy-2020-05-14-1
```
# in case of multiple deploys on the same day,
# increase the counter
# e.g. git tag apps-deploy-2020-05-14-1
```

## Manual operations

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.

1. Exec into container
1. Exec into container

```shell
# Build the bootstrap container
docker build -t kubestack .
```shell
# Build the container image
docker build -t kubestack .

# Exec into the bootstrap container
# add docker socket mount for local dev
# -v /var/run/docker.sock:/var/run/docker.sock
docker run --rm -ti \
-v `pwd`:/infra \
kubestack
```
# Exec into the container image
# add docker socket mount for local dev
# -v /var/run/docker.sock:/var/run/docker.sock
docker run --rm -ti \
-v `pwd`:/infra \
kubestack
```

1. Authenticate providers
1. Authenticate providers

Credentials are cached inside the `.user` directory. The directory is excluded from Git by the default `.gitignore`.
Credentials are cached inside the `.user` directory. The directory is excluded from Git by the default `.gitignore`.

```shell
# for AWS
aws configure
```shell
# for AWS
aws configure

# for Azure
az login
# for Azure
az login

# for GCP
gcloud init
gcloud auth application-default login
```
# for GCP
gcloud init
gcloud auth application-default login
```

1. Select desired environment
1. Select desired environment

```shell
# for ops
terraform workspace select ops
```shell
# for ops
terraform workspace select ops

# or for apps
terraform workspace select apps
```
# or for apps
terraform workspace select apps
```
1. Run Terraform commands
1. Run Terraform commands
```shell
# run terraform init
terraform init
```shell
# run terraform init
terraform init

# run, e.g. terraform plan
terraform plan
```
# run, e.g. terraform plan
terraform plan
```
[1]: https://www.kubestack.com
[2]: https://www.kubestack.com/catalog
[3]: https://www.kubestack.com/framework/documentation/inheritance-model
[4]: https://www.kubestack.com/framework/documentation
[5]: https://www.kubestack.com/framework/documentation/gitops-process
[6]: https://www.kubestack.com/framework/documentation/tutorial-build-local-lab
[6]: https://www.kubestack.com/framework/documentation/tutorial-develop-locally#provision-local-clusters
3 changes: 0 additions & 3 deletions quickstart/src/configurations/_shared/tpl_gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@

# .user home directory
.user/

# terraform generated clusters directory
clusters/
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
clusters = {
aks_zero = {
module "aks_zero" {
source = "github.com/kbst/terraform-kubestack//azurerm/cluster?ref={{version}}"

configuration = {
# apps envrionment configuration
apps = {
# Set name_prefix used to generate the cluster_name
Expand Down
27 changes: 27 additions & 0 deletions quickstart/src/configurations/aks/aks_zero_ingress.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module "aks_zero_nginx" {
providers = {
kustomization = kustomization.aks_zero
}
source = "kbst.xyz/catalog/nginx/kustomization"
version = "0.46.0-kbst.1"

configuration = {
apps = {
patches = [{
patch = <<-EOF
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
loadBalancerIP: ${module.aks_zero.default_ingress_ip}
EOF
}]
}

ops = {}

loc = {}
}
}
4 changes: 4 additions & 0 deletions quickstart/src/configurations/aks/aks_zero_providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "kustomization" {
alias = "aks_zero"
kubeconfig_raw = module.aks_zero.kubeconfig
}
5 changes: 0 additions & 5 deletions quickstart/src/configurations/aks/clusters.tf

This file was deleted.

4 changes: 0 additions & 4 deletions quickstart/src/configurations/aks/variables.tf

This file was deleted.

8 changes: 7 additions & 1 deletion quickstart/src/configurations/aks/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
terraform {
required_version = ">= 0.13"
required_providers {
kustomization = {
source = "kbst/kustomization"
}
}

required_version = ">= 0.15"
}
9 changes: 0 additions & 9 deletions quickstart/src/configurations/eks/clusters.tf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
clusters = {
eks_zero = {
module "eks_zero" {
providers = {
aws = aws.eks_zero
}

source = "github.com/kbst/terraform-kubestack//aws/cluster?ref={{version}}"

configuration = {
# apps environment
apps = {
# Set name_prefix used to generate the cluster_name
Expand Down
Loading

0 comments on commit f767ed6

Please sign in to comment.