Updating an application
Now we can use Argo CD and Kustomize to deploy patches to our application manifests using GitOps
For example, lets increase the number of replicas for ui deployment to 3
- Kustomize Patch
 - Deployment/ui
 - Diff
 
/workspace/modules/automation/gitops/argocd/update-application/deployment-patch.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ui
spec:
  replicas: 3
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/created-by: eks-workshop
    app.kubernetes.io/type: app
  name: ui
  namespace: ui
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/component: service
      app.kubernetes.io/instance: ui
      app.kubernetes.io/name: ui
  template:
    metadata:
      annotations:
        prometheus.io/path: /actuator/prometheus
        prometheus.io/port: "8080"
        prometheus.io/scrape: "true"
      labels:
        app.kubernetes.io/component: service
        app.kubernetes.io/created-by: eks-workshop
        app.kubernetes.io/instance: ui
        app.kubernetes.io/name: ui
    spec:
      containers:
        - env:
            - name: JAVA_OPTS
              value: -XX:MaxRAMPercentage=75.0 -Djava.security.egd=file:/dev/urandom
          envFrom:
            - configMapRef:
                name: ui
          image: public.ecr.aws/aws-containers/retail-store-sample-ui:latest
          imagePullPolicy: IfNotPresent
          livenessProbe:
            httpGet:
              path: /actuator/health/liveness
              port: 8080
            initialDelaySeconds: 45
            periodSeconds: 20
          name: ui
          ports:
            - containerPort: 8080
              name: http
              protocol: TCP
          resources:
            limits:
              memory: 1.5Gi
            requests:
              cpu: 250m
              memory: 1.5Gi
          securityContext:
            capabilities:
              add:
                - NET_BIND_SERVICE
              drop:
                - ALL
            readOnlyRootFilesystem: true
            runAsNonRoot: true
            runAsUser: 1000
          volumeMounts:
            - mountPath: /tmp
              name: tmp-volume
      securityContext:
        fsGroup: 1000
      serviceAccountName: ui
      volumes:
        - emptyDir:
            medium: Memory
          name: tmp-volume
     app.kubernetes.io/type: app
   name: ui
   namespace: ui
 spec:
-  replicas: 1
+  replicas: 3
   selector:
     matchLabels:
       app.kubernetes.io/component: service
       app.kubernetes.io/instance: ui
Copy patch file to the Git repository directory:
~$cp /workspace/modules/automation/gitops/argocd/update-application/deployment-patch.yaml ~/environment/argocd/apps/deployment-patch.yaml
You can review planned changes in the file apps/deployment-patch.yaml
To apply the patch you can edit the file apps/kustomization.yaml like in the example below:
/workspace/modules/automation/gitops/argocd/update-application/kustomization.yaml.example
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
- ui
patches:
- deployment-patch.yaml
Copy edited file kustomization.yaml to the Git repository directory:
~$cp /workspace/modules/automation/gitops/argocd/update-application/kustomization.yaml.example ~/environment/argocd/apps/kustomization.yaml
Push changes to the Git repository
~$git -C ~/environment/argocd add .
~$git -C ~/environment/argocd commit -am "Update UI service replicas"
~$git -C ~/environment/argocd push
Go to Argo CD UI, wait about 5s or hit Refresh/Sync and you should now have all the changes to the UI services deployed once more.
We should have now 3 pods in ui deployment

To verify, run the following commands:
~$kubectl get deployment -n ui ui
NAME READY UP-TO-DATE AVAILABLE AGE
ui 3/3 3 3 3m33s
~$kubectl get pod -n ui
NAME READY STATUS RESTARTS AGE
ui-6d5bb7b95-hzmgp 1/1 Running 0 61s
ui-6d5bb7b95-j28ww 1/1 Running 0 61s
ui-6d5bb7b95-rjfxd 1/1 Running 0 3m34s