In the world of K8s, there is a very strong trending topic: Gitops. Which involves the use of Git + Fluxcd operator. Most people think that GitOps is something that belongs to Github, which is wrong. It can be used with any service that offers the use of git for code versioning, for example: CodeCommit.
Taken from https://fluxcd.io/docs/
Cluster creation
eksctl create cb-cluster
Flux Installation for AWS CodeCommit
Clone the Git repository locally:
git clone ssh://git-codecommit.<region>.amazonaws.com/v1/repos/<my-cb-repository>
cd my-cb-repository
Create a directory inside the repository:
mkdir -p ./clusters/my-cb-cluster/flux-system
Download the Flux CLI and generate the manifests with:
flux install \
--export > ./clusters/my-cb-cluster/flux-system/gotk-components.yaml
Commit and push the manifest to the master branch:
git add -A && git commit -m "add flux components" && git push
Apply the manifests on your cluster:
kubectl apply -f ./clusters/my-cb-cluster/flux-system/gotk-components.yaml
Verify that the controllers have started:
flux check
Create a GitRepository object on your cluster by specifying the SSH address (my recommendation) of your repo:
flux create source git flux-system \
--git-implementation=libgit2 \
--url=ssh://git-codecommit.<region>.amazonaws.com/v1/repos/<my-repository> \
--branch=<branch> \
--ssh-key-algorithm=rsa \
--ssh-rsa-bits=4096 \
--interval=1m
If you prefer to use Git over HTTPS, then generate git credentials for HTTPS connections to codecommit and use these details as the username/password:
flux create source git flux-system \
--git-implementation=libgit2 \
--url=https://git-codecommit.<region>.amazonaws.com/v1/repos/<my-repository> \
--branch=main \
--username=${AWS_IAM_GC_USER} \
--password=${AWS_IAM_GC_PASS} \
--interval=1m
Create a Kustomization object on your cluster:
flux create kustomization flux-system \
--source=flux-system \
--path="./clusters/my-cb-cluster" \
--prune=true \
--interval=10m
Export both objects, generate a kustomization.yaml, commit and push the manifests to Git:
flux export source git flux-system \
> ./clusters/my-cb-cluster/flux-system/gotk-sync.yaml
flux export kustomization flux-system \
>> ./clusters/my-cb-cluster/flux-system/gotk-sync.yaml
cd ./clusters/my-cb-cluster/flux-system && kustomize create --autodetect
git add -A && git commit -m "add sync manifests files" && git push
Wait for Flux to get your previous commit with:
flux get kustomizations --watch
Conclusions
No more manual deploys, you can delegate it to Flux. Try and move to the new ways to work on K8s on AWS.
Top comments (0)