- Install the Flux CLI
curl -s https://fluxcd.io/install.sh | sudo bash
- Set the following environment variables
$ export GITHUB_USER=<YOUR_USER>
$ export GITHUB_TOKEN=<YOUR_GITHUB_TOKEN>
- Set your user to push data
$ git config --global user.email "<YOUR_EMAIL>"
$ git config --global user.name "<YOUR_NAME>"
- Install flux running the following command:
$ flux bootstrap github \
--kubeconfig /etc/rancher/k3s/k3s.yaml \
--owner=$GITHUB_USER \
--repository=developerweek-demo \
--branch=main \
--path=./clusters/mycluster \
--read-write-key \
--personal
- Clone the new repository
$ git clone https://github.com/$GITHUB_USER/developerweek-demo
$ cd developerweek-demo
- Create the new deployment
$ mkdir -p ./clusters/mycluster/manifests
$ cat << EOF > ./clusters/mycluster/manifests/led-app.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: led-app
name: led-app
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: led-app
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: led-app
spec:
containers:
- image: sergioarmgpl/leds
name: leds
imagePullPolicy: Always
env:
- name: COLOR
value: "OFF"
securityContext:
privileged: true
capabilities:
add: ["SYS_ADMIN"]
volumeMounts:
- mountPath: /dev
name: dev-volume
volumes:
- name: dev-volume
hostPath:
path: /dev
type: Directory
status: {}
EOF
- Commit and push the changes
$ git add -A
$ git commit -m "feat: added led deployment without turning on leds"
$ git push origin main
- Check until the deployment is up
$ kubectl rollout status deploy
$ kubectl rollout status deployment led-app
or
$ watch kubectl get deploy
- To check logs inside Flux when a change happens run
kubectl logs deploy/source-controller -n flux-system -f
- Edit the variable COLOR in the file clusters/mycluster/manifests/led-app.yaml to RED or GREEN, the commit and push the changes, and watch the led blinking in the color you set.
Note: Check the final result of this commands in the link: https://github.com/sergioarmgpl/developerweek-demo