# Source: https://gist.github.com/4fcd7b28948a502a348e5a8a466b186b | |
############################## | |
# Flux 2 With GitOps Toolkit # | |
############################## | |
# What Is GitOps And Why Do We Want It?: https://youtu.be/HKkhD6nokC8 | |
# Argo CD: Applying GitOps Principles To Manage Production Environment In Kubernetes: https://youtu.be/vpWQeoaiRM4 | |
######### | |
# Setup # | |
######### | |
minikube start | |
minikube addons enable ingress | |
export INGRESS_HOST=$(minikube ip) | |
# Install Flux CLI by following the instructions from https://toolkit.fluxcd.io/guides/installation/#install-the-flux-cli | |
# Replace `[...]` with the GitHub organization or a GitHub user if it is a personal account | |
export GITHUB_ORG=[...] | |
# Replace `[...]` with the GitHub token | |
export GITHUB_TOKEN=[...] | |
# Replace `[...]` with `true` if it is a personal account, or with `false` if it is an GitHub organization | |
export GITHUB_PERSONAL=[...] | |
######################### | |
# Bootstrapping Staging # | |
######################### | |
flux bootstrap github \ | |
--owner $GITHUB_ORG \ | |
--repository flux-staging \ | |
--branch main \ | |
--path apps \ | |
--personal $GITHUB_PERSONAL \ | |
--namespace flux-staging | |
kubectl --namespace flux-staging \ | |
get pods | |
git clone \ | |
https://github.com/$GITHUB_ORG/flux-staging.git | |
cd flux-staging | |
ls -1 apps | |
ls -1 apps/flux-staging | |
kubectl create namespace staging | |
############################### | |
# Deploying The First Release # | |
############################### | |
flux create source git \ | |
devops-toolkit-staging \ | |
--url https://github.com/vfarcic/devops-toolkit \ | |
--namespace flux-staging \ | |
--branch master \ | |
--interval 30s \ | |
--export \ | |
| tee apps/devops-toolkit-source.yaml | |
mkdir values | |
echo "image: | |
tag: 2.9.9 | |
ingress: | |
host: staging.devops-toolkit.$INGRESS_HOST.xip.io" \ | |
| tee values/devops-toolkit.yaml | |
flux create helmrelease \ | |
devops-toolkit-staging \ | |
--source GitRepository/devops-toolkit-staging \ | |
--values values/devops-toolkit.yaml \ | |
--chart "helm" \ | |
--namespace flux-staging \ | |
--target-namespace staging \ | |
--interval 30s \ | |
--export \ | |
| tee apps/devops-toolkit-release.yaml | |
git add . | |
git commit -m "Initial commit" | |
git push | |
watch flux --namespace flux-staging \ | |
get helmreleases | |
kubectl --namespace staging \ | |
get pods | |
########################## | |
# Deploying New Releases # | |
########################## | |
cat apps/devops-toolkit-release.yaml \ | |
| sed -e "s@tag: 2.9.9@tag: 2.9.17@g" \ | |
| tee apps/devops-toolkit-release.yaml | |
git add . | |
git commit -m "Upgrade to 2.9.17" | |
git push | |
watch kubectl --namespace staging \ | |
get pods | |
watch kubectl --namespace staging \ | |
get deployment \ | |
staging-devops-toolkit-staging-devops-toolkit \ | |
--output jsonpath="{.spec.template.spec.containers[0].image}" | |
cd .. | |
############################ | |
# Bootstrapping Production # | |
############################ | |
flux bootstrap github \ | |
--owner $GITHUB_ORG \ | |
--repository flux-production \ | |
--branch main \ | |
--path apps \ | |
--personal $GITHUB_PERSONAL \ | |
--namespace flux-production | |
watch kubectl get ns | |
git clone \ | |
https://github.com/$GITHUB_ORG/flux-production.git | |
cd flux-production | |
kubectl create namespace production | |
########################### | |
# Promoting To Production # | |
########################### | |
flux create source git \ | |
devops-toolkit-production \ | |
--url https://github.com/vfarcic/devops-toolkit \ | |
--namespace flux-production \ | |
--branch master \ | |
--interval 30s \ | |
--export \ | |
| tee apps/devops-toolkit-source.yaml | |
mkdir values | |
echo "image: | |
tag: 2.9.17 | |
ingress: | |
host: devops-toolkit.$INGRESS_HOST.xip.io" \ | |
| tee values/devops-toolkit.yaml | |
flux create helmrelease \ | |
devops-toolkit-production \ | |
--source GitRepository/devops-toolkit-production \ | |
--values values/devops-toolkit.yaml \ | |
--chart "helm" \ | |
--namespace flux-production \ | |
--target-namespace production \ | |
--interval 30s \ | |
--export \ | |
| tee apps/devops-toolkit-release.yaml | |
git add . | |
git commit -m "Initial commit" | |
git push | |
watch flux --namespace flux-production \ | |
get helmreleases | |
kubectl --namespace production \ | |
get pods | |
open http://devops-toolkit.$INGRESS_HOST.xip.io | |
######################### | |
# Destroying Everything # | |
######################### | |
minikube delete | |
cd .. | |
cd flux-staging | |
gh repo view --web | |
# Delete the repo | |
cd .. | |
rm -rf flux-staging | |
cd flux-production | |
gh repo view --web | |
# Delete the repo | |
cd .. | |
rm -rf flux-production |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment