Flux
Flux CD
A GitOps tool for Kubernetes. A CNCF project.
Flux CD
A GitOps tool for Kubernetes. A CNCF project.
Flux is a GitOps continuous delivery (CD) tool for Kubernetes. It was developed by Weaveworks and is now a CNCF graduated project. It automatically synchronizes the declarative configuration in a Git repository to the cluster, continuously maintaining the "desired state."
# git-repository.yaml
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: my-app
namespace: flux-system
spec:
interval: 1m
url: https://github.com/myorg/my-app-config
ref:
branch: main
secretRef:
name: github-token # ํ๋ผ์ด๋น ์ ์ฅ์์ฉ
---
# Secret for private repository
apiVersion: v1
kind: Secret
metadata:
name: github-token
namespace: flux-system
stringData:
username: git
password: ${GITHUB_TOKEN}
# kustomization.yaml - Flux Kustomization ๋ฆฌ์์ค
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: my-app
namespace: flux-system
spec:
interval: 10m
targetNamespace: production
sourceRef:
kind: GitRepository
name: my-app
path: ./deploy/production
prune: true # Git์์ ์ญ์ ๋ ๋ฆฌ์์ค ์๋ ์ ๋ฆฌ
healthChecks:
- apiVersion: apps/v1
kind: Deployment
name: my-app
namespace: production
timeout: 5m
# ๋ณ์ ์นํ
postBuild:
substitute:
CLUSTER_NAME: prod-cluster
ENVIRONMENT: production
substituteFrom:
- kind: ConfigMap
name: cluster-config
---
# ์์กด์ฑ ์๋ ๋ฐฐํฌ
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: my-app-db
namespace: flux-system
spec:
interval: 10m
sourceRef:
kind: GitRepository
name: my-app
path: ./deploy/database
prune: true
---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: my-app-api
namespace: flux-system
spec:
dependsOn:
- name: my-app-db # DB๊ฐ ๋จผ์ ๋ฐฐํฌ๋ ํ API ๋ฐฐํฌ
interval: 10m
sourceRef:
kind: GitRepository
name: my-app
path: ./deploy/api
prune: true
# helm-release.yaml
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: bitnami
namespace: flux-system
spec:
interval: 1h
url: https://charts.bitnami.com/bitnami
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: redis
namespace: production
spec:
interval: 10m
chart:
spec:
chart: redis
version: "17.x"
sourceRef:
kind: HelmRepository
name: bitnami
namespace: flux-system
values:
architecture: replication
replica:
replicaCount: 3
auth:
existingSecret: redis-password
# ์
๊ทธ๋ ์ด๋/๋กค๋ฐฑ ์ค์
upgrade:
remediation:
retries: 3
rollback:
cleanupOnFail: true
# image-automation.yaml
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageRepository
metadata:
name: my-app
namespace: flux-system
spec:
image: docker.io/myorg/my-app
interval: 1m
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImagePolicy
metadata:
name: my-app
namespace: flux-system
spec:
imageRepositoryRef:
name: my-app
policy:
semver:
range: ">=1.0.0"
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageUpdateAutomation
metadata:
name: my-app
namespace: flux-system
spec:
interval: 1m
sourceRef:
kind: GitRepository
name: my-app
git:
checkout:
ref:
branch: main
commit:
author:
email: fluxbot@myorg.com
name: Flux Bot
messageTemplate: |
Automated image update
- {{range .Updated.Images}}{{println .}}{{end}}
push:
branch: main
When `prune: true` is set, resources deleted from Git are also deleted from the cluster. If you delete a file by mistake, production resources may disappear, so be careful.
Do not store plaintext Secrets in Git. Use Mozilla SOPS, Sealed Secrets, or an external secrets manager (Vault).
If the interval is too short, it can put load on the Git server, and if it is too long, deployment delays occur. In general, 1-5 minutes is appropriate.
Flux itself is also managed via GitOps, so plan the dependency order carefully during the initial bootstrap.