Initial setup of FluxCD v2 monorepo with Kustomize overlays and Helm releases

This commit is contained in:
emelinda 2026-04-07 11:11:00 +03:00
parent 51c98f5b9a
commit 6e525b15c9
19 changed files with 294 additions and 67 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.idea
.claude
CLAUDE.md

161
README.md
View File

@ -1,93 +1,120 @@
# iac
# FluxCD v2 Monorepo
Репозиторий Infrastructure as Code, управляемый [FluxCD v2](https://fluxcd.io/) с использованием Kustomize-оверлеев и Helm-релизов.
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
* [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
* [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
## Структура репозитория
```
cd existing_repo
git remote add origin https://gitlab.sarex.io/infra/iac.git
git branch -M master
git push -uf origin master
├── clusters/ # Точка входа для каждого кластера (Flux читает отсюда)
│ └── contour/ # Кластер contour
│ ├── flux-system/ # Автогенерируется через `flux bootstrap` (не редактировать)
│ ├── helm-repositories.yaml # Определения HelmRepository
│ ├── infrastructure.yaml # Flux Kustomization → ./infrastructure
│ └── apps.yaml # Flux Kustomization → ./apps
├── infrastructure/ # Инфраструктурные компоненты
│ ├── kustomization.yaml # Список всех инфра-сервисов
│ └── example-infra/ # Пример инфра-компонента
│ ├── kustomization.yaml # Собирает base + patches
│ ├── base/ # Базовые манифесты (namespace, HelmRelease)
│ └── patches/ # Патчи поверх base
├── apps/ # Прикладные сервисы
│ ├── kustomization.yaml # Список всех приложений
│ └── example-app/ # Пример приложения
│ ├── kustomization.yaml # Собирает base + patches
│ ├── base/ # Базовые манифесты (Deployment, Service, ConfigMap)
│ └── patches/ # Патчи поверх base
```
## Integrate with your tools
## Как это работает
* [Set up project integrations](https://gitlab.sarex.io/infra/iac/-/settings/integrations)
Flux отслеживает директорию `clusters/<имя-кластера>/`. Каждый кластер содержит два Flux Kustomization CRD верхнего уровня:
## Collaborate with your team
1. **infrastructure.yaml** — реконсилирует `./infrastructure`. Содержит HelmReleases и вспомогательные ресурсы.
2. **apps.yaml** — реконсилирует `./apps`. Содержит Deployments, Services и другие ресурсы приложений.
* [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
* [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
* [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
* [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
* [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
`apps` зависит от `infrastructure`, что гарантирует готовность инфраструктуры до деплоя приложений.
## Test and Deploy
Каждый сервис (в `infrastructure/` или `apps/`) имеет собственную структуру:
- **base/** — базовые манифесты, общие для всех окружений
- **patches/** — патчи, применяемые поверх base
- **kustomization.yaml** — на уровне сервиса, собирает base + patches через Kustomize
Use the built-in continuous integration in GitLab.
## Начало работы
* [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
* [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
### Бутстрап Flux
***
```bash
flux bootstrap git \
--url=<URL_ВАШЕГО_РЕПОЗИТОРИЯ> \
--branch=master \
--path=clusters/contour
```
# Editing this README
### Проверка реконсиляции
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
```bash
flux get kustomizations
flux get helmreleases -A
flux events --watch
```
## Suggestions for a good README
## Добавление нового инфраструктурного компонента
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
1. Создайте директорию с base и patches:
```
infrastructure/my-component/
├── kustomization.yaml # resources: [./base], patches: [patches/...]
├── base/
│ ├── kustomization.yaml
│ ├── namespace.yaml
│ └── helmrelease.yaml
└── patches/
└── values.yaml
```
## Name
Choose a self-explaining name for your project.
2. Зарегистрируйте в `infrastructure/kustomization.yaml`:
```yaml
resources:
- example-infra
- my-component # Добавьте эту строку
```
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
3. Если нужен новый HelmRepository, добавьте его в `clusters/<кластер>/helm-repositories.yaml`.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Добавление нового приложения
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
1. Создайте директорию с base и patches:
```
apps/my-app/
├── kustomization.yaml # resources: [./base], patches: [patches/...]
├── base/
│ ├── kustomization.yaml
│ ├── namespace.yaml
│ ├── deployment.yaml
│ └── service.yaml
└── patches/
└── replicas.yaml
```
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
2. Зарегистрируйте в `apps/kustomization.yaml`:
```yaml
resources:
- example-app
- my-app # Добавьте эту строку
```
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Добавление нового кластера
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
1. Создайте точку входа `clusters/<имя>/` с `infrastructure.yaml`, `apps.yaml` и `helm-repositories.yaml`
2. Выполните бутстрап Flux с `--path=clusters/<имя>`
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Справочник API-версий
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
| Ресурс | apiVersion |
|------------------|-----------------------------------------|
| Kustomization | `kustomize.toolkit.fluxcd.io/v1` |
| GitRepository | `source.toolkit.fluxcd.io/v1` |
| HelmRepository | `source.toolkit.fluxcd.io/v1` |
| HelmRelease | `helm.toolkit.fluxcd.io/v2` |

View File

@ -0,0 +1,9 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: example-app-config
namespace: example-app
data:
APP_ENV: "production"
LOG_LEVEL: "info"

View File

@ -0,0 +1,47 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-app
namespace: example-app
labels:
app.kubernetes.io/name: example-app
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: example-app
template:
metadata:
labels:
app.kubernetes.io/name: example-app
spec:
containers:
- name: example-app
image: nginx:1.27-alpine
ports:
- name: http
containerPort: 80
protocol: TCP
envFrom:
- configMapRef:
name: example-app-config
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 200m
memory: 128Mi
livenessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 5
periodSeconds: 10

View File

@ -0,0 +1,9 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: example-app
resources:
- namespace.yaml
- configmap.yaml
- deployment.yaml
- service.yaml

View File

@ -0,0 +1,5 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: example-app

View File

@ -0,0 +1,17 @@
---
apiVersion: v1
kind: Service
metadata:
name: example-app
namespace: example-app
labels:
app.kubernetes.io/name: example-app
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: example-app
ports:
- name: http
port: 80
targetPort: http
protocol: TCP

View File

@ -0,0 +1,10 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./base
patches:
- path: patches/replicas.yaml
target:
kind: Deployment
name: example-app

View File

@ -0,0 +1,9 @@
---
# Переопределения для example-app на кластере contour
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-app
namespace: example-app
spec:
replicas: 2

5
apps/kustomization.yaml Normal file
View File

@ -0,0 +1,5 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- example-app

View File

@ -0,0 +1,6 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../infrastructure
- ../../apps

View File

@ -0,0 +1,18 @@
---
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: ingress-nginx
namespace: flux-system
spec:
interval: 24h0m0s
url: https://kubernetes.github.io/ingress-nginx
---
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: bitnami
namespace: flux-system
spec:
interval: 24h0m0s
url: https://charts.bitnami.com/bitnami

View File

@ -0,0 +1,5 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../infrastructure

View File

@ -0,0 +1,22 @@
---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: example-infra
namespace: example-infra-system
spec:
interval: 30m0s
chart:
spec:
chart: nginx
version: ">=18.0.0"
sourceRef:
kind: HelmRepository
name: bitnami
namespace: flux-system
interval: 12h0m0s
values:
# Переопределение значений чарта
replicaCount: 1
service:
type: ClusterIP

View File

@ -0,0 +1,7 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: example-infra-system
resources:
- namespace.yaml
- helmrelease.yaml

View File

@ -0,0 +1,5 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: example-infra-system

View File

@ -0,0 +1,10 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./base
patches:
- path: patches/values.yaml
target:
kind: HelmRelease
name: example-infra

View File

@ -0,0 +1,10 @@
---
# Переопределения для example-infra на кластере contour
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: example-infra
namespace: example-infra-system
spec:
values:
replicaCount: 2

View File

@ -0,0 +1,5 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- example-infra