|
| 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 |
0 commit comments