FluxCD 基本安裝

Jeff Yen
2 min readAug 16, 2024

--

123

Install the Flux CLI

第一步當然是安裝FluxCD的CLI,而且跟arocd不一樣的是,在後面很多步驟會用cli安裝和執行.

brew install fluxcd/tap/flux

準備環境變數和檢查

export GITHUB_TOKEN=<your-token>
export GITHUB_USER=<your-username>
flux check --pre

Install Flux onto your cluster

然後跑指令安裝

flux bootstrap github \
--owner=$GITHUB_USER \
--repository=fleet-infra \
--branch=main \
--path=./clusters/my-cluster \
--personal

他也會幫忙生成github repo

Clone the git repository

git clone https://github.com/$GITHUB_USER/fleet-infra
cd fleet-infra

Add podinfo repository to Flux

使用官方用go寫的web,github.com/stefanprodan/podinfo

flux create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--branch=master \
--interval=1m \
--export > ./clusters/my-cluster/podinfo-source.yaml

Deploy podinfo application

我用Flux CLI建置的kustomization的repo

flux create kustomization podinfo \
--target-namespace=default \
--source=podinfo \
--path="./kustomize" \
--prune=true \
--wait=true \
--interval=30m \
--retry-interval=2m \
--health-check-timeout=3m \
--export > ./clusters/my-cluster/podinfo-kustomization.yaml

一樣git commit

git add -A && git commit -m "Add podinfo Kustomization"
git push

Watch Flux sync the application

使用flux get去觀察狀態

flux get kustomizations --watch

kubectl -n default get deployments,services

Customize podinfo deployment

使用Flux in-line patches.以下範例展示如何使用patch來變更 podinfo 部署。

等git push剛剛的設定後,檢查pod有沒有變三個

--

--