Skip to content

Commit 5c56bf5

Browse files
Initial commit RAW
0 parents  commit 5c56bf5

File tree

62 files changed

+1593
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1593
-0
lines changed

.claude/CLAUDE.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# CLAUDE.md
2+
3+
## Обзор проекта
4+
5+
GitOps-репозиторий для управления Kubernetes через ArgoCD. Использует App-of-Apps паттерн с Kustomize для управления несколькими окружениями.
6+
7+
## Структура
8+
9+
```
10+
clusters/ # Точки входа для каждого окружения (dev, prd)
11+
platform/ # Платформенные компоненты (infra, observability, gitops)
12+
tenants/ # Приложения команд
13+
policies/ # OPA Rego политики для валидации
14+
```
15+
16+
## Ключевые файлы
17+
18+
- `clusters/<env>/kustomization.yaml` — главный файл окружения, собирает все ресурсы
19+
- `clusters/<env>/destination.yaml` — патч для подстановки имени кластера
20+
- `platform/core/cluster-bootstrap/app-of-apps.yaml` — root ArgoCD Application
21+
- `platform/gitops/appsets/` — ApplicationSets для генерации Applications
22+
23+
## Паттерны
24+
25+
### ArgoCD Application
26+
Каждый компонент — это ArgoCD Application в `base/application.yaml`:
27+
- Helm charts указываются через `spec.source.repoURL` + `chart`
28+
- Kustomize через `spec.source.path`
29+
- `destination.name: CLUSTER` — placeholder, заменяется патчем
30+
31+
### Sync Waves
32+
`argocd.argoproj.io/sync-wave: "N"` — порядок деплоя (меньше = раньше)
33+
34+
### Image Updater
35+
Аннотации для автообновления образов:
36+
```yaml
37+
argocd-image-updater.argoproj.io/image-list: alias=registry/image:^1
38+
argocd-image-updater.argoproj.io/alias.update-strategy: semver
39+
argocd-image-updater.argoproj.io/write-back-method: git
40+
```
41+
42+
## Команды
43+
44+
```bash
45+
# Рендер манифестов
46+
kubectl kustomize clusters/dev/
47+
48+
# Валидация
49+
kubeconform -summary -strict rendered.yaml
50+
51+
# Проверка политик
52+
opa eval -f pretty -d policies/ -i rendered.yaml "data.kubernetes.deny[msg]"
53+
```
54+
55+
## Добавление компонента
56+
57+
1. Создай `platform/infrastructure/<category>/<name>/base/`
58+
2. Добавь `application.yaml` и `kustomization.yaml`
59+
3. Включи в `clusters/<env>/kustomization.yaml`
60+
61+
## Добавление tenant приложения
62+
63+
1. Создай `tenants/<team>/apps/<app>/base/`
64+
2. Добавь Application с нужными аннотациями
65+
3. Включи в `clusters/<env>/kustomization.yaml`
66+
67+
## Важно
68+
69+
- Все Applications деплоятся в namespace `argocd`
70+
- Секреты шифруются через sealed-secrets или тянутся через external-secrets
71+
- Политики в `policies/kubernetes.rego` проверяются в CI

.github/workflows/validate.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Validate K8s Manifests
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'platform/**'
7+
- 'clusters/**'
8+
- 'tenants/**'
9+
- 'policies/**'
10+
11+
jobs:
12+
validate:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
env: [dev]
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup tools
21+
run: |
22+
curl -LO https://github.com/yannh/kubeconform/releases/latest/download/kubeconform-linux-amd64.tar.gz
23+
tar -xf kubeconform-linux-amd64.tar.gz && sudo mv kubeconform /usr/local/bin
24+
curl -LO https://openpolicyagent.org/downloads/latest/opa_linux_amd64
25+
chmod +x opa_linux_amd64 && sudo mv opa_linux_amd64 /usr/local/bin/opa
26+
27+
- name: Validate Kustomize
28+
run: |
29+
kubectl kustomize clusters/${{ matrix.env }}/ > rendered.yaml
30+
31+
- name: Kubeconform validation
32+
run: kubeconform -summary -strict rendered.yaml
33+
34+
- name: OPA policy check
35+
run: |
36+
opa eval -f pretty -d policies/ -i rendered.yaml "data.kubernetes.deny[msg]"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rendered.yaml
2+
*.tgz
3+
.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Yevgeny Kulikov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# GitOps Kubernetes Platform
2+
3+
GitOps-репозиторий для управления Kubernetes-инфраструктурой через ArgoCD.
4+
5+
## Архитектура
6+
7+
```
8+
├── clusters/ # Конфигурации окружений
9+
│ ├── dev/ # Development кластер
10+
│ └── prd/ # Production кластер
11+
├── platform/ # Платформенные компоненты
12+
│ ├── core/ # Bootstrap ArgoCD, RBAC
13+
│ ├── gitops/ # ApplicationSets, Image Updater
14+
│ ├── infrastructure/ # Инфраструктура (nginx, cert-manager, storage)
15+
│ └── observability/ # Мониторинг (Grafana, Loki, OTEL)
16+
├── tenants/ # Приложения команд
17+
│ └── product-team/ # Tenant: product-team
18+
├── policies/ # OPA Rego политики
19+
└── .github/workflows/ # CI валидация
20+
```
21+
22+
## Как это работает
23+
24+
### App-of-Apps паттерн
25+
26+
1. **Root Application** (`platform/core/cluster-bootstrap/app-of-apps.yaml`) указывает на `clusters/<env>/`
27+
2. **Kustomization** (`clusters/<env>/kustomization.yaml`) собирает все ArgoCD Applications
28+
3. **Патчи** подставляют правильный destination кластер через `destination.yaml`
29+
30+
```
31+
Git Push → ArgoCD → Sync Applications → Kubernetes
32+
33+
argocd-image-updater (автообновление образов)
34+
```
35+
36+
### Sync Waves
37+
38+
Порядок деплоя контролируется через `argocd.argoproj.io/sync-wave`:
39+
- `0` — Ingress, базовая инфраструктура
40+
- `5` — Приложения (chat-api)
41+
42+
## Компоненты
43+
44+
### Infrastructure
45+
| Компонент | Описание |
46+
|-----------|----------|
47+
| ingress-nginx | Ingress controller |
48+
| cert-manager | TLS сертификаты (Let's Encrypt) |
49+
| external-dns | DNS записи в Cloudflare |
50+
| sealed-secrets | Шифрование секретов в git |
51+
| external-secrets | Синхронизация секретов из внешних хранилищ |
52+
| reflector | Репликация секретов между namespace |
53+
| longhorn | Distributed storage |
54+
55+
### Observability
56+
| Компонент | Описание |
57+
|-----------|----------|
58+
| Grafana | Дашборды и визуализация |
59+
| Loki | Агрегация логов |
60+
| OTEL Collector | Сбор телеметрии |
61+
62+
### AI Platform
63+
| Компонент | Описание |
64+
|-----------|----------|
65+
| Open WebUI | UI для LLM моделей |
66+
67+
## Добавление нового приложения
68+
69+
1. Создай директорию в `tenants/<team>/apps/<app>/base/`
70+
2. Добавь `application.yaml` с ArgoCD Application
71+
3. Добавь `kustomization.yaml`
72+
4. Включи в `clusters/<env>/kustomization.yaml`:
73+
```yaml
74+
resources:
75+
- ../../tenants/<team>/apps/<app>/base
76+
```
77+
78+
## Автообновление образов
79+
80+
Для автоматического обновления версий используется argocd-image-updater:
81+
82+
```yaml
83+
annotations:
84+
argocd-image-updater.argoproj.io/image-list: app=ghcr.io/org/app:^1
85+
argocd-image-updater.argoproj.io/app.update-strategy: semver
86+
argocd-image-updater.argoproj.io/write-back-method: git
87+
```
88+
89+
## CI/CD
90+
91+
GitHub Actions валидирует манифесты на каждый PR:
92+
93+
1. **Kustomize build** — рендеринг манифестов
94+
2. **Kubeconform** — валидация против JSON схем
95+
3. **OPA** — проверка политик безопасности
96+
97+
### Политики (policies/)
98+
99+
- Контейнеры должны иметь limits (cpu, memory)
100+
- Обязательные probes (liveness, readiness)
101+
- Запуск не от root (`runAsNonRoot: true`)
102+
- Наличие namespace
103+
- OTEL endpoint для телеметрии
104+
105+
## Локальная разработка
106+
107+
```bash
108+
# Рендеринг манифестов
109+
kubectl kustomize clusters/dev/
110+
111+
# Валидация
112+
kubeconform -summary -strict <(kubectl kustomize clusters/dev/)
113+
114+
# Проверка политик
115+
opa eval -f pretty -d policies/ -i rendered.yaml "data.kubernetes.deny[msg]"
116+
```
117+
118+
## Требования
119+
120+
- Kubernetes кластер
121+
- ArgoCD установлен в namespace `argocd`
122+
- Доступ к GitHub репозиторию
123+
124+
## Лицензия
125+
126+
MIT

clusters/dev/bootstrap.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# clusters/dev/bootstrap.yaml
2+
apiVersion: argoproj.io/v1alpha1
3+
kind: Application
4+
metadata:
5+
name: root-app-dev
6+
namespace: argocd
7+
spec:
8+
source:
9+
repoURL: https://github.com/justgithubaccount/app-release.git
10+
path: platform/core/cluster-bootstrap
11+
targetRevision: main
12+
destination:
13+
server: https://kubernetes.default.svc
14+
namespace: argocd

clusters/dev/chat-values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
helm:
2+
parameters:
3+
- name: image.name
4+
value: ghcr.io/justgithubaccount/chat-api
5+
forcestring: true
6+
- name: image.tag
7+
value: 1.1.7
8+
forcestring: true

clusters/dev/destination.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# infra/clusters/dev/destination.yaml
2+
apiVersion: argoproj.io/v1alpha1
3+
kind: Application
4+
metadata:
5+
name: all
6+
namespace: argocd
7+
spec:
8+
project: default
9+
destination:
10+
name: in-cluster

clusters/dev/kustomization.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
# All app names must be unique across the ArgoCD instance
4+
# So let's prefix the app names with the cluster name (dev- | demo-worker1-)
5+
# namePrefix: dev-
6+
resources:
7+
# Security
8+
- ../../platform/infrastructure/security/sealed-secrets/base
9+
- ../../platform/infrastructure/security/reflector/base
10+
- ../../platform/infrastructure/security/external-secrets/base
11+
# Networking
12+
- ../../platform/infrastructure/networking/nginx/base
13+
- ../../platform/infrastructure/networking/cert-manager/base
14+
- ../../platform/infrastructure/networking/external-dns/base
15+
# Storage
16+
- ../../platform/infrastructure/storage/longhorn/base
17+
# AI Platform
18+
- ../../platform/infrastructure/ai-platform/open-webui/base
19+
# Observability
20+
- ../../platform/observability/monitoring/loki
21+
- ../../platform/observability/monitoring/grafana
22+
- ../../platform/observability/opentelemetry/collector/otel-collector
23+
# GitOps
24+
- ../../platform/gitops/argocd-image-updater
25+
# Tenants
26+
- ../../tenants/product-team/apps/chat/base
27+
28+
patches:
29+
# Override .spec.destination.name
30+
- path: destination.yaml
31+
target:
32+
kind: Application
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Infrastructure values for dev cluster
2+
# Override helm values here
3+
4+
ingress-nginx:
5+
controller:
6+
replicaCount: 1
7+
8+
cert-manager:
9+
installCRDs: true
10+
11+
longhorn:
12+
persistence:
13+
defaultClassReplicaCount: 1

0 commit comments

Comments
 (0)