title | menu_order |
---|---|
Installing Weave Flux Manually |
10 |
This short guide shows a self-contained example of Flux and just takes a couple of minutes to get set up. By the end you will have Flux running in your cluster and it will be deploying any code changes for you.
Note: If you would like to install Flux using Helm, refer to the Helm section.
You will need to have Kubernetes set up. For a quick local test,
you can use minikube
or kubeadm
. Any other Kubernetes setup
will work as well though.
When using a cluster in the cloud (e.g. GKE), use nodes with at least 2 CPU's.
When using nodes with only 1 CPU (like n1-standard-1
), an upgrade
may be stuck with not enough CPU resources. This issue usually manifests itself
in the form of pods hanging in the PENDING state, which looks something like:
$ kubectl describe pod/helloworld-... | tail -3
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 3m (x37 over 13m) default-scheduler 0/2 nodes are available: 2 Insufficient cpu.
If working on e.g. GKE with RBAC enabled, you will need to add a clusterrolebinding:
kubectl create clusterrolebinding "cluster-admin-$(whoami)" --clusterrole=cluster-admin --user="$(gcloud config get-value core/account)"to avoid an error along the lines of
Error from server (Forbidden): error when creating "deploy/flux-account.yaml": clusterroles.rbac.authorization.k8s.io "flux" is forbidden: attempt to grant extra privileges:
Get Flux:
git clone https://github.com/weaveworks/flux
cd flux
Now you can go ahead and edit Flux's deployment manifest. At the very
least you will have to change the --git-url
parameter to point to
the config repository for the workloads you want Flux to deploy for
you. You are going to need access to this repository.
$EDITOR deploy/flux-deployment.yaml
In our example we are going to use flux-example. If you want to use that too, be sure to create a fork of it on Github and add the git URL to the config file above.
In the next step, deploy Flux to the cluster:
kubectl apply -f deploy
Allow some time for all containers to get up and running. If you're impatient, run the following command and see the pod creation process.
watch kubectl get pods --all-namespaces
At startup Flux generates a SSH key and logs the public key. Find the SSH public key with:
kubectl logs deployment/flux | grep identity.pub | cut -d '"' -f2
Note: If you have downloaded fluxctl already, you can use
fluxctl identity
as well.
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, give it a name, check Allow write access, paste the Flux public key and click Add key.
(Or replace YOURUSER
with your Github ID in this url:
https://github.com/YOURUSER/flux-example/settings/keys/new
and
paste the key there.)
In this example we are using a simple example of a webservice and
change its configuration to use a different message. The easiest
way is to edit your fork of flux-example
and change the msg
argument.
Replace YOURUSER
in
https://github.com/YOURUSER/flux-example/blob/master/helloworld-deploy.yaml
with your Github ID), open the URL in your browser, edit the file,
change the argument value and commit the file.
You can check out the Flux logs with:
kubectl -n default logs deployment/flux -f
The default sync frequency is 5 minutes. This can be tweaked easily. By observing the logs you can see when the change landed in in the cluster.
To access our webservice and check out its welcome message, simply run:
kubectl port-forward deployment/helloworld 8080:80 &
curl localhost:8080
As you can see, the actual steps to set up Flux, get our app deployed, give Flux access to it and see modifications land are very straight-forward and are a quite natural work-flow.
As a next step, you might want to dive deeper into how to control Flux or check out more sophisticated setups.