|
| 1 | +# Services management |
| 2 | + |
| 3 | +The deployment defines multiple service (or application), each being a |
| 4 | +collection of kubernetes manifests located in `src/<service>/`. |
| 5 | + |
| 6 | +## Structure |
| 7 | + |
| 8 | +- `external/`: third party resources |
| 9 | +- `src/`: deployable manifests |
| 10 | +- secrets are encrypted with sops+age and persisted in `src/secrets/` |
| 11 | + |
| 12 | +Each service is structured as follows (supported tools are `ytt` and `helm`): |
| 13 | + |
| 14 | +```text |
| 15 | +├── external |
| 16 | +│ └── <tool> |
| 17 | +│ └── <service>/... # <- third party templates |
| 18 | +└── src |
| 19 | + └── <service> |
| 20 | + ├── additional-manifest.yaml # <- custom manifests for this deployment |
| 21 | + ├── kustomization.yaml # <- kustomization file to select resources |
| 22 | + └── <tool> |
| 23 | + ├── out/... # <- rendered manifests |
| 24 | + └── values.yaml # <- values used for templating |
| 25 | +``` |
| 26 | + |
| 27 | +## Templating |
| 28 | + |
| 29 | +[ytt](https://carvel.dev/ytt) is the preferred rendering engine, but helm is |
| 30 | +also supported as many upstream templates are distributed with |
| 31 | +[helm](https://helm.sh). |
| 32 | + |
| 33 | +When running `just render`, we attempt to render each service with helm and then |
| 34 | +with ytt and save the rendered manifests in the repository. |
| 35 | + |
| 36 | +## Deployment |
| 37 | + |
| 38 | +When deploying with `just deploy`, deployment is done with kustomize |
| 39 | +(`kubectl -k`). This means that the `src` and each of its subdirectories contain |
| 40 | +a `kustomization.yaml` file which determine what manifests are included in the |
| 41 | +deployment. |
| 42 | + |
| 43 | +For example, running `just deploy src/` will recursively parse |
| 44 | +`src/kustomization.yaml` and the `kustomization.yaml` from each resources |
| 45 | +declared in that file. This allows to simply exclude services or manifests by |
| 46 | +commenting them out of `kustomization.yaml`. |
| 47 | + |
| 48 | +## Updating a service |
| 49 | + |
| 50 | +Here is the typical workflow to re-deploy a service that has been updated |
| 51 | +upstream. |
| 52 | + |
| 53 | +1. Update the external manifest templates. This will update the `vendir` lock |
| 54 | + file and fetch the latest templates into `external/<tool>/<service>`. |
| 55 | + |
| 56 | +```bash |
| 57 | +just external::refresh |
| 58 | +``` |
| 59 | + |
| 60 | +2. Render the manifests with the new templates. |
| 61 | + |
| 62 | +```bash |
| 63 | +just render |
| 64 | +``` |
| 65 | + |
| 66 | +> [!NOTE] |
| 67 | +> This may fail if the new templates broke compatibility with existing values, |
| 68 | +> in which case you will need to update your values in |
| 69 | +> `src/<service>/<tool>/values.yaml`. Also watch out in case the upstream added |
| 70 | +> new template files, as you may need to include them in the service |
| 71 | +> `kustomization.yaml`. |
| 72 | +
|
| 73 | +3. Deploy the updated manifests. |
| 74 | + |
| 75 | +```bash |
| 76 | +just deploy src/<service> |
| 77 | +``` |
| 78 | + |
| 79 | +> [!IMPORTANT] |
| 80 | +> In some cases, you may want to manually delete resources related to the |
| 81 | +> service. You can achieve that with `just delete src/<service>` or use |
| 82 | +> `kubectl delete` to delete specific resoruces. |
| 83 | +
|
| 84 | +## Adding custom manifests |
| 85 | + |
| 86 | +Custom manifests (e.g. additional volumes) can be added inside `src/<service>/`, |
| 87 | +but they need to be added as a resource in `kustomization.yaml` file in the same |
| 88 | +directory. |
0 commit comments