Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 6940c76

Browse files
committed
Adding manual guide to rings
1 parent b96a7d3 commit 6940c76

File tree

1 file changed

+323
-0
lines changed

1 file changed

+323
-0
lines changed

guides/manual-guide-to-rings.md

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
# A manual guide to utilizing rings
2+
3+
### Introduction
4+
5+
This guide presumes that you have set up your `spk` project, and installed all
6+
necessary pipelines created via `spk project init` (the lifecycle pipeline),
7+
`spk service create` (build update hld pipeline), and `spk hld init` (manifest
8+
generation pipeline), and followed the
9+
[guidelines for creating helm charts](./building-helm-charts-for-spk).
10+
11+
In `spk`, we offer the concept of a `ring` - a way to route inbound traffic to
12+
_revisions_ of a service on a Kubernetes cluster via request headers. For
13+
example, if an inbound request is decorated with the `Ring: dev` header, the
14+
request is routed to the `dev` revision of a service. Similarly, if a request is
15+
decorated with the `Ring: prod` header, the request is routed to the `prod`
16+
revision of a service.
17+
18+
### Service Revisions and Git
19+
20+
Service revisions are built and deployed by committing to bedrock.yaml tracked
21+
git branches in the form of a `ring`. A `ring` maps one to one with a service
22+
revision, which maps directly onto a git branch.
23+
24+
Let's think about a git repository containing three branches, `dev`, `qa`, and
25+
`prod`. Each of these branches contain variations of an application's source
26+
code. `dev` containing the in-progress feature work, `qa` containing stable, but
27+
under-test feature work, and `prod`, containing live/production ready features.
28+
29+
A `bedrock.yaml` for this service might look like:
30+
31+
```yaml
32+
rings:
33+
dev:
34+
isDefault: true
35+
qa:
36+
prod:
37+
services:
38+
./:
39+
displayName: "fabrikam"
40+
helm:
41+
chart:
42+
branch: master
43+
git: "https://dev.azure.com/fabrikam/frontend/_git/charts"
44+
path: frontend
45+
k8sBackend: "fabrikam-k8s-svc"
46+
k8sBackendPort: 80
47+
middlewares: []
48+
pathPrefix: "fabrikam-service"
49+
pathPrefixMajorVersion: "v1"
50+
variableGroups:
51+
- fabrikam-vg
52+
```
53+
54+
Each of the three entries under the `rings` object map one to one with a git
55+
branch in the application source repository. When this `bedrock.yaml` is
56+
deployed, and the container images for each of the `rings` are built and pushed
57+
for the `fabrikam` service, your cluster will have three running revisions of
58+
the `fabrikam` application - one each for `dev`, `qa`, and `prod`. A user is
59+
then able to invoke each revision by making HTTP requests to a single endpoint,
60+
decorated with the proper header for each Ring.
61+
62+
### How deploying service revisions with rings will work
63+
64+
Refer to the `bedrock.yaml` above, with the following rings, and thus git
65+
branches:
66+
67+
```
68+
- dev
69+
- prod
70+
- qa
71+
```
72+
73+
A user wants to add a ring `test-new-homepage`, they first ensure that the git
74+
branch exists:
75+
76+
- `git checkout dev -b test-new-homepage`
77+
78+
and then invoke the relevant `spk` command to add a `ring`:
79+
80+
- `spk ring create test-new-homepage`
81+
82+
This command will add an entry to our `rings` dictionary in `bedrock.yaml`, and
83+
modify all `build-update-hld` pipelines for services tracked in bedrock.yaml.
84+
Our revised `bedrock.yaml` will now look like:
85+
86+
```yaml
87+
rings:
88+
dev:
89+
isDefault: true
90+
qa:
91+
prod:
92+
test-new-homepage: <-- NEW -->
93+
services:
94+
./:
95+
displayName: "fabrikam"
96+
helm:
97+
chart:
98+
branch: master
99+
git: "https://dev.azure.com/fabrikam/frontend/_git/charts"
100+
path: frontend
101+
k8sBackend: "fabrikam-k8s-svc"
102+
k8sBackendPort: 80
103+
middlewares: []
104+
pathPrefix: "fabrikam-service"
105+
pathPrefixMajorVersion: "v1"
106+
variableGroups:
107+
- fabrikam-vg
108+
```
109+
110+
And the revised `build-update-hld` pipeline for the `fabrikam` service will now
111+
look like:
112+
113+
```yaml
114+
trigger:
115+
branches:
116+
include:
117+
- dev
118+
- qa
119+
- prod
120+
- test-new-homepage <-- NEW -->
121+
variables:
122+
- group: fabrikam-vg
123+
124+
```
125+
126+
_Note that the `test-new-homepage` branch name has been added to the branch
127+
include trigger_
128+
129+
A user is then expected to commit and push the `bedrock.yaml`, and the updated
130+
pipelines yaml files.
131+
132+
When a user commits to the `test-new-homepage` branch in the application
133+
repository, the `build-update-hld` pipeline will be able to build the container
134+
image with the changes to the source code from the `test-new-homepage` branch.
135+
It will continue to push the image to Azure Container Registry, and make a pull
136+
request against the High Level Definition repository with the newly built
137+
container image tag.
138+
139+
### Status Quo and current work
140+
141+
At present, `spk` is at version `0.5.4`, which _does_ not implement `ring`
142+
management commands - ie adding or removing a `ring` using a _more_ user
143+
friendly cli, however this work is being tracked in the following github issues:
144+
145+
- [Ring Management Docs and Implementation Epic](https://github.com/microsoft/bedrock/issues/955)
146+
- [Adding a Ring in SPK](https://github.com/microsoft/bedrock/issues/969)
147+
- [Deleting a Ring in SPK](https://github.com/microsoft/bedrock/issues/971)
148+
- [Setting a default Ring in SPK](https://github.com/microsoft/bedrock/issues/972)
149+
- [Removing a service and a ring from a Cluster](https://github.com/microsoft/bedrock/issues/858)
150+
151+
### Bridging the gap
152+
153+
While `ring` management features are not yet available in `spk`, we can bridge
154+
the gap to using `rings` with a few manual steps for configuration
155+
156+
#### Adding a Ring
157+
158+
See [this issue](https://github.com/microsoft/bedrock/issues/969) for details on
159+
how this feature will be implemented in `spk`.
160+
161+
To add a ring manually, an `spk` user can take the following steps:
162+
163+
1. Ensure a git branch exists with the same name of the `ring` to be added (eg:
164+
a `ring` named `test-new-feature` relies on a git branch with the same name,
165+
`test-new-feature`)
166+
2. In an application repository's `bedrock.yaml`, add the name of the `ring` to
167+
the top level `rings` object ie:
168+
169+
```yaml
170+
rings:
171+
dev:
172+
isDefault: true
173+
qa:
174+
prod:
175+
test-new-feature: <-- NEW -->
176+
177+
```
178+
179+
3. For _every_ service tracked in bedrock.yaml, ensure that service's
180+
`build-update-hld` pipeline is configured to trigger off of the `ring` branch
181+
ie:
182+
183+
```yaml
184+
trigger:
185+
branches:
186+
include:
187+
- dev
188+
- qa
189+
- prod
190+
- test-new-feature <-- NEW -->
191+
variables:
192+
- group: fabrikam-vg
193+
194+
```
195+
196+
4. Commit the changes to the `bedrock.yaml`, and all updated `build-update-hld`
197+
pipelines.
198+
5. Approve the generated Pull Request from the `hld-lifecycle` pipeline against
199+
the HLD repository. This Pull Request will add a new `ring` component for
200+
each service tracked in bedrock.yaml. The `ring` component is identified in
201+
the below diagram as `[Ring Component]`
202+
203+
![Sample HLD](./images/spk-hld-generated.png)
204+
205+
6. Change to the new `ring` branch: `test-new-feature`, and begin to commit, and
206+
push code as you normally would.
207+
208+
#### Deleting a Ring
209+
210+
See: [this issue](https://github.com/microsoft/bedrock/issues/971) for details
211+
on how this feature will be implemented in `spk`.
212+
213+
To delete a `ring` manually, an `spk` user can take the following steps:
214+
215+
1. In an application repository's `bedrock.yaml`, remove the name of the `ring`
216+
from the top level `rings` object ie:
217+
218+
Before:
219+
220+
```yaml
221+
rings:
222+
dev:
223+
isDefault: true
224+
qa:
225+
prod:
226+
test-new-feature: <-- DELETE -->
227+
228+
```
229+
230+
After:
231+
232+
```yaml
233+
rings:
234+
dev:
235+
isDefault: true
236+
qa:
237+
prod:
238+
239+
```
240+
241+
2. For _every_ service tracked in bedrock.yaml, ensure that service's
242+
`build-update-hld` pipeline is no longer configured to trigger off the `ring`
243+
branch ie:
244+
245+
Before:
246+
247+
```yaml
248+
trigger:
249+
branches:
250+
include:
251+
- dev
252+
- qa
253+
- prod
254+
- test-new-feature <-- DELETE -->
255+
variables:
256+
- group: fabrikam-vg
257+
258+
```
259+
260+
After:
261+
262+
```yaml
263+
trigger:
264+
branches:
265+
include:
266+
- dev
267+
- qa
268+
- prod
269+
variables:
270+
- group: fabrikam-vg
271+
272+
```
273+
274+
3. Commit the changes to the `bedrock.yaml`, and all updated `build-update-hld`
275+
pipelines.
276+
4. Observe that committing to the `test-new-feature` should no longer trigger
277+
builds.
278+
279+
_Do note that deleting a `ring` presently does not remove the service and `ring`
280+
from a cluster. This work is being
281+
[tracked here](https://github.com/microsoft/bedrock/issues/858) but the
282+
following instructions will detail how this can be done manually_
283+
284+
5. To remove a `ring` from a cluster, you must remove the `ring` component from
285+
the HLD. Recall the Pull Request generated by the `hld-lifecycle` pipeline
286+
when adding a `ring` to the `bedrock.yaml` file. The `ring` component is
287+
identified in the below diagram as `[Ring Component]`. In a clone of the HLD
288+
repository, one can delete the directory identified by `[Ring Component]`:
289+
290+
![Sample HLD](./images/spk-hld-generated.png)
291+
292+
6. Finally, a user must modify the `component.yaml` within the directory
293+
identified by `[Service Component]` in the above diagram to no longer point
294+
to the directory that was deleted. For our sample service, `fabrikam`, with a
295+
ring to be removed, `test-new-feature`, the Service Component
296+
`component.yaml` resembles this structure. A user can simply remove the
297+
`test-new-feature` entry in the subcomponents array:
298+
299+
```yaml
300+
name: fabrikam
301+
subcomponents:
302+
- name: dev
303+
type: component
304+
method: local
305+
path: ./dev
306+
- name: qa
307+
type: component
308+
method: local
309+
path: ./qa
310+
- name: prod
311+
type: component
312+
method: local
313+
path: ./prod
314+
- name: test-new-feature <-- DELETE -->
315+
type: component <-- DELETE -->
316+
method: local <-- DELETE -->
317+
path: ./test-new-feature <-- DELETE -->
318+
```
319+
320+
7. Finally, after ensuring the `component.yaml` has been updated, and the `ring`
321+
component directory in the HLD has been removed for the service, a user can
322+
commit and push the changes to a branch, merging it into the master branch of
323+
their HLD, and triggering a rebuild of manifests deployed to the cluster.

0 commit comments

Comments
 (0)