|
| 1 | +# Adding a new microservice |
| 2 | + |
| 3 | +This document outlines the steps required to add a new microservice to the Online Boutique application. |
| 4 | + |
| 5 | +## 1. Create a new directory |
| 6 | + |
| 7 | +Create a new directory for your microservice within the `src/` directory. The directory name should be the name of your microservice. |
| 8 | + |
| 9 | +## 2. Add source code |
| 10 | + |
| 11 | +Place your microservice's source code inside the newly created directory. The structure of this directory should follow the conventions of the existing microservices. For example, a Python-based service would include at minimum the following files: |
| 12 | + |
| 13 | +- `README.md`: The service's description and documentation. |
| 14 | +- `main.py`: The application's entry point. |
| 15 | +- `requirements.in`: A list of Python dependencies. |
| 16 | +- `Dockerfile`: To containerize the application. |
| 17 | + |
| 18 | +Take a look at existing microservices for inspiration. |
| 19 | + |
| 20 | +## 3. Create a Dockerfile |
| 21 | + |
| 22 | +Create a `Dockerfile` in your microservice's directory. This file will define the steps to build a container image for your service. |
| 23 | + |
| 24 | +Refer to this example and tweak based on your new service's needs: https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/src/frontend/Dockerfile |
| 25 | + |
| 26 | +## 4. Create Kubernetes manifests |
| 27 | + |
| 28 | +Create a new directory under `kustomize/components/` in the root of the repository for your microservice. Inside this directory, add the necessary Kubernetes YAML files for your new microservice. This typically includes: |
| 29 | + |
| 30 | +- A **Deployment** to manage your service's pods. |
| 31 | +- A **Service** to expose your microservice to other services within the cluster. |
| 32 | + |
| 33 | +Ensure you follow the existing naming conventions and that the container image specified in the Deployment matches the one built by your `cloudbuild.yaml` and `skaffold.yaml` files. |
| 34 | + |
| 35 | +Refer to this example and tweak based on your new service's needs: https://github.com/GoogleCloudPlatform/microservices-demo/tree/main/kustomize/components/shopping-assistant |
| 36 | + |
| 37 | +## 5. Update the root `kustomization.yaml` file |
| 38 | + |
| 39 | +Add your newly created component to the root kustomization file so it gets picked up by the deployment cycle. |
| 40 | + |
| 41 | +The file is available here: https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/kustomize/kustomization.yaml |
| 42 | + |
| 43 | +## 6. Update the root `skaffold.yaml` |
| 44 | + |
| 45 | +Add your newly created service to the root skaffold file so the images build correctly. |
| 46 | + |
| 47 | +The file is available here: https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/skaffold.yaml |
| 48 | + |
| 49 | +## 7. Update the Helm chart |
| 50 | + |
| 51 | +Add your newly created service to the Helm chart templates and default values. |
| 52 | + |
| 53 | +The chart is available here: https://github.com/GoogleCloudPlatform/microservices-demo/tree/main/helm-chart |
| 54 | + |
| 55 | +## 8. Update the documentation |
| 56 | + |
| 57 | +Finally, update the project's documentation to reflect the addition of your new microservice. This may include: |
| 58 | + |
| 59 | +- Adding a section to the main `README.md` if the service introduces significant new functionality. |
| 60 | +- Updating the architecture diagrams in the `docs/img` directory. |
| 61 | +- Adding a new document in the `docs` directory if the service requires detailed explanation. |
0 commit comments