Skip to content

Instantly share code, notes, and snippets.

@dantejauregui
Created January 15, 2024 07:00
Show Gist options
  • Save dantejauregui/0c82b871cd9be3da2d7f3fe94d89c6a1 to your computer and use it in GitHub Desktop.
Save dantejauregui/0c82b871cd9be3da2d7f3fe94d89c6a1 to your computer and use it in GitHub Desktop.
FluxCD & Killerkoda K3S
FluxCD & Killerkoda K3S
*Killercoda install automatically GIT, DOCKER and K3S Kubernetes
Creating SSH Key “gitlabKey1” and storing it in GITLAB User Settings:
ssh-keygen -t ed25519 -C “killercoda1”
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub (EL CODIGO QUE SE GENERA SE COPIA Y SE PEGA EN GITLAB USER SETTINGS “SSH KEYS”)
Installing Flux:
curl -s https://fluxcd.io/install.sh | sudo bash
. <(flux completion bash)
CREATE NEW REPO IN GITLAB with README autocreated, AND AFTER:
git clone (GITLAB REPO SSH URL)
cd (GITLAB REPO FOLDER NAME)
Bootstraping:
EN GITLAB SE CREA UN “PERSONAL ACCESS TOKEN” Y SE EXPORTA:
export GITLAB_TOKEN=glpat-JFZbJJ7RLDeKn6BBuKPj (CREATED TEMPORAL TOKEN IN GITLAB)
***According Flux official page (and we dont have to create 3 previous yaml files manually):
flux bootstrap gitlab \
--token-auth \
--owner=dantejauregui \
--repository=killercoda1 \
--branch=main \
--read-write-key \
--components-extra=image-reflector-controller,image-automation-controller \
--path=flux-clusters/dev-cluster \
--personal --kubeconfig=/etc/rancher/k3s/k3s.yaml
Bringing files into local added by Flux
git pull
verify if all is correct installed:
kubectl get namespaces
kubectl get pods -n flux-system
flux get sources git --kubeconfig=/etc/rancher/k3s/k3s.yaml
flux get kustomizations --kubeconfig=/etc/rancher/k3s/k3s.yaml
Creating some basic Sources and Kustomization Flux files (bb-app-source example):
flux create source git 2-demo-source-git-bb-app \
--url=https://github.com/sid-demo/bb-app-source \
--branch=2-demo \
--interval=10s \
--export > ~/killercoda1/flux-clusters/dev-cluster/2-demo-source-git-bb-app.yml
OR using my OWN APP REPO:
flux create source git 2-demo-source-git-python-app \
--url=https://gitlab.com/dantejauregui/pipeline-a \
--branch=main \
--interval=10s \
--export > ~/killercoda1/flux-clusters/dev-cluster/2-demo-source-git-python-app.yml
OR using SSH to use my OWN APP REPO:
flux create source git 2-demo-source-git-python-app \
--url=ssh://git@gitlab.com/dantejauregui/pipeline-a.git \
--branch=main \
--timeout=10s \
--secret-ref 2-demo-secret-python-app-auth \
--export > ~/killercoda1/flux-clusters/dev-cluster/2-demo-source-git-python-app.yml
*Before the next Flux create command, create a new Namespace “2-demo”:
kubectl create namespace 2-demo
flux create kustomization 2-demo-kustomize-git-bb-app \
--source GitRepository/2-demo-source-git-bb-app \
--prune true \
--interval 10s \
--target-namespace 2-demo \
--path manifests \
--export > ~/killercoda1/flux-clusters/dev-cluster/2-demo-kustomize-git-bb-app.yml
OR using my OWN APP REPO:
flux create kustomization 2-demo-kustomize-git-python-app \
--source GitRepository/2-demo-source-git-python-app \
--prune true \
--interval 10s \
--target-namespace 2-demo \
--path manifests \
--export > ~/killercoda1/flux-clusters/dev-cluster/2-demo-kustomize-git-python-app.yml
*Luego haces Push para q flux empiece el Deployment Automatico:
Uploading Code:
git config --global user.name "Dante"
git config --global user.email "dnte.jauregui@gmail.com"
git add .
git commit -m “adding Flux files"
git push
Finalmente se ve el Service creado en el nuevo namespace 2-demo:
kubectl get all -n 2-demo
There you see in which PORT is deployed, so you can use the APP!
in this case, we will see the “bb-app-source” deployed in PORT 30002, as example!
implementing the IMAGE AUTOMATION CONTROLLER:
1st Scan a Image Repo:
flux create image repository 2-demo-image-repo-python-app \
--image registry.gitlab.com/dantejauregui/pipeline-a/flask-gitlab \
--interval 10s \
--export > ~/killercoda1/flux-clusters/dev-cluster/2-demo-image-repo-python-app.yml
and to see the status of image repository: flux get images all
2nd Flux image Policy, which is going to pickup the latest Tag based on Regex Patterns:
flux create image policy 2-demo-image-policy-python-app \
--image-ref=2-demo-image-repo-python-app \
--select-semver 7.8.x \
--export > ~/killercoda1/flux-clusters/dev-cluster/2-demo-image-policy-python-app.yml
and to see the status of image repository: flux get images all
3rd Flux image update, which will execute the update of the image
flux create image update 2-demo-image-update-python-app \
--git-repo-ref 2-demo-source-git-python-app \
--checkout-branch main \
--author-name fuxcdbot \
--author-email fluxcdbot@users.noreply.gitlab.com \
--git-repo-path ./manifests \
--push-branch main \
--interval 100s \
--export > ~/killercoda1/flux-clusters/dev-cluster/2-demo-image-update-python-app.yml
*to Update the new Image Tag number/version in the other Repository, we need Authorization, so we create a SECRET Deploy Key (will give u the Public Key, while the Private key will be stores as secret inside the Cluster):
flux create secret git 2-demo-secret-python-app-auth \
--url=ssh://git@gitlab.com/dantejauregui/pipeline-a.git \
--ssh-key-algorithm=ecdsa \
--ssh-ecdsa-curve=p521 \
--kubeconfig=/etc/rancher/k3s/k3s.yaml
And the generated Public Key you place it in the GITLAB Repo, go to their specific Settings > RepositorySettings > Deploy Keys sections > Add new key. (And do not forget to enable the option of ALLOW WRITE ACCESS)
DeployKey:
...
git remote set-url origin git@gitlab.com:dantejauregui/pipeline-a.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment