Workshop Production - Pushing to Production

Now, it’s time to push our application to production. We’ll use one last Pipeline, promote-to-prod, to tag our image, push it to the vote-app-prod-%USERID% environment, then update the repository with this new image digest. Then, we’ll use Argo CD to create a new production application with self-healing enabled. Finally, we’ll use Git to modify the application, scaling up the deployment replicas and viewing this high availability in real-time from the OpenShift Web Console.

Viewing the promote-to-prod pipeline

Firstly, ensure that you’re currently using the vote-app-ci-%USERID% project. This is where our pipeline manifests have been created and where we’ll run the Pipeline from.

switch project

Within the Pipelines dashboard, we can select the promote-to-prod pipeline to see the details of the Pipeline.

pipeline prod details

Here, you can review the pipeline steps and see what each step is doing. You can also see the pipeline resources that are being used. In addition, you can see the pipeline parameters that are being used. These parameters are used to pass in the name of the image that will be built and the name of the image that will be pushed to the registry. For reference, here are the pipeline steps:

  • tag-to-prod: This step tags the image from the vote-app-dev-%USERID% project and pushes it to the vote-app-prod-%USERID% project.

  • image-tag-to-digest: This step tags the image with the digest of the image that was pushed to the vote-app-prod-%USERID% project.

  • git-update-deployment: This step updates the vote-app-gitops repository with the new image digest.

Running the promote-to-prod pipeline

Now, let’s go ahead and start the Pipeline. Click on the top-right Actions and then the Start button to start the Pipeline. The steps are the same as the previous pipelines so we won’t go through them again.

pipeline prod ui start

You will be prompted to enter the values for the pipeline parameters. However, the default values are already set for you. At the bottom of the menu, we can specify an Empty Directory for the app-source parameter. This is because we’re not building the application from the source; we’re using the image that was built in the dev project. Click on the Start button to start the Pipeline.

pipeline prod ui start 2

Now that the promote-to-prod PipelineRun has been started, let’s go ahead and check the status of the Pipeline.

pipeline prod ui status

Once the Pipeline has been completed, you’ll notice that the vote-app-gitops repo has been updated with a new hash of an image. This is the image that was built in the dev project, pushed to the prod project, and referenced in the environments/prod/kustomization.yaml file that can be found here.

pipeline prod ui gitops

Deploying the application to production using Argo CD

Let’s head to the Argo CD dashboard, and click on the + New App button to begin creating our production application.

argocd new app

Fill in the following information, many of which may auto-fill when selected:

  • Application Name: vote-app-prod-%USERID%

  • Project: default

  • Sync Policy: Automatic

  • Self-Healing: Enabled

  • Auto-create Namespace: Enabled

  • Repository URL:

http://gitea.gitea.svc:3000/%USERID%/vote-app-gitops
argocd new app 2
argocd new app 3

When finished, click the CREATE button in the top left-hand corner to create the application. You will be taken to the application details page. Here, you can see the application’s health, sync status, and associated resources. Currently, the application is syncing, so the status is OutOfSync. Once the application is synced, the status will change to a green Synced.

argocd new app 5

Reviewing SyncWaves in Argo CD

Argo CD has a feature called Syncwaves, which allows you to deploy applications in a staggered fashion. This is useful when you have multiple applications that are dependent on each other and you want to deploy them in a specific order. For example, you may have a database application you want to deploy first, then your application depends on the database. SyncWaves can deploy the database application first, then the application that depends on the database.

app diagram

In our case, we see SyncWaves in action, as we need the vote-api to be deployed before vote-ui. Let’s visit the vote-app-gitops production kustomization.yaml file here.

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
  - ../../k8s/
patchesJson6902: (1)
- patch: |-
    - op: add
      path: /metadata/annotations
      value:
        argocd.argoproj.io/sync-wave: "0" (2)
  target: (3)
    group: apps
    kind: Deployment
    name: vote-api
    version: v1
- patch: |-
    - op: add
      path: /metadata/annotations
      value:
        argocd.argoproj.io/sync-wave: "1"
  target:
    kind: Service
    name: vote-api
    version: v1
- patch: |-
    - op: add
      path: /metadata/annotations
      value:
        argocd.argoproj.io/sync-wave: "2"
  target:
    group: apps
    kind: Deployment
    name: vote-ui
    version: v1
- patch: |-
    - op: add
      path: /metadata/annotations
      value:
        argocd.argoproj.io/sync-wave: "3"
  target:
    kind: Service
    name: vote-ui
    version: v1
- patch: |-
    - op: add
      path: /metadata/annotations
      value:
        argocd.argoproj.io/sync-wave: "4"
  target:
    kind: Route
    name: vote-ui
    version: v1
1 Here, we are using Kustomize to add SyncWaves as annotations to the Kubernetes manifests for production
2 The SyncWaves cardinality defines the order of deployment; in this case, we want to deploy first the backend and then the frontend
3 With Kustomize, we can define which manifest to match for the patch: Deployments, Services, and Routes.

With our configuration currently, SyncWaves allow for a controlled rollout of resources by setting a sequence in which they should be deployed. In this case, we have multiple resources, vote-api and vote-ui. The vote-api resources have syncwaves of 0 and 1, whereas the vote-ui resources have a syncwave of 2, 3, and 4. This means that the vote-api resource will be deployed first, then the vote-ui resource will be deployed second.

Argo CD App Details

Viewing the application and detecting drift

Now that the application has been deployed to production let’s go ahead and view the application in the OpenShift console. Click on the Developer perspective, then select the Topology view. Ensure you’re in the vote-app-prod-%USERID% project, and you should see the application deployed.

app prod topology

Click on the vote-ui deployment, and click Details to see the deployment details. Here, you see how Argo CD will auto-detect drift in the application. Let’s go ahead and change the number of replicas to 2 and see how Argo CD detects the drift and auto-heals.

app prod topology 2

Almost immediately after scaling up the replicas for the vote-ui deployment, Argo CD notices this drift and auto-corrects us back to 1 replicas. Pretty neat!

Using Git to modify the application

Now, let’s go ahead and make a change to the application. We’ll change the number of replicas to 2 and see how Argo CD detects the drift and auto-heals. To do this, let’s go ahead and modify the environments/prod/kustomization.yaml file in the vote-app-gitops repository here. Now, within the Code tab, click on the Edit button to edit within the web page.

gitops prod kustomization

Change the number of replicas on line 4 to 2, then navigate to the Commit changes section at the bottom of the page. Here, we can select Create a new branch for this commit and start a pull request. We will create a new branch, %USERID%-feature-ha and start a pull request to merge the changes into the main branch. This can be helpful if we want to easily roll back changes to our cluster using GitOps. Click on the Propose file change button to create the pull request.

gitops prod kustomization 2

You will be taken to the New Pull Request page. Here, you can see the changes that were made to the file, just changing the replicas of the vote-ui deployment. Click on the New Pull Request button to create the pull request.

gitops prod kustomization 3

Here, you can see the pull request details; to save time, we can skip adding details to this PR. Select the Create Pull Request button to create the pull request.

gitops prod kustomization 4

With the new pull request created, let’s go ahead and merge the pull request into the main branch, where Argo CD is currently tracking our repository. Click the Create merge commit button to merge the pull request.

gitops prod kustomization 5

Viewing the application and detecting drift

Now, let’s go ahead and check the application status in the OpenShift Web Console. Select the Developer perspective, then click on the Topology view. Ensure you’re in the vote-app-prod-%USERID% application, and you should see the vote-ui deployed, now with 2 replicas.

app prod topology 3

Click on the vote-ui deployment, and click Details to see the deployment details. Here, you see how Argo CD will auto-detect drift in the application. Let’s go ahead and change the number of replicas to 1 and see how Argo CD detects the drift and auto-heals.

app prod topology 4

Automatically, the application will sync, and we cannot keep the vote-ui pod replicas at 1. Argo CD uses the manifests in the vote-app-gitops repository and Git as the single source of truth, detecting these application drifts and keeping our resource at 2 replicas. We can also see this in Argo CD, where auto sync is enabled.

argocd new app 6

Conclusion

In this section, we learned how to use OpenShift GitOps to deploy an application from a development to a production environment and how to use Argo CD to detect drift in the application and ensure high availability.