1
---
2
name: gitops-workflow
3
description: Implement GitOps workflows with ArgoCD and Flux for automated, declarative Kubernetes deployments with continuous reconciliation. Use when implementing GitOps practices, automating Kubernetes deployments, or setting up declarative infrastructure management.
4
---
5
6
# GitOps Workflow
7
8
Complete guide to implementing GitOps workflows with ArgoCD and Flux for automated Kubernetes deployments.
9
10
## Purpose
11
12
Implement declarative, Git-based continuous delivery for Kubernetes using ArgoCD or Flux CD, following OpenGitOps principles.
13
14
## When to Use This Skill
15
16
- Set up GitOps for Kubernetes clusters
17
- Automate application deployments from Git
18
- Implement progressive delivery strategies
19
- Manage multi-cluster deployments
20
- Configure automated sync policies
21
- Set up secret management in GitOps
22
23
## OpenGitOps Principles
24
25
1. **Declarative** - Entire system described declaratively
26
2. **Versioned and Immutable** - Desired state stored in Git
27
3. **Pulled Automatically** - Software agents pull desired state
28
4. **Continuously Reconciled** - Agents reconcile actual vs desired state
29
30
## ArgoCD Setup
31
32
### 1. Installation
33
34
```bash
35
# Create namespace
36
kubectl create namespace argocd
37
38
# Install ArgoCD
39
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
40
41
# Get admin password
42
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
43
```
44
45
**Reference:** See `references/argocd-setup.md` for detailed setup
46
47
### 2. Repository Structure
48
49
```
50
gitops-repo/
51
├── apps/
52
│ ├── production/
53
│ │ ├── app1/
54
│ │ │ ├── kustomization.yaml
55
│ │ │ └── deployment.yaml
56
│ │ └── app2/
57
│ └── staging/
58
├── infrastructure/
59
│ ├── ingress-nginx/
60
│ ├── cert-manager/
61
│ └── monitoring/
62
└── argocd/
63
├── applications/
64
└── projects/
65
```
66
67
### 3. Create Application
68
69
```yaml
70
# argocd/applications/my-app.yaml
71
apiVersion: argoproj.io/v1alpha1
72
kind: Application
73
metadata:
74
name: my-app
75
namespace: argocd
76
spec:
77
project: default
78
source:
79
repoURL: https://github.com/org/gitops-repo
80
targetRevision: main
81
path: apps/production/my-app
82
destination:
83
server: https://kubernetes.default.svc
84
namespace: production
85
syncPolicy:
86
automated:
87
prune: true
88
selfHeal: true
89
syncOptions:
90
- CreateNamespace=true
91
```
92
93
### 4. App of Apps Pattern
94
95
```yaml
96
apiVersion: argoproj.io/v1alpha1
97
kind: Application
98
metadata:
99
name: applications
100
namespace: argocd
101
spec:
102
project: default
103
source:
104
repoURL: https://github.com/org/gitops-repo
105
targetRevision: main
106
path: argocd/applications
107
destination:
108
server: https://kubernetes.default.svc
109
namespace: argocd
110
syncPolicy:
111
automated: {}
112
```
113
114
## Flux CD Setup
115
116
### 1. Installation
117
118
The example uses Homebrew. For other systems, follow the
119
[official Flux installation guide](https://fluxcd.io/flux/installation/).
120
121
```bash
122
# Install the Flux CLI with Homebrew
123
brew install fluxcd/tap/flux
124
flux check --pre
125
126
# Bootstrap Flux
127
flux bootstrap github \
128
--owner=org \
129
--repository=gitops-repo \
130
--branch=main \
131
--path=clusters/production \
132
--personal
133
```
134
135
### 2. Create GitRepository
136
137
```yaml
138
apiVersion: source.toolkit.fluxcd.io/v1
139
kind: GitRepository
140
metadata:
141
name: my-app
142
namespace: flux-system
143
spec:
144
interval: 1m
145
url: https://github.com/org/my-app
146
ref:
147
branch: main
148
```
149
150
### 3. Create Kustomization
151
152
```yaml
153
apiVersion: kustomize.toolkit.fluxcd.io/v1
154
kind: Kustomization
155
metadata:
156
name: my-app
157
namespace: flux-system
158
spec:
159
interval: 5m
160
path: ./deploy
161
prune: true
162
sourceRef:
163
kind: GitRepository
164
name: my-app
165
```
166
167
## Sync Policies
168
169
### Auto-Sync Configuration
170
171
**ArgoCD:**
172
173
```yaml
174
syncPolicy:
175
automated:
176
prune: true # Delete resources not in Git
177
selfHeal: true # Reconcile manual changes
178
allowEmpty: false
179
retry:
180
limit: 5
181
backoff:
182
duration: 5s
183
factor: 2
184
maxDuration: 3m
185
```
186
187
**Flux:**
188
189
```yaml
190
spec:
191
interval: 1m
192
prune: true
193
wait: true
194
timeout: 5m
195
```
196
197
**Reference:** See `references/sync-policies.md`
198
199
## Progressive Delivery
200
201
### Canary Deployment with ArgoCD Rollouts
202
203
```yaml
204
apiVersion: argoproj.io/v1alpha1
205
kind: Rollout
206
metadata:
207
name: my-app
208
spec:
209
replicas: 5
210
strategy:
211
canary:
212
steps:
213
- setWeight: 20
214
- pause: { duration: 1m }
215
- setWeight: 50
216
- pause: { duration: 2m }
217
- setWeight: 100
218
```
219
220
### Blue-Green Deployment
221
222
```yaml
223
strategy:
224
blueGreen:
225
activeService: my-app
226
previewService: my-app-preview
227
autoPromotionEnabled: false
228
```
229
230
## Secret Management
231
232
### External Secrets Operator
233
234
```yaml
235
apiVersion: external-secrets.io/v1beta1
236
kind: ExternalSecret
237
metadata:
238
name: db-credentials
239
spec:
240
refreshInterval: 1h
241
secretStoreRef:
242
name: aws-secrets-manager
243
kind: SecretStore
244
target:
245
name: db-credentials
246
data:
247
- secretKey: password
248
remoteRef:
249
key: prod/db/password
250
```
251
252
### Sealed Secrets
253
254
```bash
255
# Encrypt secret
256
kubeseal --format yaml < secret.yaml > sealed-secret.yaml
257
258
# Commit sealed-secret.yaml to Git
259
```
260
261
## Best Practices
262
263
1. **Use separate repos or branches** for different environments
264
2. **Implement RBAC** for Git repositories
265
3. **Enable notifications** for sync failures
266
4. **Use health checks** for custom resources
267
5. **Implement approval gates** for production
268
6. **Keep secrets out of Git** (use External Secrets)
269
7. **Use App of Apps pattern** for organization
270
8. **Tag releases** for easy rollback
271
9. **Monitor sync status** with alerts
272
10. **Test changes** in staging first
273
274
## Troubleshooting
275
276
**Sync failures:**
277
278
```bash
279
argocd app get my-app
280
argocd app sync my-app --prune
281
```
282
283
**Out of sync status:**
284
285
```bash
286
argocd app diff my-app
287
argocd app sync my-app --force
288
```
289
290
## Related Skills
291
292
- `k8s-manifest-generator` - For creating manifests
293
- `helm-chart-scaffolding` - For packaging applications
294