Sources (GitRepository, HelmRepository)
Table of Contentsβ
1 - Source conceptβ
What is a Source?β
A Source defines where Flux fetches the configurations to deploy.
Source typesβ
| Type | Description | Use case |
|---|---|---|
| GitRepository | Git repo | YAML manifests, Kustomize |
| HelmRepository | Helm HTTP repo | Helm charts |
| OCIRepository | OCI registry | OCI charts, artifacts |
| Bucket | S3, GCS, Minio | Stored artifacts |
π Back to table of contentsβ
2 - GitRepositoryβ
Public repositoryβ
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: podinfo
namespace: flux-system
spec:
interval: 1m
url: https://github.com/stefanprodan/podinfo
ref:
branch: master
Private repository (HTTPS)β
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: my-private-repo
namespace: flux-system
spec:
interval: 1m
url: https://github.com/my-org/private-repo
ref:
branch: main
secretRef:
name: git-credentials
---
apiVersion: v1
kind: Secret
metadata:
name: git-credentials
namespace: flux-system
type: Opaque
stringData:
username: git
password: <github-token>
Private repository (SSH)β
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: my-private-repo
namespace: flux-system
spec:
interval: 1m
url: ssh://[email protected]/my-org/private-repo.git
ref:
branch: main
secretRef:
name: ssh-credentials
---
apiVersion: v1
kind: Secret
metadata:
name: ssh-credentials
namespace: flux-system
type: Opaque
stringData:
identity: |
-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----
known_hosts: |
github.com ssh-rsa AAAA...
Reference a tag or commitβ
spec:
ref:
# Par branche
branch: main
# Par tag
tag: v1.2.3
# Par semver
semver: ">=1.0.0 <2.0.0"
# Par commit
commit: abc123def456
Via CLIβ
# CrΓ©er un GitRepository
flux create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--branch=master \
--interval=1m
# Avec authentication
flux create source git private-repo \
--url=ssh://[email protected]/my-org/repo.git \
--branch=main \
--secret-ref=ssh-credentials
π Back to table of contentsβ
3 - HelmRepositoryβ
Public repositoryβ
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: bitnami
namespace: flux-system
spec:
interval: 1h
url: https://charts.bitnami.com/bitnami
Private repositoryβ
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: private-charts
namespace: flux-system
spec:
interval: 1h
url: https://charts.example.com
secretRef:
name: helm-credentials
---
apiVersion: v1
kind: Secret
metadata:
name: helm-credentials
namespace: flux-system
type: Opaque
stringData:
username: admin
password: <password>
Via CLIβ
flux create source helm bitnami \
--url=https://charts.bitnami.com/bitnami \
--interval=1h
π Back to table of contentsβ
4 - OCIRepositoryβ
OCI chartsβ
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: OCIRepository
metadata:
name: podinfo
namespace: flux-system
spec:
interval: 5m
url: oci://ghcr.io/stefanprodan/charts/podinfo
ref:
tag: 6.5.0
With authenticationβ
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: OCIRepository
metadata:
name: private-chart
namespace: flux-system
spec:
interval: 5m
url: oci://registry.example.com/charts/myapp
ref:
semver: ">=1.0.0"
secretRef:
name: oci-credentials
---
apiVersion: v1
kind: Secret
metadata:
name: oci-credentials
namespace: flux-system
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: <base64-encoded-docker-config>
π Back to table of contentsβ
5 - Bucket (S3)β
AWS S3β
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: Bucket
metadata:
name: artifacts
namespace: flux-system
spec:
interval: 5m
provider: aws
bucketName: my-artifacts-bucket
region: us-east-1
secretRef:
name: aws-credentials
Minioβ
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: Bucket
metadata:
name: minio-artifacts
namespace: flux-system
spec:
interval: 5m
provider: generic
endpoint: minio.example.com
bucketName: flux-artifacts
secretRef:
name: minio-credentials
π Back to table of contentsβ
6 - Hands-on exercisesβ
Exercise 1: Create a GitRepositoryβ
# Via CLI
flux create source git demo-app \
--url=https://github.com/stefanprodan/podinfo \
--branch=master \
--interval=1m
# VΓ©rifier
flux get sources git
Exercise 2: GitRepository YAMLβ
# demo-source.yaml
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: demo-app
namespace: flux-system
spec:
interval: 1m
url: https://github.com/stefanprodan/podinfo
ref:
branch: master
kubectl apply -f demo-source.yaml
flux get sources git
Quizβ
Q1. What is the difference between GitRepository and HelmRepository?
Answer
- GitRepository: Fetches files from a Git repo (YAML, Kustomize, local charts)
- HelmRepository: Fetches charts from a Helm HTTP repo (index.yaml)
GitRepository is more flexible, HelmRepository is specific to Helm charts.
Q2. How do you reference a specific tag in a GitRepository?
Answer
spec:
ref:
tag: v1.2.3
Or with semver for the latest compatible tag:
spec:
ref:
semver: ">=1.0.0 <2.0.0"
π Back to table of contentsβ
Key takeawaysβ
- Source = definition of the origin of configs
- GitRepository: Git repos (YAML, Kustomize)
- HelmRepository: Helm HTTP repos
- OCIRepository: OCI registries
- Secrets for authentication
interval: polling frequency