GitOps with Helm and Weave Flux
Automate Helm releases with Weave Flux.
Prerequisites:
- fork this repository
- install Helm and Tiller
- install Weave Flux
Install Helm
Install Helm CLI:
brew install kubernetes-helm
Create a service account and a cluster role binding for Tiller:
kubectl -n kube-system create sa tiller
kubectl create clusterrolebinding tiller-cluster-rule \
--clusterrole=cluster-admin \
--serviceaccount=kube-system:tiller
Deploy Tiller in kube-system
namespace:
helm init --skip-refresh --upgrade --service-account tiller
Install Weave Flux
Add Weave Flux chart repo:
helm repo add sp https://stefanprodan.github.io/k8s-podinfo
Install Weave Flux and its Helm Operator by specifying your fork URL
(replace stefanprodan
with your GitHub username):
helm install --name cd \
--set helmOperator.create=true \
--set git.url=git@github.com:stefanprodan/weave-flux-helm-demo \
--set git.chartsPath=charts \
--namespace flux \
sp/weave-flux
You can connect Weave Flux to Weave Cloud using your service token:
helm install --name cd \
--set token=YOUR_WEAVE_CLOUD_SERVICE_TOKEN \
--set helmOperator.create=true \
--set git.url=git@github.com:stefanprodan/weave-flux-helm-demo \
--set git.chartsPath=charts \
--namespace flux \
sp/weave-flux
Setup Git sync
At startup Flux generates a SSH key and logs the public key. Find the SSH public key with:
export FLUX_POD=$(kubectl get pods --namespace flux -l "app=weave-flux,release=cd" -o jsonpath="{.items[0].metadata.name}")
kubectl -n flux logs $FLUX_POD | grep identity.pub | cut -d '"' -f2 | sed 's/.\{2\}$//'
In order to sync your cluster state with git you need to copy the public key and create a deploy key with write access on your GitHub repository.
Open GitHub, navigate to your fork, go to Setting > Deploy keys click on Add deploy key, check Allow write access, paste the Flux public key and click Add key.
After a couple of seconds Flux will create the test
namespace and will install a Helm release
for each resource inside the releases
dir.
helm list --namespace test
NAME REVISION UPDATED STATUS CHART NAMESPACE
backend 1 Tue Apr 24 01:28:22 2018 DEPLOYED podinfo-0.1.0 test
cache 1 Tue Apr 24 01:28:23 2018 DEPLOYED memcached-2.0.1 test
database 1 Tue Apr 24 01:28:21 2018 DEPLOYED mongodb-0.4.27 test
frontend 1 Tue Apr 24 01:28:22 2018 DEPLOYED podinfo-0.1.0 test