|
| 1 | +--- |
| 2 | +title: "Lab 4: Config Sync Groups" |
| 3 | +weight: 400 |
| 4 | +toc: true |
| 5 | +nd-content-type: tutorial |
| 6 | +nd-product: nginx-one |
| 7 | +--- |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +In this lab, you create and manage Config Sync Groups in NGINX One Console. Config Sync Groups keep your NGINX instances in sync with a shared configuration. You learn to create a group, add instances, apply a shared config, and fix sync errors. |
| 12 | + |
| 13 | +## What you’ll learn |
| 14 | + |
| 15 | +By the end of this lab, you'll know how to: |
| 16 | + |
| 17 | +- Create a Config Sync Group |
| 18 | +- Add instances to a Config Sync Group |
| 19 | +- Update the shared configuration for a Config Sync Group |
| 20 | + |
| 21 | +## Before you begin |
| 22 | + |
| 23 | +Make sure you have: |
| 24 | + |
| 25 | +- Completed [Lab 2: Run workshop components with Docker]({{< ref "nginx-one/workshops/lab2/run-workshop-components-with-docker.md" >}}) |
| 26 | +- Docker and Docker Compose installed and running |
| 27 | +- Your data plane key in the `TOKEN` environment variable (set in Lab 2): |
| 28 | + |
| 29 | + ```shell |
| 30 | + export TOKEN="your-data-plane-key" |
| 31 | + ``` |
| 32 | + |
| 33 | +- Your NGINX Plus JWT license file saved as `nginx-repo.jwt`, and `JWT` set (set in Lab 2): |
| 34 | + |
| 35 | + ```shell |
| 36 | + export JWT=$(cat path/to/nginx-repo.jwt) |
| 37 | + ``` |
| 38 | + |
| 39 | +- Your unique identifier in the NAME environment variable (set in Lab 2), for example `s.jobs`: |
| 40 | + |
| 41 | + ```shell |
| 42 | + export NAME="s.jobs" |
| 43 | + ``` |
| 44 | + |
| 45 | +- Basic familiarity with Linux command line and NGINX concepts |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## Exercise 1: Create a Config Sync Group |
| 50 | + |
| 51 | +A Config Sync Group lets you apply one configuration to multiple NGINX instances and keep them in sync. |
| 52 | + |
| 53 | +1. In the NGINX One Console, select **Manage > Config Sync Groups**. |
| 54 | +2. In the **Config Sync Groups** pane, select **Add Config Sync Group**. |
| 55 | +3. In the **Add Config Sync Group** form, in the **Name** field, enter `$NAME-sync-group` (for example, `s.jobs-sync-group`). |
| 56 | +4. Select **Create**. The new group appears with **Details** and **Configuration** tabs. |
| 57 | + - The **Details** tab shows: |
| 58 | + - Object ID |
| 59 | + - Last publication status and config version ID |
| 60 | + - Config Sync Status (for example, Unknown) |
| 61 | + - Instance status counts (In Sync, Out of Sync, Offline, Unavailable) |
| 62 | +5. Switch to the **Configuration** tab to view your group’s configuration files. It’s empty for now. You’ll add one in Exercise 2. |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +## Exercise 2: Add instances to the Config Sync Group |
| 67 | + |
| 68 | +{{< call-out "note" "Note" "" >}} You can mix OSS and Plus instances in one group. But any config feature you use must work on every instance. If you need Plus-only features, put them in a separate group. {{</ call-out >}} |
| 69 | + |
| 70 | +When you create a Config Sync Group, it has no shared config to begin with. You can add a shared config in two ways: |
| 71 | + |
| 72 | +- **Define config manually**: select your group, go to the **Configuration** tab, then select **Edit Configuration**. Add or paste your NGINX config, select **Next**, review the diff, and select **Save and Publish**. |
| 73 | +- **Populate from first instance**: add one NGINX instance. The console uses that instance’s existing config as the group’s shared config. |
| 74 | + |
| 75 | +### Populate group config from first instance |
| 76 | + |
| 77 | +Add a single NGINX instance so the console uses its existing config as the group’s shared config. |
| 78 | + |
| 79 | +1. Select **Manage > Config Sync Groups**. |
| 80 | +2. Select your `$NAME-sync-group` group. (For example, `s.jobs-sync-group`.) |
| 81 | +3. On the **Details** tab, in the **Instances** pane, select **Add Instance to Config Sync Group**. |
| 82 | +4. Select **Register a new instance with NGINX One then add to config sync group**, then select **Next**. |
| 83 | +5. Select **Use existing key**, paste `$TOKEN` (or your actual data plane key) into the **Data Plane Key** box. |
| 84 | +6. Select the **Docker Container** tab. The tab shows sample commands for logging in, pulling an image, and running the container. Copy those sample commands and modify them as follows: |
| 85 | + |
| 86 | +7. Log in to the private registry: |
| 87 | + |
| 88 | + ```shell |
| 89 | + echo "$JWT" \ |
| 90 | + | docker login private-registry.nginx.com \ |
| 91 | + --username "$JWT" --password-stdin |
| 92 | + ``` |
| 93 | + |
| 94 | +8. Pull a Docker (replace version as needed). Subject to availability, you can replace the agent with the specific NGINX Plus version, OS type, and OS version you need. Here we are going to pull the r31 version of NGINX+ on alpine to demonstrate that.See [Pulling the image]({{< ref "nginx/admin-guide/installing-nginx/installing-nginx-docker.md#pull-the-image" >}}). |
| 95 | + |
| 96 | + ```shell |
| 97 | + docker pull private-registry.nginx.com/nginx-plus/agent:nginx-plus-r31-alpine-3.19-20240522 |
| 98 | + ``` |
| 99 | + |
| 100 | +9. Copy the docker run command from the user interface and modify it as follows: |
| 101 | + |
| 102 | + - Replace `YOUR_JWT_HERE` in `--env NGINX_LICENSE_JWT` with `$JWT` |
| 103 | + - Replace `YOUR_DATA_PLANE_KEY` in `--env NGINX_AGENT_SERVER_TOKEN` with `$TOKEN` |
| 104 | + - Add `--hostname "$NAME-one-manual"` and `--name "$NAME-one-manual"` flags |
| 105 | + - Ensure `--env NGINX_AGENT_INSTANCE_GROUP="$NAME-sync-group"` is set |
| 106 | + |
| 107 | + ```shell |
| 108 | + docker run \ |
| 109 | + --hostname "$NAME-one-manual" \ |
| 110 | + --name "$NAME-one-manual" \ |
| 111 | + --env NGINX_LICENSE_JWT="$JWT" \ |
| 112 | + --env NGINX_AGENT_SERVER_GRPCPORT=443 \ |
| 113 | + --env NGINX_AGENT_SERVER_HOST=agent.connect.nginx.com \ |
| 114 | + --env NGINX_AGENT_SERVER_TOKEN="$TOKEN" \ |
| 115 | + --env NGINX_AGENT_INSTANCE_GROUP="$NAME-sync-group" \ |
| 116 | + --env NGINX_AGENT_TLS_ENABLE=true \ |
| 117 | + --restart always \ |
| 118 | + --runtime runc \ |
| 119 | + -d private-registry.nginx.com/nginx-plus/agent:nginx-plus-r31-alpine-3.19-20240522 |
| 120 | + ``` |
| 121 | + |
| 122 | +10. In the **Config Sync Groups** panel, select **Refresh**. The new instance appears and the shared config populates. The first instance added becomes the default config source. |
| 123 | +11. Select the **Configuration** tab to view the shared config. |
| 124 | + |
| 125 | +#### Add instances using Docker Compose |
| 126 | + |
| 127 | +Instead of registering each container manually, you can set the sync group in your compose file and restart all containers at once. |
| 128 | + |
| 129 | +You can edit the `docker-config.yaml` file to add those instances to the config sync group: |
| 130 | + |
| 131 | +1. Stop the running containers: |
| 132 | + |
| 133 | + ```shell |
| 134 | + docker compose down |
| 135 | + ``` |
| 136 | + |
| 137 | +2. Open `docker-compose.yaml` in a text editor. |
| 138 | +3. Uncomment the lines beginning with: |
| 139 | + |
| 140 | + ```yaml |
| 141 | + NGINX_AGENT_INSTANCE_GROUP: $NAME-sync-group |
| 142 | + ``` |
| 143 | +
|
| 144 | +4. Restart all containers: |
| 145 | +
|
| 146 | + ```shell |
| 147 | + docker compose up --force-recreate -d |
| 148 | + ``` |
| 149 | + |
| 150 | +5. In the NGINX One Console, select **Refresh**. The instances with `NGINX_AGENT_INSTANCE_GROUP` set appear in the Config Sync Group. |
| 151 | + |
| 152 | +6. Instances automatically sync the existing NGINX config. When the sync finishes, the **Config Sync Status** shows `In Sync`. |
| 153 | + |
| 154 | +<span style="display: inline-block;"> |
| 155 | +{{< img src="nginx-one/images/config-sync-status.png" |
| 156 | + alt="Table showing hostnames, NGINX versions, operating systems, availability status, and green In Sync indicators for each instance in the config sync group" >}} |
| 157 | +</span> |
| 158 | + |
| 159 | + |
| 160 | +## Exercise 3: Edit the group config and sync changes |
| 161 | + |
| 162 | +Modify the shared group configuration and apply those changes to all group members. |
| 163 | + |
| 164 | +1. Select **Manage > Config Sync Groups**, then choose your `$NAME-sync-group` (for example, `s-jobs-sync-group`). |
| 165 | +2. Select the **Configuration** tab. |
| 166 | +3. Select **Edit Configuration** (pencil icon). |
| 167 | +4. In the file list, select `default.conf`. |
| 168 | +5. In the editor pane, add these lines at 21–24: |
| 169 | + |
| 170 | + ```yaml |
| 171 | + location /test_header { |
| 172 | + add_header X-Test-App true; |
| 173 | + return 200 'HTTP/1.1 200 OK\nContent-Type: text/html\n\n<html><body>Welcome to Lab 4 of the NGINX One Console Workshop!</body></html>'; |
| 174 | + } |
| 175 | + ``` |
| 176 | + |
| 177 | + <span style="display: inline-block;"> |
| 178 | + {{< img src="nginx-one/images/config-sync-edits.png" |
| 179 | + alt="" >}} |
| 180 | + </span> |
| 181 | + |
| 182 | + When you make these edits, the file is marked "modified" and the validator shows **NGINX Config OK**. |
| 183 | +6. Select **Next**, review the diff, then select **Save and Publish**. |
| 184 | +7. Select the **Details** tab and confirm **Last Publication Status** shows **Succeeded**. |
| 185 | +8. In the **Instances** table, confirm each host shows **Config Sync Status** = **In Sync**. |
| 186 | +9. Test your change by curling any instance’s HTTP endpoint. Replace `<HOST>` and `<PORT>` with your instance’s host name or IP and the port shown in the Instances table (for example, `localhost:80`): |
| 187 | + |
| 188 | + ```shell |
| 189 | + curl http://localhost:80/test_header |
| 190 | + ``` |
| 191 | + |
| 192 | + You should see: |
| 193 | + |
| 194 | + ```text |
| 195 | + HTTP/1.1 200 OK |
| 196 | + Content-Type: text/html |
| 197 | +
|
| 198 | + <html><body>Welcome to Lab 4 of the NGINX One Console Workshop!</body></html> |
| 199 | + ``` |
| 200 | + |
| 201 | +--- |
| 202 | + |
| 203 | +## Next steps |
| 204 | + |
| 205 | +You have created a Config Sync Group and added instances. In Lab 5, you will install your NGINX Plus license (JWT) on each instance so you can upgrade them to NGINX R34. |
| 206 | + |
| 207 | +Go to [Lab 5: Upgrade to R34]() |
| 208 | + |
| 209 | +--- |
| 210 | + |
| 211 | +## References |
| 212 | + |
| 213 | +- [NGINX One Console docs](https://docs.nginx.com/nginx-one/) |
0 commit comments