layout | title | date | categories | tags | image | ||||
---|---|---|---|---|---|---|---|---|---|
post |
The FASTEST way to deploy apps to Kubernetes - GitOps with FLUX |
2022-05-13 08:00:00 -0500 |
kubernetes |
flux devops gitops kubernetes |
|
I think I found the perfect GitOps and DevOps toolkit with FluxCD and Kubernetes.Flux is an open source GitOps solution that helps your deploy app and infrastructure with automation.It can monitor git repositories, source control, image container repositories, helm repositories, and more.It can install apps using Kustomize, Helm, Kubernetes manifests so it's designed to fit into your existing workflow.It can even push alerts to your chat system letting you know when deployments happen.In this tutorial we'll cover all of this and more.
Be sure to ⭐ the Flux GitHub repo
{% include embed/youtube.html id='PFLimPh5-wo' %}
If you're looking to install your own Kubernetes cluster, be sure to check out this video that creates a cluster with Ansible
If you're looking for the repo I created this in video, you can find it here /demos/flux-demo
curl -s https://fluxcd.io/install.sh | sudo bash
You'll need to grab a personal access token from here
flux bootstrap github \
--components-extra=image-reflector-controller,image-automation-controller \
--owner=YourGitHUbUserName \
--repository=flux \
--branch=main \
--path=clusters/home \
--personal \
--token-auth
Check flux pods
kubectl get pods -n flux-system
See reference repo for files, located in /demos/flux-demo
See reference repo for files, /demos/flux-demo
See reference repo for files, /demos/flux-demo
First create a workload (see redis deployment file)
Deploy the redis workload (deployment.yml
)
git add -A && \
git commit -m "add redis deployment" && \
git push origin main
Create ImageRepository
in the cluster, namespace, and chart that correspond.
flux create image repository podinfo \
--image=redis \
--interval=1m \
--export > ./clusters/home/default/redis/redis-registry.yaml
Create ImagePolicy
in the cluster, namespace, and chart that correspond.
flux create image policy podinfo \
--image-ref=podinfo \
--select-semver=5.0.x \
--export > ./clusters/home/default/redis/redis-policy.yaml
Then deploy the ImageRepository
and ImagePolicy
git add -A && \
git commit -m "add redis image scan" && \
git push origin main
tell flux to apply changes
flux reconcile kustomization flux-system --with-source
Now edit your deployment.yml
and add a comment
spec:
containers:
- name: redis
image: redis:6.0.0 # {"$imagepolicy": "flux-system:redis"}
Create ImageUpdateAutomation
flux create image update flux-system \
--git-repo-ref=flux-system \
--git-repo-path="./clusters/home" \
--checkout-branch=main \
--push-branch=main \
--author-name=fluxcdbot \
--author-email=fluxcdbot@users.noreply.github.com \
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}" \
--export > ./clusters/home/flux-system-automation.yaml
Commit and deploy
git add -A && \
git commit -m "add image updates automation" && \
git push origin main
tell flux to apply changes
flux reconcile kustomization flux-system --with-source
Now do a git pull to see that flux has applied the tags
git pull
Your deployment.yml
should be updated and it should be deployed to your cluster!
spec:
containers:
- name: redis
image: redis:6.0.16 # {"$imagepolicy": "flux-system:redis"}
Create a secret
kubectl -n flux-system create secret generic discord-url \
--from-literal=address=https://discord.com/api/webhooks/YOUR/WEBHOOK/URL
Create a notification provider
apiVersion: notification.toolkit.fluxcd.io/v1beta1
kind: Provider
metadata:
name: discord
namespace: flux-system
spec:
type: discord
channel: general
secretRef:
name: discord-url
Define an Alert
apiVersion: notification.toolkit.fluxcd.io/v1beta1
kind: Alert
metadata:
name: on-call-webapp
namespace: flux-system
spec:
providerRef:
name: discord
eventSeverity: info
eventSources:
- kind: GitRepository
name: '*'
- kind: Kustomization
name: '*'
Get alerts
kubectl -n flux-system get alerts
NAME READY STATUS AGE
on-call-webapp True Initialized 1m
If you need to update flux, check out Updating Flux Installation Using the Latest Binary from CLI
🛍️ Check out the new Merch Shop at https://l.technotim.live/shop
⚙️ See all the hardware I recommend at https://l.technotim.live/gear
🚀 Don't forget to check out the 🚀Launchpad repo with all of the quick start source files