GitOps Workflow with Argo CD
20 MINUTE EXERCISE
In this lab you will learn about deploying and managing Kubernetes resources using a GitOps tool.
Export OpenShift Resources
First, you need to export the project resources from OpenShift.
In your Workspace, click on 'Terminal' → 'Run Task…' → 'GitOps - Export Coolstore'
A terminal should be opened with the following output:
--- Export Kubernetes resources for GitOps from my-project%USER_ID% to cn-project%USER_ID% ---
Exporting resources for inventory-coolstore...
Exporting resources for catalog-coolstore...
Exporting resources for gateway-coolstore...
Exporting resources for web-coolstore...
--- Kubernetes resources has been exported! ---
This operation exports the project resources (deploymentconfig, route, secret, service) and cleans them up. As a result, you should have all resources in YAML files under the /projects/workshop/labs/gitops folder.
Create a Git Repository for Your Configuration
The next step is to store all Kubernetes/OpenShift resources in a source code repository.
In your Git Repository, create a new Repository
as follows:
Parameter | Value |
---|---|
Repository Name* |
inventory-gitops |
Push the Configuration of Inventory Service into the Git Repository
Now that you have a Git repository for the configuration, you should push the exported Inventory configuration into it.
In your Workspace, click on 'Terminal' → 'Run Task…' → 'GitOps - Commit Inventory'
A terminal should be opened with the following output:
Initialized empty Git repository in /projects/workshop/labs/gitops/inventory-coolstore/.git/
[master (root-commit) 918f5d6] Initial Inventory GitOps
6 files changed, 251 insertions(+)
create mode 100644 configmap.yaml
create mode 100644 deployment.yaml
create mode 100644 deploymentconfig.yaml
create mode 100644 route.yaml
create mode 100644 secret.yaml
create mode 100644 service.yaml
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 16 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 2.42 KiB | 2.42 MiB/s, done.
Total 8 (delta 1), reused 0 (delta 0), pack-reused 0
remote: . Processing 1 references
remote: Processed 1 references in total
To http://gitea-server.gitea.svc:3000/user1/inventory-gitops.git
* [new branch] master -> master
Once done, in Git Repository, refresh the page of your 'inventory-gitops' repository
. You should
see the files in the repository.
Add your Newly Created GitOps Repository
In Argo CD, Select the 'Configuration menu' then click on 'Repositories'
Click on 'CONNECT REPO USING HTTPS'
and enter the following:
Parameter | Value |
---|---|
Type |
git |
Repository URL |
http://gitea-server.gitea.svc:3000/user%USER_ID%/inventory-gitops.git |
Finally, Click on 'CONNECT'
.
Your GitOps repository is now added to Argo CD.
Create a GitOps Application
In Argo CD, Select the 'Application menu' then click on '+ New App'
and enter the following details:
Section | Parameter | Value |
---|---|---|
GENERAL |
Application Name |
inventory%USER_ID% |
GENERAL |
Project |
cn-project%USER_ID% |
GENERAL |
SYNC POLICY |
Manual |
SOURCE |
Repository URL |
http://gitea-server.gitea.svc:3000/user%USER_ID%/inventory-gitops.git |
SOURCE |
Revision |
HEAD |
SOURCE |
Path |
. (dot) |
DESTINATION |
Cluster |
|
DESTINATION |
Namespace |
cn-project%USER_ID% |
ALL OTHER SECTIONS |
* |
leave them empty/by default |
Finally, Click on 'CREATE'
.
Your Coolstore Application has been created in Argo CD.
The application status is initially in yellow OutOfSync state since the application has yet to be deployed into cn-project%USER_ID% OpenShift project, and no Kubernetes resources have been created.
Deploy a Resource on OpenShift
In Argo CD, click on the 3 dots menu at the left of the 'CM Inventory' resource then select 'Sync'
Then click on the 'Synchonize' button
. Now the ConfigMap of Inventory has been deployed and synchronized
with your environment.
In the OpenShift Web Console, from the Developer view,
select your 'cn-project%USER_ID%'
and click on 'Config Maps'
. You should find the resource you just
deployed via Argo CD.
Recover from a Configuration Drift
A Configuration Drift is a term used whenever someone makes ad hoc changes in a (production) environment which are not recorded or tracked.
In the OpenShift Web Console, from the Developer view,
select your 'cn-project%USER_ID%'
and click on 'Config Maps' → 'CM inventory' → 'YAML'
.
Add the following line in your configuration then click on 'Save'
simple.adhoc.change=This is a configuration drift
In Argo CD, the 'CM Inventory' resource is no longer synchronized.
Click on it then select 'Diff' tab and check 'Compact diff'
.
Argo CD detects automatically your modification which is not compliant with the desired state described in Git - the source of truth. Indeed, from now, when you want to change the configuration, you will have to update the Git Repository first to record and track your changes to avoid configuration drifts.
You can leave the configuration drift as it is. You will fix it in the next lab.
Push the Coolstore Configuration to the Git Repository
To prepare the next lab, you need to push the remaining coolstore application configuration to the Git repository.
In your Workspace, click on 'Terminal' → 'Run Task…' → 'GitOps - Commit & Configure Coolstore'
Once done, in your Git Repository, you should see the 3 new '*-gitops' repositories.
In Argo CD, you should see the 4 Applications in the OutOfSync state since no service has not yet been deployed into cn-project%USER_ID% OpenShift project.
You are going to fix it in the next lab.
Well done! You are ready for the next lab.