Kubernetes Server Side Apply with Argo CD

Abhishek Veeramalla
2 min readOct 3, 2022

Server-Side Apply is a feature stable as part of k8s v1.22 and is introduced into Argo CD with PR #9711. However, this feature is not yet released and is set to milestone v2.5.

If you would like to try this feature you can either build Argo CD from master or use the below Docker Image(not recommended for production or per-production).


docker.io/abhishekf5/argocd@sha256:ac5d7b74e71eb6453944d564e1b5f056a4f3d8c4447141cde0e9f540a7115afc

TL;DR

Enable Server-Side Apply and turn off Schema Validation(not required in the below example, but this is similar to kubectl apply — server-side — validate=false.
This is required when you try to update anything in .spec).

Example configuration for Server-Side Apply

Argo CD Server-Side Apply

By default, ArgoCD executes kubectl apply operation to apply the configuration stored in Git. This is a client side operation that relies on kubectl.kubernetes.io/last-applied-configuration annotation to store the previous resource state.

  • In some cases the resource is too big to fit in 262144 bytes allowed annotation size. In this case server-side apply can be used to avoid this issue as the annotation is not used in this case.
  • Apart from this Server-Side Apply can also be used to patch an existing resource that is not managed or deployed by Argo CD.

apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
syncPolicy:
syncOptions:
— ServerSideApply=true

If the ServerSideApply=true sync option is set the ArgoCD will use kubectl apply — server-side command to apply changes.

This can also be configured at individual resource level.

metadata: 
annotations:
argocd.argoproj.io/sync-options: ServerSideApply=true

Let’s try Server-Side Apply with a basic configuration

We will label a simple nginx deployment that is already available on the cluster and not managed by Argo CD. Let’s start with creating the nginx deployment.

1. Create a nginx deployment.

kubectl create deployment nginx — image=nginx

2. Patch the object that only includes the fields and values for which the user has an opinion. We will patch the nginx deployment with label
`foo: bar`.

— Place the below nginx deployment in a git repo.

apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx
namespace: default

3. Create an Argo CD Application that points to the git repo and path as shown below.

Argo CD Application for Server-Side Apply

4. Finally you will see that the new label `foo:bar` is attached to the nginx deployment.

Updated Deployment with Labels updated by Server-Side Apply

--

--