Inside the infrastructure Deployments to Kubernetes
Deployments to Kubernetes
GitOps: the desired state of the cluster is kept in a Git repository, and Argo CD’s controller compares what runs with it and brings the cluster back to it, resource by resource and wave by wave.
My work
I deployed applications to Kubernetes through Argo CD.
How it is built
An example of the mechanism, not the configuration of the real deployments: a generalised layout from the Argo CD documentation, with three sync waves. What I deployed and how its manifests were laid out is not shown.
While wave 0 waits to become healthy
- Argo CD applies the first wave in which a resource is out of sync or unhealthy, and goes on only when it is in sync and healthy.
- While a resource of wave 0 is Progressing, not healthy yet, waves 1 and 2 are not applied.
- If it never becomes healthy, the application may never become healthy either. 5
6
Components
Press a component to read what it does.
Git repository manifests
Where the desired state of the applications is written: their manifests, at a revision.
Repo server renders
An internal service of Argo CD: it keeps a local cache of the repository and generates the Kubernetes manifests of an application from it.
API server UI, webhooks
Serves the web UI, the command line and CI, and receives the webhook events of the Git server.
Controller compares
The application controller: a Kubernetes controller that compares the live state of the applications with the desired state and can bring it back; it runs the hooks of a sync.
Wave 0 resources
Resources whose sync-wave annotation is 0, the default. Applied first among the waves of this example.
Wave 1 resources
Resources of the next wave: applied once wave 0 is in sync and healthy.
Wave 2 resources
The last wave of this example: applied once wave 1 is in sync and healthy.
-
Rendering
The repository server keeps a local copy of the Git repository and generates an application’s Kubernetes manifests from it: from its repository, revision, path and settings.
In detail
The repository server is an internal service which maintains a local cache of the Git repository holding the application manifests. It generates and returns the Kubernetes manifests when given the repository URL, the revision (a commit, tag or branch), the application path and the settings of the template, such as parameters or Helm values. 1
Where it breaks A change made by hand in the live cluster is not an input of the generation: what is generated comes from the repository, the revision, the path and the settings of the template.
-
Comparison
The controller keeps comparing what runs with what the repository says. Where they differ, the application is OutOfSync, and the controller can bring it back.
In detail
The application controller is a Kubernetes controller which continuously monitors running applications and compares their live state against the desired target state, as specified in the repository. It detects an OutOfSync state and can take corrective action, and it is responsible for invoking the user-defined hooks of the lifecycle: PreSync, Sync, PostSync. 1
2 Where it breaks By default a change made in the live cluster does not by itself trigger an automated sync; self-heal makes it one.
-
Refresh
Argo CD looks at the repository again every 120 seconds plus up to 60 seconds of jitter: three minutes at most. A webhook from the Git server removes that wait.
In detail
The interval of automatic sync is set by timeout.reconciliation in the argocd-cm ConfigMap: 120 seconds by default, with 60 seconds of jitter added, for a maximum of three minutes. The jitter spreads the refreshes of many applications; timeout.reconciliation set to 0 turns the timed reconciliation off. The API server is a listener and forwarder of the Git server’s webhook events, which take the place of the wait. 1
3 4 Where it breaks Without a webhook, a commit can wait up to the whole interval before Argo CD sees it.
-
Sync
A sync applies the manifests in phases: PreSync hooks first, then the resources with the Sync hooks, then PostSync hooks once everything is healthy. A failed hook stops the sync.
My part I deployed applications to Kubernetes through Argo CD.
In detail
PreSync hooks run before the manifests are applied; Sync hooks run after all PreSync hooks have completed successfully, at the same time as the manifests are applied; PostSync hooks run after all Sync hooks have completed successfully, the application has been applied and all resources are healthy. If a PreSync hook fails, the whole sync stops and is marked as failed; hooks marked SyncFail run when a sync operation fails. In a selective sync, of some resources only, hooks are not run. 2
5 7 Where it breaks Applied is not yet healthy: the hooks after the sync run only once every resource is healthy.
-
Waves
Within a sync, resources go in waves, from the lowest number to the highest: the next wave is applied only when the earlier ones are in sync and healthy.
In detail
A wave is set by the argocd.argoproj.io/sync-wave annotation; resources are in wave 0 by default, and a wave can be negative. Argo CD orders the resources by phase, wave, kind and name, finds the first wave in which any resource is out of sync or unhealthy, applies that wave, and repeats until all phases and waves are in sync and healthy. Between two waves it waits, 2 seconds by default (ARGOCD_SYNC_WAVE_DELAY), so as not to judge health against an object just applied. 5
Where it breaks A resource that is unhealthy in an early wave holds back every later one: the application may never become healthy.
-
Health
Each resource has a health: Healthy, Progressing (not healthy yet, but making progress), Degraded, or Suspended, waiting for something outside to resume.
In detail
Healthy: the resource is healthy. Progressing: it is not healthy yet but is still making progress and might be healthy soon. Degraded: the resource is degraded. Suspended: it is suspended and waiting for some external event to resume, such as a suspended CronJob or a paused Deployment. A pod that is meant to run to completion, such as one a Job creates, is Progressing while it runs and becomes Healthy only once it has succeeded. 6
Where it breaks A long-running pod created with a restart policy of Never or OnFailure keeps the application Progressing for ever, unless its annotation argocd.argoproj.io/ignore-restart-policy is set to "true"; even then, a pod that fails is Degraded, and on a pod used as a resource hook the annotation has no effect.
-
Automated sync
With automated sync on, Argo CD syncs when Git changes. It deletes nothing unless pruning is on, and a change made in the cluster is not by itself a reason to sync, unless self-heal is on.
In detail
By default, changes made to the live cluster do not trigger an automated sync; with self-heal on, a sync is attempted again after the self-heal timeout, 5 seconds by default. Automated sync does not delete a resource no longer defined in Git unless prune is on. It does not start a new sync for the same commit and parameters as one that failed; retries within an operation are a setting of their own. 2
Where it breaks An application with automated sync on cannot be rolled back.
Next case
MySQL access and ProxySQL rules
Configuration management: a Salt master keeps the desired state of the servers, states and the pillar data they use, and its minions apply it on the hosts. Here the state is who may do what in MySQL, and which hostgroup ProxySQL sends a query to.