DEV Community

Falcon for AWS Community Builders

Posted on

Flux on AWS (EKS)

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.

Image description

Taken from https://fluxcd.io/docs/

Cluster creation

eksctl create cb-cluster
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Create a directory inside the repository:

mkdir -p ./clusters/my-cb-cluster/flux-system
Enter fullscreen mode Exit fullscreen mode

Download the Flux CLI and generate the manifests with:

flux install \
  --export > ./clusters/my-cb-cluster/flux-system/gotk-components.yaml
Enter fullscreen mode Exit fullscreen mode

Commit and push the manifest to the master branch:

git add -A && git commit -m "add flux components" && git push
Enter fullscreen mode Exit fullscreen mode

Apply the manifests on your cluster:

kubectl apply -f ./clusters/my-cb-cluster/flux-system/gotk-components.yaml
Enter fullscreen mode Exit fullscreen mode

Verify that the controllers have started:

flux check
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Create a Kustomization object on your cluster:

flux create kustomization flux-system \
  --source=flux-system \
  --path="./clusters/my-cb-cluster" \
  --prune=true \
  --interval=10m
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Wait for Flux to get your previous commit with:

flux get kustomizations --watch
Enter fullscreen mode Exit fullscreen mode

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)