[Video Course][Siddharth Barahalikar] FluxCD 101 with Hands-On Labs [ENG, 2023][~5h 45m]


03. Source and Kustomize Controller


LAB 2 - Deploy Application Manifest - Flux Repo


$ cd bb-app-source/
$ git switch 1-demo
$ git pull


$ flux get sources git
NAME       	REVISION          	SUSPENDED	READY	MESSAGE
flux-system	main@sha1:9f2d417a	False    	True 	stored artifact for revision 'main@sha1:9f2d417a'


$ flux get kustomization
NAME       	REVISION          	SUSPENDED	READY	MESSAGE
flux-system	main@sha1:9f2d417a	False    	True 	Applied revision: main@sha1:9f2d417a


Скопировали манифесты из bb-app-source/manifests в каталог clusters/my-cluster/1-demo

commit / push


// Должно появиться 1-demo
$ kubectl get ns
NAME                        STATUS   AGE
1-demo                      Active   28s
***


$ kubectl -n 1-demo get all
NAME                                READY   STATUS    RESTARTS   AGE
pod/block-buster-7c7c5bd4d8-2ggrb   1/1     Running   0          75s

NAME                           TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
service/block-buster-service   NodePort   10.108.171.222   <none>        80:30001/TCP   75s

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/block-buster   1/1     1            1           75s

NAME                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/block-buster-7c7c5bd4d8   1         1         1       75s


$ export PROFILE=${USER}-minikube
$ minikube --profile ${PROFILE} ip


// OK!
http://192.168.49.2:30001


// Посмотреть где в итоге хранятся манифесты
$ kubectl -n flux-system get pods
$ kubectl -n flux-system exec -it source-controller-664f9c8869-c6nj8 -- sh
$ cd data/gitrepository/flux-system/flux-system/
$ ls
035ab64a849b04b2595d837e6a80d0eb4eb22001.tar.gz
035ab64a849b04b2595d837e6a80d0eb4eb22001.tar.gz.lock

$ tar -tf 035ab64a849b04b2595d837e6a80d0eb4eb22001.tar.gz
.
clusters
clusters/my-cluster
clusters/my-cluster/1-demo
clusters/my-cluster/1-demo/deployment.yml
clusters/my-cluster/1-demo/namespace.yml
clusters/my-cluster/1-demo/service.yml
clusters/my-cluster/flux-system
clusters/my-cluster/flux-system/gotk-components.yaml
clusters/my-cluster/flux-system/gotk-sync.yaml
clusters/my-cluster/flux-system/kustomization.yaml


LAB 3 - Deploy Application Manifest - External Git Repo


$ git switch 2-demo


// Посмотреть, но не создавать
$ flux create source git 2-demo-source-git-bb-app \
  --url https://github.com/wildmakaka/bb-app-source \
  --branch=2-demo \
  --timeout 10s \
  --export


// Создать
$ flux create source git 2-demo-source-git-bb-app \
  --url https://github.com/wildmakaka/bb-app-source \
  --branch=2-demo \
  --timeout 10s


$ flux get sources git
NAME                    	REVISION            	SUSPENDED	READY	MESSAGE
2-demo-source-git-bb-app	2-demo@sha1:310e0bea	False    	True 	stored artifact for revision '2-demo@sha1:310e0bea'
flux-system             	main@sha1:035ab64a  	False    	True 	stored artifact for revision 'main@sha1:035ab64a'


$ flux delete source git 2-demo-source-git-bb-app


$ cd ~/projects/fluxcd/block-buster/clusters/my-cluster/


// Создать yaml
$ flux create source git 2-demo-source-git-bb-app \
  --url https://github.com/wildmakaka/bb-app-source \
  --branch=2-demo \
  --timeout 10s \
  --export > 2-demo-source-git-bb-app.yaml


// Создать yaml
$ flux create kustomization 2-demo-source-git-bb-app \
  --source GitRepository/2-demo-source-git-bb-app \
  --prune true \
  --interval 10s \
  --target-namespace 2-demo \
  --path manifests \
  --export > 2-demo-kustomize-git-bb-app.yaml


// Добавились новые REVISION
$ flux get sources git
$ flux get kustomizations


$ kubectl get ns
NAME                        STATUS   AGE
1-demo                      Active   49m
2-demo                      Active   44s
***


// OK!
http://192.168.49.2:30002


$ kubectl -n 2-demo get all


// Пришлось останавливать ранее запущенное приложение, т.к. мало cpu.
// OK!
http://192.168.49.2:30002


Продолжение


$ git switch 3-demo


$ cd ~/projects/fluxcd/block-buster/clusters/my-cluster/


$ flux create source git 3-demo-source-git-bb-app \
  --url https://github.com/wildmakaka/bb-app-source \
  --branch=3-demo \
  --timeout 10s \
  --export > 3-demo-source-git-bb-app.yaml


$ flux create kustomization 3-demo-source-git-bb-app \
  --source GitRepository/3-demo-source-git-bb-app \
  --prune true \
  --interval 10s \
  --target-namespace 3-demo \
  --path kustomize \
  --export > 3-demo-kustomize-git-bb-app.yaml


$ flux get sources git
$ kubectl get ns


$ kubectl -n 3-demo get all


// Пришлось останавливать ранее запущенное приложение, т.к. мало cpu.
// OK!
http://192.168.49.2:30003


LAB 4 - Deploy Application Manifest from a S3 Repo


$ git switch 4-demo


$ kubectl apply -f minio/minio-s3.yaml


$ kubectl -n minio-dev get all


// OK!
// minioadmin / minioadmin
http://192.168.49.2:30040/


Buckets -> create bucket
name: bucket-bb-app


Object Browser -> Create new path
name: app-740


Upload: manifests


$ flux create source bucket 4-demo-source-minio-s3-bucket-bb-app \
  --bucket-name bucket-bb-app \
  --secret-ref minio-crds \
  --endpoint minio.minio-dev.svc.cluster.local:9000 \
  --provider generic \
  --insecure \
  --export > 4-demo-source-minio-s3-bucket-bb-app.yaml


$ flux create kustomization 4-demo-kustomize-minio-s3-bucket-bb-app \
  --source Bucket/4-demo-source-minio-s3-bucket-bb-app \
  --target-namespace 4-demo \
  --path ./app-740 \
  --prune true \
  --export > 4-demo-kustomize-minio-s3-bucket-bb-app.yaml


$ kubectl -n flux-system create secret generic minio-crds \
    --from-literal=accesskey=minioadmin \
    --from-literal=secretkey=minioadmin


commit / push


$ flux get source bucket
NAME                                	REVISION       	SUSPENDED	READY	MESSAGE
4-demo-source-minio-s3-bucket-bb-app	sha256:cce16a8a	False    	True 	stored artifact: revision 'sha256:cce16a8a'


// При необходимости
$ flux reconcile source bucket 4-demo-source-minio-s3-bucket-bb-app


$ kubectl -n 4-demo get all


// Пришлось останавливать ранее запущенное приложение, т.к. мало cpu.
// OK!
http://192.168.49.2:30004