sudo apt update && sudo apt upgrade
sudo apt install qemu-guest-agent -y
sudo apt install nfs-common open-iscsi -y
sudo reboot now
sudo modprobe iscsi_tcp
- Check node are ready
curl -sSfL https://raw.githubusercontent.com/longhorn/longhorn/v1.7.2/scripts/environment_check.sh | bash
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--disable local-storage --disable servicelb --disable=traefik --disable-cloud-controller" sh -
sudo cat /etc/rancher/k3s/k3s.yaml
Let's use K3D because it K3S in docker so everything is easy.
- Install K3D.
wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
- Init K3D small cluster (1 server, 2 nodes) using a config file.
k3d cluster create --config cluster.yml
- Check if everything is OK.
kubectl get nodes
- Deploy nginx manifest
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
- Check what is deployed
kubectl describe pod nginx
kubectl port-forward service/nginx 8080:80
- Install FluxCD CLI
curl -s https://fluxcd.io/install.sh | sudo bash
- Create token here.
export GITHUB_TOKEN=<your-token>
export GITHUB_USER=irish1986
export GITHUB_REPO=gitops
- Create a repo
mkdir ${GITHUB_REPO}
cd ${GITHUB_REPO}
gh repo create ${GITHUB_REPO} --public
git init
touch README
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/irish1986/gitops-demo.git
git push -u origin main
- Bootstrap the repo.
flux bootstrap github \
--owner=irish1986 \
--repository=gitops \
--branch=main \
--path=cluster/demo \
--personal \
--token-auth
-
Deploy nginx manifest via FluxCD. Move manifest under FluxCD directory.
-
Deploy nginx manifest via FluxCD
git add .
git commit -m "something something"
git push origin main
flux get kustomizations --watch
flux reconcile kustomization flux-system --with-source
- Check status
kubectl describe pod nginx
kubectl port-forward service/nginx 8080:80
- Create ImageRepository
flux create image repository nginx \
--image=nginx \
--interval=1m \
--export > ./bootstrap/default/manifest/repo.yaml
- Create ImagePolicy
flux create image policy nginx \
--image-ref=nginx \
--select-semver=1.23.x \
--export > ./bootstrap/default/manifest/policy.yaml
- Deploy repo and policy
git add .
git commit -m "something something"
git push origin main
flux get kustomizations --watch
flux reconcile kustomization flux-system --with-source
- Enable policy on deployment.yaml manifest
spec:
containers:
- name: nginx
image: nginx:1.23.0 # {"$imagepolicy": "flux-system:nginx"}
- Create ImageUpdateAutomation (WARRRRRPPP SPEEEEDDD !!!)
flux create image update flux-system \
--git-repo-ref=flux-system \
--git-repo-path="./bootstrap/default" \
--checkout-branch=main \
--push-branch=main \
--author-name=fluxcdbot \
[email protected] \
--commit-template="" \
--export > ./bootstrap/flux-system-automation.yaml
- Deploy automation
git add .
git commit -m "something something"
git push origin main
flux get kustomizations --watch
flux reconcile kustomization flux-system --with-source
GO TO GITHUB, WAIT FOR A MINUTE.
- Check status
git pull
kubectl describe pod nginx
- Break stuff !
KUBE_EDITOR=nano kubectl edit deployment nginx-deployment
kubectl describe pod nginx
flux get kustomizations --watch
flux reconcile kustomization flux-system --with-source
Delete local cluster
k3d cluster delete k3d-cluster