DEV Community

Puneet Khandelwal
Puneet Khandelwal

Posted on

Zero-Downtime Deployment with GitOps and Weave Flux

We've all been there. You push a hotfix, but it breaks the entire stack. Maybe your fix requires swapping out a core service or demands an hour of downtime. Nobody wants to explain that to their boss at 3 AM. Zero-downtime deployment is the holy grail. You can actually hit that target using GitOps and Weave Flux.

GitOps treats your infrastructure as code. You treat your cluster config exactly like your Node.js source code. You get version control, automated testing, and a clear audit trail for every change. Weave Flux bridges the gap between your Git repo and Kubernetes.

Let's look at a concrete example. Imagine a Node.js service talking to a PostgreSQL database. You need to bump the Node library version without dropping a single connection.

First, create a Git repo. This is your source of truth. Flux watches this repo and forces the cluster to match whatever you define there.

Start by defining your state in a values.yaml file.

apiVersion: v1
kind: Secret
metadata:
  name: db-password
type: Opaque
data:
  password: <your_password_here>
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-service
spec:
  replicas: 3
  selector:
    matchLabels:
      app: node-service
  template:
    metadata:
      labels:
        app: node-service
    spec:
      containers:
      - name: node-service
        image: <your_image_here>
        ports:
        - containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: node-service
spec:
  selector:
    app: node-service
  ports:
  - name: http
    port: 3000
    targetPort: 3000
  type: LoadBalancer
Enter fullscreen mode Exit fullscreen mode

This snippet handles your DB credentials, the deployment, and the LoadBalancer service. Next, build your gitops.yaml to wire up your GitHub repo and cluster.

gitops:
  github:
    token: <your_token_here>
    repository: <your_repo_here>
  flux:
    repository: <your_repo_here>
  kubernetes:
    cluster: <your_cluster_here>
Enter fullscreen mode Exit fullscreen mode

You need to tell Flux how to behave with a flux.yaml file (field notes here).

flux:
  source:
    type: github
    repo: <your_repo_here>
  sync:
    automatic:
      prune: true
Enter fullscreen mode Exit fullscreen mode

Finally, set your sync interval in sync.yaml.

sync:
  interval: 5m
Enter fullscreen mode Exit fullscreen mode

Commit these files. Push them to GitHub. Flux picks up the changes and pushes them to Kubernetes. The first run sets everything up. Future runs just patch your existing resources. Your cluster state stays locked to your repo.

Verify the rollout using kubectl get pods or check your dashboard. I prefer kubectl because it’s faster. If you need to debug the sync process, use the flx CLI. flx get pulls the current config, while flx logs helps when things go sideways.

Flux makes infrastructure updates boring. That’s a win in my book. Reliable, scalable, and predictable deployments mean I can actually sleep through the night.

I’ll cover more advanced topics like handling production gotchas in a follow-up. Drop a comment below if you’ve been running Flux in production—I want to hear about the headaches you've solved.

Top comments (0)