Article directory
-
- 1 Introduction
- 2. Install and verify the GitOps operator
- 3. Access Argo CD via Web UI
- 4. 检查 Argo CD Projects, Applications and Application Sets
- 5. Prepare the coffee shop project
- 6. Deploy the Coffee Shop application
- 7. 部署 Barista Component as Knative Service with Argo CD Application Set
- 8. Change application settings and watch Argo CD Argo CD Repair
- 9. Discover New Logging Data
- Red Hat OpenShift 4.8 environment cluster building
- How does openshift output json logs
- openshfit Vertical Pod Autoscaler practice
- openshift Certified Helm Charts Practice
- openshift creates a serverless application
- openshift gitops practice
- openshift Tekton pipeline practice
1 Introduction
GitOps is a declarative approach to continuous deployment for cloud-native applications. You can use GitOps to create repeatable processes for managing Red Hat® OpenShift® Container Platform clusters and applications across multi-cluster Kubernetes environments. GitOps can process and automate complex deployments quickly, saving time during deployment and release cycles.
In this lab, you will deploy the GitOps operator and use it to deploy Coffee Shop
applications into prod-coffeeshop
namespaces. The Coffee Shop application is stored in a Git repository as a YAML manifest and Kustomize file. You can check this Git repository to learn more about how Kustomize works.
First, deploy Argo CD and access the web interface. You then copy and paste the Argo CD application definition from the front end of the Coffee Shop application into the interface and watch it deploy. You delete the application after you deploy it.
Then, you'll explore the ability to deploy complex sets of applications to multiple clusters, but you'll only deploy to the local cluster. You can use application sets to deploy not only the coffee shop front-end components, but also the barista Knative application, all in one application object.
Finally, you make some manual changes to the application on the cluster and observe how Argo CD returns the application to the desired state described in GitOps repository.
Target:
- Deploy a single application using Argo CD
- Deploy Kubernetes deployments and Knative services using the Argo CD application set
- Experience Argo CD Repair
2. Install and verify the GitOps operator
- Browse to your OpenShift Container Platform web console and
admin
log in as . - Instructions and credentials for this are in the configuration email you receive.
- In the Administrator perspective, select
Operators → Operator Hub
. - To easily find the installer card, type in the
Filter by keyword...
fieldopenshift gitops
and click the card. - Click Install, then Install again, keeping all default values for Update Channel: Stable and Update Approval: Automatic.
3. Access Argo CD via Web UI
Argo CD is not yet automatically integrated with the OpenShift Container Platform certification system.
- To obtain the Argo CD administrator password:
a. Select the project from the Project drop-down list:openshift-gitops
.
b. From the navigation menu, selectWorkloads → Secrets
.
c. Use Search by name… and enteropenshift-gitops-cluster
, then click theopenshift-gitops-cluster
link .
d. Navigate toSecrets → Secret details
and scroll down to the Data section.
e. Find the password field and click ⎘ (copy) to copy the password value to the clipboard. - Now find the link to the Argo CD Web UI:
a. On the navigation menu, selectNetworking → Routes
.
b. Click theopenshift-gitops-server Location
link . - Login to Argo CD Web UI with username admin and password from clipboard
4. 检查 Argo CD Projects, Applications and Application Sets
The Argo CD project is different from the OpenShift project.
Argo CD defines a project as
- Source: Application configuration YAML manifest repository, such as a Git or Helm repository.
- Target: The OpenShift server, namespace, and users of the deployment source.
- SyncPolicy: defines how Argo CD keeps the source and destination in sync
- Tools: projects like Kustomize, scripts, etc. A tool to convert application configuration settings (such as YAML or
Helm) into specific target details. Examples include: hostname, port, secret, and container image registry.
Argo CD defines an application to include the following
- Namespaces
- deploy
- Serve
- route
Argo CD Application Collection Add Application Automation
- Multi-cluster support and cluster multi-tenancy support in Argo CD.
- Applications can be templated from multiple sources, including Git or Argo CD's own defined list of clusters.
5. Prepare the coffee shop project
In this exercise, you will create a new dedicated project for your Coffee Shop application. Argo CD's user interface can be a bit finicky, so follow the instructions carefully. If you miss a step, some plausible defaults may not actually apply. This is a security feature - make sure you are aware that you are "allowing all".
1. From the Argo CD web console, click the gear icon to enter the project management interface:
2. Select PROJECTS → NEW PROJECT.
-
Enter
coffee-shop
as the new project name and clickCREATE
. -
Scroll down to
SOURCE REPOSITORIES
and clickEDIT
. -
Make sure there is an asterisk * in the field and click SAVE.
Asterisk allows applications using this project to use any repository. You have to do this to know that applications in this project can now pull configuration from any repository anywhere. -
Scroll down to Destination and click Edit.
-
Click
ADD DESTINATION
and underNamespace
replace the asterisk*
withprod-coffeeshop.
You don't need to enter the server name because the server you are using is
OpenShift GitOps operator
a local server. You specifically chose theprod-coffeeshop
namespace because you don't want Argo CD to manage the OpenShift Container Platform environment - justprod-coffeeshop
all the applications on it.
-
Click SAVE.
-
Click the stack paper icon to enter the application management interface:
now you have a project that you can associate with the new Argo CD application to guide application management on the OpenShift Container Platform.
6. Deploy the Coffee Shop application
In this exercise, you will deploy the Coffee Shop application into the production namespace. The Coffee Shop application has three components: the database, the Coffee Shop front end and the order management system, and the Barista service that manages each order from preparation ( PREPARING
) to collection status ( ).COLLECTED
The database has been deployed for you.
Start by deploying only the Coffee Shop application front-end components so that you can understand what an Argo CD
"application" is.
Your Argo CD application management interface should show "No Application". The Argo CD application YAML content is provided for you to copy and paste into the Argo CD interface.
- Click
CREATE APPLICATION
and then clickEDIT
AS YAML. - Copy and paste the following manifest:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: coffee-shop
namespace: openshift-gitops
spec:
destination:
server: https://kubernetes.default.svc
namespace: prod-coffeeshop
project: coffee-shop
source:
path: ./coffee-shop-kustomize/coffee-shop/overlays/production
repoURL: http://github.com/redhat-gpte-devopsautomation/ocp48_hands_on_apps.git
targetRevision: HEAD
If there are any issues with this app definition, you can find a working copy here: https://github.com/redhat-gpte-devopsautomation/ocp48_hands_on_apps/blob/main/coffee-shop-argocd/coffee-shop.yaml.
- Click
SAVE
.
Observe that the fields that define the application are now populated. - Click
CREATE
. - In the pop-up window that appears, click
SYNC
→SYNCHRONIZE
. - Click on the app name to see the rollout of the app and see a representation of all app sections
- After successfully deploying the application components, click on the coffee shop application
DELETE
. You can remove it so that two components can be deployed with one object (Application set)
7. 部署 Barista Component as Knative Service with Argo CD Application Set
In this exercise, you will use OpenShift GitOps Argo CD
a new feature: Application Sets
.
Application sets make it easy to deploy multiple applications across multiple clusters with different owners.
In this example, you have a simple deployment of the existing Coffee Shop application components (Coffee - Shop and barista), both on the same server and in the same namespace.
1. Return to the OpenShift Container Platform web console.
The application set doesn't have a user interface yet, so you'll need the OpenShift Container Platform web console to do the job. (Do not close your Argo CD web console.)
2. From the toolbar at the top of your web console, click ocp_web_console_add_icon (add) to import the YAML manifest of your application's Argo CD application set as follows:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: coffee-shop-set
namespace: openshift-gitops
spec:
generators:
- git:
repoURL: https://github.com/redhat-gpte-devopsautomation/ocp48_hands_on_apps.git
revision: HEAD
directories:
- path: coffee-shop-kustomize/*
template:
metadata:
name: '{
{path.basename}}'
spec:
destination:
namespace: prod-coffeeshop
server: 'https://kubernetes.default.svc'
project: coffee-shop
source:
path: '{
{path}}/overlays/production/'
repoURL: >-
https://github.com/redhat-gpte-devopsautomation/ocp48_hands_on_apps.git
targetRevision: HEAD
syncPolicy:
automated:
allowEmpty: false
prune: true
selfHeal: true
retry:
backoff:
duration: 5s
factor: 2
maxDuration: 3m
limit: 5
syncOptions:
- Validate=false
- CreateNamespace=true
- PrunePropagationPolicy=foreground
- PruneLast=true
If there are any issues with this app definition, you can find a working copy here: https://github.com/redhat-gpte-devopsautomation/ocp48_hands_on_apps/blob/main/coffee-shop-argocd/coffee-shop-set. yaml .
3.Click Create
to create your application set.
7.1 Sync Applications
- Change your Argo CD web console and notice that the
barista
application has been added. - On the barista application, click
SYNC
. - If a pop-up menu appears, click
SYNCHRONIZE
. - Repeat the
SYNC → SYNCHRONIZE
steps on the coffee-shop
application.
Expect thecoffee-shop
application to sync.
8. Change application settings and watch Argo CD Argo CD Repair
Argo CD monitors your source and destination for changes. When synced, Argo CD returns the destination to the state defined in the source file, either automatic or approved depending on your Argo CD application configuration. Argo CD is conservative by default, so its sync automation policy is not turned on. But in this lab setting, policy is turned on.
For this exercise, you will manually scale up the production coffee shop application and watch Argo CD shrink it down to a single copy.
- Go back to the OpenShift Container Platform web console.
- From the
Administrator
perspective, selectProject: prod-coffeeshop
. - From the navigation menu, select
Workloads → Deployments
. - Locate the
coffee-shop
deployment, click options_menu_icon(Options), and selectEdit
Pod count. - Click ⊕ (Plus) four times to scale up the deployment to five pods.
- Return to the Argo CD web console.
- From the application management interface, click the
coffee-shop
application card.
You can see the single replica configuration here:
https://github.com/redhat-gpte-devopsautomation/ocp48_hands_on_apps/blob/main/coffee-shop-kustomize/coffee-shop/base/deployment.yaml#L14.
You can click REFRESH
to refresh the Argo CD view of the actual deployed OpenShift Container Platform resources.
9. Discover New Logging Data
You have deployed several new application components into the prod-coffeeshop
namespace. In this exercise, you will learn how the log is changed.
9.1 Add prod-coffeeshop
Namespace to ClusterLogForwarder
- Go to the OpenShift Container Platform web console and select the Administrators perspective.
- On the navigation menu, select
Home → Search
. - From the
Project
: drop-down list, select theopenshift-logging
namespace. - From the
Resources
drop-down list, selectClusterLogForwarder
. - Click the
CLF instance
. - Click the
YAML
tab. - Scroll to line 52, -
dev-coffeeshop
. - Immediately after line 52, insert -prod-coffeshop into this YAML array as a new array element.
Expect it to look like this:
9. Click Save
.
9.2 Verify New Logs
- Go to the Kibana web console.
- Create a new index pattern to capture all of the Coffee Shop projects—both
dev-coffeeshop
andprod-coffeeshop
:
a. On the navigation menu, clickManagement
.
b. ClickCreate index pattern
and add an index pattern named*-coffeeshop-*
.
c. ClickNext
.
d. In the Time Filter field select@timestamp
. - From the navigation menu, click
Discover
. - Select the
*-coffeeshop-*
index pattern you just built, and also theAvailable Fields kubernetes.namespace_name
andstructured.message
.
Expect to see results from both the dev-coffeeshop and prod-coffeeshop namespaces. - Observe that new orders are also being processed by the
Create Order
cron job running in your cluster.
You observe that Argo CD deploys the application separately in your first production coffee shop application. Then you see that Argo CD deploys an ApplicationSet that automatically creates two applications: coffee-shop and barista. Barista happens to be a service provided by Knative. Using Argo CD to deploy Kubernetes deployments or Knative services requires no special activity.
You also saw how to get log results from the prod-coffeshop namespace and can query structured. * field for a more detailed analysis.
In the next lab you will create a simple pipeline for developmen