| 
 | 1 | +---  | 
 | 2 | +sidebar_position: 3  | 
 | 3 | +title: ArgoCD Example  | 
 | 4 | +---  | 
 | 5 | + | 
 | 6 | +### Introduction  | 
 | 7 | + | 
 | 8 | +This guide explains how to use the provided example to deploy a complete OceanBase environment using ArgoCD. The example follows the "App of Apps" pattern, where a single parent ArgoCD application (`oceanbase-stack`) manages the deployment of all the other child applications, ensuring they are created in the correct order using a combination of Sync Phases and Waves.  | 
 | 9 | + | 
 | 10 | +### Prerequisites  | 
 | 11 | + | 
 | 12 | +Before you begin, ensure you have the following:  | 
 | 13 | + | 
 | 14 | +*   A running Kubernetes cluster.  | 
 | 15 | +*   ArgoCD installed on your cluster. You can find the installation instructions in the [official ArgoCD documentation](https://argo-cd.readthedocs.io/en/stable/getting_started/).  | 
 | 16 | +*   `kubectl` installed and configured to connect to your cluster.  | 
 | 17 | + | 
 | 18 | +### Installation  | 
 | 19 | + | 
 | 20 | +The installation process involves applying a single manifest to your ArgoCD cluster, which will then deploy all the necessary components.  | 
 | 21 | + | 
 | 22 | +**Step 1: Configure Custom Health Checks**  | 
 | 23 | + | 
 | 24 | +For ArgoCD to accurately report the status of all resources, you must add custom health check scripts to the `argocd-cm` ConfigMap.  | 
 | 25 | + | 
 | 26 | +1.  Create a file named `argocd-health-patch.yaml` with the following content:  | 
 | 27 | +    ```yaml  | 
 | 28 | +    data:  | 
 | 29 | +      resource.customizations.health.argoproj.io_Application: |  | 
 | 30 | +        hs = {}  | 
 | 31 | +        hs.status = "Progressing"  | 
 | 32 | +        hs.message = ""  | 
 | 33 | +        if obj.status ~= nil then  | 
 | 34 | +          if obj.status.health ~= nil then  | 
 | 35 | +            hs.status = obj.status.health.status  | 
 | 36 | +            if obj.status.health.message ~= nil then  | 
 | 37 | +              hs.message = obj.status.health.message  | 
 | 38 | +            end  | 
 | 39 | +          end  | 
 | 40 | +        end  | 
 | 41 | +        return hs  | 
 | 42 | +      resource.customizations.health.oceanbase.oceanbase.com_OBCluster: |  | 
 | 43 | +        hs = {}  | 
 | 44 | +        if obj.status == nil or obj.status.status == nil then  | 
 | 45 | +          hs.status = "Progressing"  | 
 | 46 | +          hs.message = "Waiting for status"  | 
 | 47 | +          return hs  | 
 | 48 | +        end  | 
 | 49 | +
  | 
 | 50 | +        local current_status = obj.status.status  | 
 | 51 | +        if current_status == "running" then  | 
 | 52 | +          hs.status = "Healthy"  | 
 | 53 | +          hs.message = "Cluster is running"  | 
 | 54 | +        elseif current_status == "failed" then  | 
 | 55 | +          hs.status = "Degraded"  | 
 | 56 | +          hs.message = "Cluster has failed"  | 
 | 57 | +        else  | 
 | 58 | +          hs.status = "Progressing"  | 
 | 59 | +          hs.message = "Cluster is " .. current_status  | 
 | 60 | +        end  | 
 | 61 | +        return hs  | 
 | 62 | +      resource.customizations.health.oceanbase.oceanbase.com_OBTenant: |  | 
 | 63 | +        hs = {}  | 
 | 64 | +        if obj.status == nil or obj.status.status == nil then  | 
 | 65 | +          hs.status = "Progressing"  | 
 | 66 | +          hs.message = "Waiting for status"  | 
 | 67 | +          return hs  | 
 | 68 | +        end  | 
 | 69 | +
  | 
 | 70 | +        local current_status = obj.status.status  | 
 | 71 | +        if current_status == "running" then  | 
 | 72 | +          hs.status = "Healthy"  | 
 | 73 | +          hs.message = "Tenant is running"  | 
 | 74 | +        elseif current_status == "failed" then  | 
 | 75 | +          hs.status = "Degraded"  | 
 | 76 | +          hs.message = "Tenant has failed"  | 
 | 77 | +        else  | 
 | 78 | +          hs.status = "Progressing"  | 
 | 79 | +          hs.message = "Tenant is " .. current_status  | 
 | 80 | +        end  | 
 | 81 | +        return hs  | 
 | 82 | +    ```  | 
 | 83 | +
  | 
 | 84 | +2.  Apply the patch to your `argocd-cm` ConfigMap:  | 
 | 85 | +    ```bash  | 
 | 86 | +    kubectl patch configmap argocd-cm -n argocd --patch-file argocd-health-patch.yaml  | 
 | 87 | +    ```  | 
 | 88 | + | 
 | 89 | +**Step 2: Prepare the Repository**  | 
 | 90 | + | 
 | 91 | +The example files are configured to be deployed from the upstream OceanBase operator repository. If you are deploying from your own fork of the repository, you must first update the `repoURL` in the application manifests.  | 
 | 92 | + | 
 | 93 | +The following files need to be updated to point to your Git repository:  | 
 | 94 | +- `example/argocd/oceanbase-stack.yaml`  | 
 | 95 | +- `example/argocd/apps/secrets.yaml`  | 
 | 96 | +- `example/argocd/apps/obcluster.yaml`  | 
 | 97 | +- `example/argocd/apps/obtenant.yaml`  | 
 | 98 | +- `example/argocd/apps/ob-configserver.yaml`  | 
 | 99 | +- `example/argocd/apps/obproxy.yaml`  | 
 | 100 | + | 
 | 101 | +In each file, change the `repoURL` to your forked repository's URL.  | 
 | 102 | + | 
 | 103 | +**Step 3: Deploy the Application Stack**  | 
 | 104 | + | 
 | 105 | +The `oceanbase-stack` application is the parent application that manages all other components. Deploy it to your ArgoCD instance using the following command:  | 
 | 106 | + | 
 | 107 | +```bash  | 
 | 108 | +kubectl apply -f example/argocd/oceanbase-stack.yaml -n argocd  | 
 | 109 | +```  | 
 | 110 | + | 
 | 111 | +**Step 4: Monitor the Deployment**  | 
 | 112 | + | 
 | 113 | +Once the `oceanbase-stack` application is created, you can monitor the deployment process in the ArgoCD UI. The deployment follows a specific order to ensure dependencies are met:  | 
 | 114 | + | 
 | 115 | +*   **Pre-Sync Phase:** The following applications are deployed first to set up the foundational components. ArgoCD will wait for these to complete and become Healthy before moving on.  | 
 | 116 | +    *   `ob-operator`: Installs the OceanBase operator and its CRDs.  | 
 | 117 | +    *   `secrets`: Creates the necessary password secrets.  | 
 | 118 | +    *   `ob-configserver`: Deploys the configuration server.  | 
 | 119 | + | 
 | 120 | +*   **Wave 1:** After the Pre-Sync phase is successful, this wave deploys the main cluster components.  | 
 | 121 | +    *   `obcluster`: Deploys the OceanBase cluster.  | 
 | 122 | +    *   `obproxy`: Deploys the proxy.  | 
 | 123 | + | 
 | 124 | +*   **Wave 2:** After Wave 1 is healthy, the final wave deploys the tenant.  | 
 | 125 | +    *   `obtenant`: Deploys the tenant.  | 
 | 126 | + | 
 | 127 | +### Verification  | 
 | 128 | + | 
 | 129 | +After the sync process is complete, all applications in the ArgoCD UI should have a `Synced` and `Healthy` status.  | 
 | 130 | + | 
 | 131 | +You can also verify the deployment using `kubectl`:  | 
 | 132 | +- Check the pods in the `oceanbase` and `oceanbase-system` namespaces to ensure all components are running.  | 
 | 133 | +- Check the status of the `OBCluster` and `OBTenant` custom resources.  | 
 | 134 | + | 
 | 135 | +### Accessing the Database  | 
 | 136 | + | 
 | 137 | +Once all the applications are `Synced` and `Healthy`, the `oceanbase-stack` provides a fully functional OceanBase tenant that is compatible with MySQL. You can connect to this database instance from other applications within your Kubernetes cluster.  | 
 | 138 | + | 
 | 139 | +**Connection Details:**  | 
 | 140 | + | 
 | 141 | +*   **Host:** `obproxy.oceanbase.svc.cluster.local`  | 
 | 142 | +*   **Port:** `2883`  | 
 | 143 | +*   **Username:** `root@obtenant`  | 
 | 144 | +*   **Password:** The password is automatically generated and stored in a Kubernetes secret.  | 
 | 145 | + | 
 | 146 | +To retrieve the password, run the following command:  | 
 | 147 | + | 
 | 148 | +```bash  | 
 | 149 | +kubectl get secret tenant-root-password -n oceanbase -o jsonpath='{.data.password}' | base64 -d  | 
 | 150 | +```  | 
 | 151 | + | 
 | 152 | +You can use these details to configure any MySQL-compatible client or application to connect to your OceanBase tenant.  | 
 | 153 | + | 
 | 154 | +### Troubleshooting  | 
 | 155 | + | 
 | 156 | +**Sync Failures due to Network Issues:**  | 
 | 157 | +The ArgoCD server needs to be able to connect to the Git repository and the Helm repository. If you see `Unknown` sync statuses or errors like `context deadline exceeded`, it indicates a network problem between your ArgoCD instance and the internet. Ensure that firewalls, proxies, and network policies are configured to allow this traffic.  | 
0 commit comments