One app on every cluster in an environment

Deploy a cluster add-on once, to an environment that selects its clusters by label, and have it follow clusters as they come and go.

The situation

You run a log agent on every edge cluster, and you have eleven of them, with more to come. A deployment per cluster means eleven deployments to keep in step. Instead make an environment that holds the edge clusters, and one deployment that targets the environment. Wardn renders one snapshot and queues one apply for each cluster the environment holds (Environments and many clusters).

The environment finds its clusters by label. Label a cluster role=edge and it joins; the agent arrives with the next apply.

Repository layout

configmap.yaml
daemonset.yaml

Settings

The manifests

Every object must be namespaced and name no namespace other than the deployment's. A DaemonSet needs no cluster-wide permissions here, so the operator can apply it. If your agent needs a ClusterRole, create that once outside Wardn: the operator refuses cluster-scoped objects (Connect a cluster).

log-agent/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: log-agent
data:
  config.yaml: |
    outputs:
      - url: https://logs.example.com/ingest
log-agent/daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: log-agent
spec:
  selector:
    matchLabels:
      app: log-agent
  template:
    metadata:
      labels:
        app: log-agent
    spec:
      containers:
        - name: agent
          image: ghcr.io/example/log-agent:2.3.1
          volumeMounts:
            - name: config
              mountPath: /etc/log-agent
            - name: varlog
              mountPath: /var/log
              readOnly: true
      volumes:
        - name: config
          configMap:
            name: log-agent
        - name: varlog
          hostPath:
            path: /var/log

The environment

Create an environment named edge with a selector for the label, and give it a class that is not production, so the production branch rule does not apply to an add-on.

Open Environments › New environment: Name edge, Class edge, Create environment. Open its Settings tab, under Clusters choose Add label and enter role and edge, then Save. Wardn runs the label rule over every cluster that is in no environment.

To label a cluster, open the environment's Clusters tab and use the New label field on a cluster's row, or set Labels when you connect the cluster (Connect a cluster). A cluster that carries every label of the selector and is in no environment joins on its own.

The rule places only a cluster that has no environment, and it never moves one out of another. A cluster that already belongs to an environment must be assigned to edge by hand (Put clusters in an environment).

The namespace on each cluster

Wardn applies as the service account wardn-deployer in the deployment's namespace, on every cluster. Make it on each, now and for every cluster you add later:

for ctx in edge-eu-1 edge-us-1; do
  kubectl --context "$ctx" create namespace logging
  kubectl --context "$ctx" -n logging create serviceaccount wardn-deployer
  kubectl --context "$ctx" -n logging create rolebinding wardn-deployer \
    --clusterrole=admin --serviceaccount=logging:wardn-deployer
done

A cluster without it fails its apply with the cluster's own error, and the deployment's state shows that cluster as failed.

The app and the deployment

Open /apps/new: A new repository, Git repository, the URL, Path log-agent, Name log-agent, Rendered with Plain manifests. On the app's page choose New deployment: Name log-agent, Runs on Environment, Environment edge, Namespace logging, Snapshots arrive Track a branch, Branch main.

Check that it worked

api "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/state" \
  | jq '{sync, health, clusters: [.clusters[] | {clusterName, sync, health}]}'

The deployment's own sync and health are the roll-up: applied when every cluster has applied, health the worst of theirs. clusters gives each cluster's own state. In the web app, the deployment shows one status, and the environment's Deployments tab lists it.

Now add a twelfth cluster: connect it, create the namespace and account as above, and label it role=edge. It joins edge, and the agent arrives with the next apply. To apply the current snapshot there at once, choose Sync now on the app's page within the deployment, or:

api -X POST "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/sync"

sync needs deployment:sync and answers 409 while an apply is running.

An apply queued for a cluster that is offline waits for it for a limited time (Failures and offline clusters). A drift revert is queued only for the clusters that reported drift, and a restore for every cluster.

Next

Related: Deployment settings, Drift, Restore and rollback.

On this page