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 |
---|---|
Owner* |
user%USER_ID% |
Repository Name* |
gitops-cn-project |
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/.git/
[master (root-commit) b066fd2] Initial Inventory GitOps
6 files changed, 251 insertions(+)
create mode 100644 inventory-coolstore-configmap.yaml
create mode 100644 inventory-coolstore-deployment.yaml
create mode 100644 inventory-coolstore-deploymentconfig.yaml
create mode 100644 inventory-coolstore-route.yaml
create mode 100644 inventory-coolstore-secret.yaml
create mode 100644 inventory-coolstore-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.47 KiB | 2.47 MiB/s, done.
Total 8 (delta 1), reused 0 (delta 0)
remote: . Processing 1 references
remote: Processed 1 references in total
To http://gitea-server.gitea.svc:3000/user%USER_ID%/gitops-cn-project.git
* [new branch] master -> master
Once done, in Git Repository, refresh the page of your 'gitops-cn-project' 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%/gitops-cn-project.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 |
cn-project%USER_ID% |
GENERAL |
Project |
default |
GENERAL |
SYNC POLICY |
Manual |
SOURCE |
Repository URL |
http://gitea-server.gitea.svc:3000/user%USER_ID%/gitops-cn-project.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 Coolstore'
A terminal should be opened with the following output:
Reinitialized existing Git repository in /projects/gitops/.git/
[master 7d5e824] Initial Coolstore GitOps
18 files changed, 612 insertions(+)
[...]
Enumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 16 threads.
Compressing objects: 100% (14/14), done.
Writing objects: 100% (14/14), 3.80 KiB | 3.80 MiB/s, done.
Total 14 (delta 8), reused 0 (delta 0)
remote: . Processing 1 references
remote: Processed 1 references in total
To http://gitea-server.gitea.svc:3000/user%USER_ID%/gitops-cn-project.git
d35eafe..7d5e824 master -> master
Once done, in your Git Repository, refresh the page of your 'gitops-cn-project' repository
. You should
see the project files in the repository.
In Argo CD, the application status is once again in yellow OutOfSync state since the Catalog, Gateway and Web services have 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.