openshift gitops practice


  1. Red Hat OpenShift 4.8 environment cluster building
  2. How does openshift output json logs
  3. openshfit Vertical Pod Autoscaler practice
  4. openshift Certified Helm Charts Practice
  5. openshift creates a serverless application
  6. openshift gitops practice
  7. 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 Shopapplications into prod-coffeeshopnamespaces. 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:

  1. Deploy a single application using Argo CD
  2. Deploy Kubernetes deployments and Knative services using the Argo CD application set
  3. Experience Argo CD Repair

2. Install and verify the GitOps operator

  1. Browse to your OpenShift Container Platform web console and adminlog in as .
  2. Instructions and credentials for this are in the configuration email you receive.
  3. In the Administrator perspective, select Operators → Operator Hub.
  4. To easily find the installer card, type in the Filter by keyword...field openshift gitopsand click the card.
  5. 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.

  1. To obtain the Argo CD administrator password:
    a. Select the project from the Project drop-down list: openshift-gitops.
    b. From the navigation menu, select Workloads → Secrets.
    c. Use Search by name… and enter openshift-gitops-cluster, then click the openshift-gitops-clusterlink .
    d. Navigate to Secrets → Secret detailsand scroll down to the Data section.
    e. Find the password field and click ⎘ (copy) to copy the password value to the clipboard.
  2. Now find the link to the Argo CD Web UI:
    a. On the navigation menu, select Networking → Routes.
    b. Click the openshift-gitops-server Locationlink .
  3. 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:
insert image description here
2. Select PROJECTS → NEW PROJECT.

  1. Enter coffee-shop as the new project name and click CREATE.

  2. Scroll down to SOURCE REPOSITORIES and click EDIT.

  3. 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.

  4. Scroll down to Destination and click Edit.

  5. Click ADD DESTINATION and under Namespace replace the asterisk * with prod-coffeeshop.

You don't need to enter the server name because the server you are using is OpenShift GitOps operatora local server. You specifically chose the prod-coffeeshopnamespace because you don't want Argo CD to manage the OpenShift Container Platform environment - just prod-coffeeshopall the applications on it.

  1. Click SAVE.

  2. Click the stack paper icon to enter the application management interface:
    insert image description here
    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 click EDIT 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.

  1. Click SAVE.
    Observe that the fields that define the application are now populated.
  2. Click CREATE.
  3. In the pop-up window that appears, click SYNCSYNCHRONIZE.
  4. Click on the app name to see the rollout of the app and see a representation of all app sections
    insert image description here
  5. 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 CDa 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

  1. Change your Argo CD web console and notice that the baristaapplication has been added.
  2. On the barista application, click SYNC.
  3. If a pop-up menu appears, click SYNCHRONIZE.
  4. Repeat the SYNC → SYNCHRONIZE steps on the coffee-shop
    application.
    Expect the coffee-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.

  1. Go back to the OpenShift Container Platform web console.
  2. From the Administrator perspective, select Project: prod-coffeeshop.
  3. From the navigation menu, select Workloads → Deployments.
  4. Locate the coffee-shop deployment, click options_menu_icon(Options), and select Edit Pod count.
  5. Click ⊕ (Plus) four times to scale up the deployment to five pods.
  6. Return to the Argo CD web console.
  7. 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 REFRESHto 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-coffeeshopnamespace. In this exercise, you will learn how the log is changed.

9.1 Add prod-coffeeshop Namespace to ClusterLogForwarder

  1. Go to the OpenShift Container Platform web console and select the Administrators perspective.
  2. On the navigation menu, select Home → Search.
  3. From the Project: drop-down list, select the openshift-logging namespace.
  4. From the Resources drop-down list, select ClusterLogForwarder.
  5. Click the CLF instance.
  6. Click the YAML tab.
  7. Scroll to line 52, - dev-coffeeshop.
  8. Immediately after line 52, insert -prod-coffeshop into this YAML array as a new array element.

Expect it to look like this:
insert image description here
9. Click Save.

9.2 Verify New Logs

  1. Go to the Kibana web console.
  2. Create a new index pattern to capture all of the Coffee Shop projects—both dev-coffeeshop and prod-coffeeshop:
    a. On the navigation menu, click Management.
    b. Click Create index pattern and add an index pattern named *-coffeeshop-*.
    c. Click Next.
    d. In the Time Filter field select @timestamp.
  3. From the navigation menu, click Discover.
  4. Select the *-coffeeshop-* index pattern you just built, and also the Available Fields kubernetes.namespace_name and structured.message.
    Expect to see results from both the dev-coffeeshop and prod-coffeeshop namespaces.
  5. 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

Guess you like

Origin blog.csdn.net/xixihahalelehehe/article/details/123336100