Automate Kubernetes with GitOps
Implemeting GitOps within your cloud-native infrastructure could get you up and running after a potential disaster in less than an hour.
Join the DZone community and get the full member experience.Join For Free
at the recent cloud native transformation summit sponsored by sysdig, bryan boreham, weaveworks engineer, gave a talk on "automating kubernetes with gitops."
the term gitops was originally coined by alexis richardson, ceo of weaveworks, and according to bryan, alexis came up with it to capture what the weaveworks engineering team was already doing on a daily basis.
the goal of gitops is to increase the velocity of your team's output. it automates much of the process of kubernetes releases and deployments. put simply, gitops is a way to avoid the use of custom scripts and instead it automates your kubernetes deployments so that you can safely ship code on a daily basis.
gitops embraces these four principles:
- describe your entire system declaratively.
- version-control the desired system state.
- apply changes to the desired state as version-controlled commits.
- use software agents to synchronize and alert on divergence.
what is the cloud-native transformation?
bryan described what it took for companies to scale before the cloud. in the past, scaling your system required you to order new servers. in a traditional datacenter, you would have waited for about a month to get new servers, and now with the cloud, it takes about two minutes to spin up a new one.
but how long does it take teams to deliver a software change?
according to forester, most businesses are releasing on a monthly basis. but only 20% of companies surveyed say they are releasing faster than once a month.
what slows down releases?
there are many reasons why people are slow to release. the diagram below illustrates the average release approval process. it is the approval process, according to bryan, that is the reason why many teams take a very long to release a new feature.
weaveworks recovered from disaster in 45 minutes
at weaveworks, we run a saas called weave cloud . several years ago one of our engineers mistyped something on the command line, and in the process, he accidentally deleted all of our clusters . but because we were using gitops way back then, we were able to bring everything back up in 45 minutes.
how did we do that?
because our entire system is described declaratively in kubernetes, docker, and terraform, our system can be easily version controlled in git. our entire system, including code, configuration, monitoring rules, and their dashboards is all kept under source control with a built-in and full audit trail that git provides.
"with our entire system in git, we have a single source of truth for when things go wrong." — bryan boreham, engineer at weaveworks
and so, when all of our servers went down, we were able to reapply the configuration we had in git and bring up new servers, install the software, and then reapply all of the manifests for kubernetes. all of our pods came up with the last known best state and in 45 minutes, we're up and running again. since every git commit is an audit trail, it can provide a simple way for you to check for the "good state" of your cluster.
with our source of truth in git, we also have an agent running in the cluster that compares the state of the running cluster with what's in git. as an example, a developer can ssh onto the cluster and change something, and if this happens, the cluster will notice the change, and send an alert that the cluster no longer matches with what's in git.
things to keep under version control are your yaml files that describe kubernetes and how your deployment runs in it. superior to keeping your configuration in a database, yamls kept versioned in git come with a built-in audit trail of who did what when.
gitops for configuration
with all of your manifest files in git, you also need something to synchronize these with the production cluster. our open source product flux is the agent that can be used for this type of synchronization.
gitops for continuous deployment
to implement continuous deployment you need to add an image repo, like docker hub, to your build pipeline. in addition, you might need continuous integration where the change makes it all the way from your running system to the image repo. whenever a new image appears in the image repo, the version will be automatically updated in the deployment manifest and then checked back into git. and when that occurs, the source of truth will differ from the running cluster, where an automatic update can occur. in our case, we update to staging before we deploy to production.
weaveworks includes an approval process between staging and production. but we do use the same configuration repo for both environments. you can use any process here, though, but the main idea is that changes to the cluster are driven by a git commit.
Published at DZone with permission of Anita Buehrle, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.