|
| 1 | +--- |
| 2 | +title: 'Deploying a blue-green infrastructure' |
| 3 | +slug: blue-green |
| 4 | +excerpt: 'This guide will show you how to deploy a blue-green infrastructure with the OVHcloud Load Balancer' |
| 5 | +section: 'Use case' |
| 6 | +--- |
| 7 | + |
| 8 | +## Objective |
| 9 | + |
| 10 | +With this guide, we will explore a specific use for the OVHcloud Load Balancer service — configuring a service to manage production/development infrastructures easily. This is also called a blue-green infrastructure. |
| 11 | + |
| 12 | +With a `blue-green`{.action} infrastructure, you can stop your infrastructure from experiencing any downtime. The main benefit of this deployment type is that you can prepare updates and/or maintenance in an environment that is isolated from your production environment. This way, you can test your changes before they are put into production, undo them quickly if you detect any faults, and do all of this with virtually zero downtime. |
| 13 | + |
| 14 | +**This guide will show you how to deploy a blue-green infrastructure with the OVHcloud Load Balancer.** |
| 15 | + |
| 16 | + |
| 17 | +## Requirements |
| 18 | + |
| 19 | +To deploy a `blue-green`{.action} infrastructure, you need the following components: |
| 20 | + |
| 21 | +- an OVHcloud Load Balancer service |
| 22 | +- a first server that hosts your production infrastructure |
| 23 | +- a second server with a similar infrastructure, dedicated to development |
| 24 | + |
| 25 | +## Instructions |
| 26 | + |
| 27 | +### Scenario |
| 28 | + |
| 29 | +The scenario we’ll describe here is as follows... |
| 30 | + |
| 31 | +You have an infrastructure that you can use to put your website online. |
| 32 | + |
| 33 | +This infrastructure hosts your website’s code, and it also hosts the applications (web servers, database servers, etc.) required to put your website online. You need to update your applications and/or your code on a regular basis. You want to be able to test your updates without the risk of affecting your website’s availability to customers, or stopping the website from working properly. |
| 34 | + |
| 35 | +One way to achieve this is by deploying a `blue-green`{.action} infrastructure. |
| 36 | + |
| 37 | +The principle of a `blue-green`{.action} deployment involves being able to switch easily from a development infrastructure to a production infrastructure, and vice versa. This switch must be done in a way that is transparent for your users. To do this, we will assign the standard HTTP port 80 for access to the production infrastructure, and the arbitrary port 8888 to access the development infrastructure. |
| 38 | + |
| 39 | + |
| 40 | +## Deploy the infrastructures. |
| 41 | + |
| 42 | +In the scenario we are using, your IP Load Balancer service plays a central role. It is the element you use to expose your two infrastructures (production and development) to different users at the same time. |
| 43 | + |
| 44 | +The production infrastructure can be accessed by your customers on the standard HTTP service (port 80), and your development infrastructure can be accessed by developers and admins on the non-standard port 8888. |
| 45 | + |
| 46 | +During the initial setup phase, we will arbitrarily assign a role to each of the parts of our infrastructure. `Infrastructure A`{.action} will be assigned to production, while `infrastructure B`{.action} will be assigned to development. At this stage, we will consider them to be similar to one another. |
| 47 | + |
| 48 | +A `blue-green`{.action} infrastructure involves switching from infrastructure A to infrastructure B, when infrastructure B is ready to expose your website after your changes have been applied and tested. The IP Load Balancer will manage this switch. |
| 49 | + |
| 50 | +The diagram below gives a general idea of the architecture: |
| 51 | + |
| 52 | + |
| 53 | +{.thumbnail} |
| 54 | + |
| 55 | + |
| 56 | +### Infrastructure A. |
| 57 | + |
| 58 | +This infrastructure is made up of a server farm that will later be associated with a front-end of your IP Load Balancer. This farm will expose an HTTP, TCP or UDP service to the front-end. It also balances loads by sending the front-end’s incoming traffic to the servers. For more detail on the role of various component of the OVHcloud Load Balancer service, you can read the following guide: [](use_presentation/guide.gb-en.md){.ref}. |
| 59 | + |
| 60 | +In our scenario, we will declare a farm of servers for the HTTP service. Please note that you can create as many farms (as well as TCP and/or UDP services) as are required for your final service to be exposed to your customers. |
| 61 | + |
| 62 | + |
| 63 | +#### Via the OVHcloud Control Panel: |
| 64 | + |
| 65 | +{.thumbnail} |
| 66 | + |
| 67 | + |
| 68 | +{.thumbnail} |
| 69 | + |
| 70 | + |
| 71 | +#### Via the API: |
| 72 | + |
| 73 | +> [!api] |
| 74 | +> |
| 75 | +> @api {POST} /ipLoadbalancing/{serviceName}/http/farm |
| 76 | +> |
| 77 | +
|
| 78 | +|Setting|Meaning| |
| 79 | +|---|---| |
| 80 | +|serviceName|Your Load Balancer service ID| |
| 81 | + |
| 82 | +With the additional calls listed below, you can list, modify and delete your server farms respectively. |
| 83 | + |
| 84 | + |
| 85 | +> [!api] |
| 86 | +> |
| 87 | +> @api {GET} /ipLoadbalancing/{serviceName}/http/farm |
| 88 | +> |
| 89 | +
|
| 90 | +> [!api] |
| 91 | +> |
| 92 | +> @api {PUT} /ipLoadbalancing/{serviceName}/http/farm |
| 93 | +> |
| 94 | +
|
| 95 | +> [!api] |
| 96 | +> |
| 97 | +> @api {DELETE} /ipLoadbalancing/{serviceName}/http/farm |
| 98 | +> |
| 99 | +
|
| 100 | +Associate a server with your farm, if it is a physical server hosting your production infrastructure. The service exposed to the front-end is supplied by the server’s port 8080. Please note that you can associate one or more servers with each farm (to balance the load and/or offer higher fault tolerance, for ex.). |
| 101 | + |
| 102 | +#### Via the OVHcloud Control Panel: |
| 103 | + |
| 104 | +{.thumbnail} |
| 105 | + |
| 106 | + |
| 107 | +{.thumbnail} |
| 108 | + |
| 109 | + |
| 110 | +#### Via the API: |
| 111 | + |
| 112 | +> [!api] |
| 113 | +> |
| 114 | +> @api {POST} /ipLoadbalancing/{serviceName}/http/farm/{farmId}/server |
| 115 | +> |
| 116 | +
|
| 117 | +|Setting|Required|Meaning|Example| |
| 118 | +|---|---|---|---| |
| 119 | +|serviceName|Required|Your Load Balancer service ID|loadbalancer-abcdef0123456789| |
| 120 | +|farmId|Required|Your server farm ID|77212| |
| 121 | +|address|Required|Your server's IPv4 address|10.10.1.100| |
| 122 | +|displayName||The name of the server associated with your farm|HTTP A server| |
| 123 | +|port||The server port associated with your farm|8080| |
| 124 | + |
| 125 | +With the additional calls listed below, you can list, modify and delete your servers respectively. |
| 126 | + |
| 127 | + |
| 128 | +> [!api] |
| 129 | +> |
| 130 | +> @api {GET} /ipLoadbalancing/{serviceName}/http/farm/{farmId}/server |
| 131 | +> |
| 132 | +
|
| 133 | +> [!api] |
| 134 | +> |
| 135 | +> @api {PUT} /ipLoadbalancing/{serviceName}/http/farm/{farmId}/server |
| 136 | +> |
| 137 | +
|
| 138 | +> [!api] |
| 139 | +> |
| 140 | +> @api {DELETE} /ipLoadbalancing/{serviceName}/http/farm/{farmId}/server |
| 141 | +> |
| 142 | +
|
| 143 | + |
| 144 | +### Infrastructure B. |
| 145 | + |
| 146 | +Functionally, this second infrastructure is identical to the first. It is also composed of a server farm that will later be associated with a second front-end of your IP Load Balancer. This server farm exposes the same service to the front-end as the first server farm. This service is supplied on the servers by port 8080. |
| 147 | + |
| 148 | +Deploy the server farm for the HTTP service (and/or any other TCP or UDP services required for your final service to be exposed to your customers). |
| 149 | + |
| 150 | + |
| 151 | +#### Via the Sunrise Control Panel: |
| 152 | + |
| 153 | +{.thumbnail} |
| 154 | + |
| 155 | + |
| 156 | +{.thumbnail} |
| 157 | + |
| 158 | + |
| 159 | +#### Via the API: |
| 160 | + |
| 161 | +> [!api] |
| 162 | +> |
| 163 | +> @api {POST} /ipLoadbalancing/{serviceName}/http/farm |
| 164 | +> |
| 165 | +
|
| 166 | +|Setting|Meaning| |
| 167 | +|---|---| |
| 168 | +|serviceName|Your Load Balancer service ID| |
| 169 | + |
| 170 | +Associate a server with your farm. Here, it involves one or more physical servers hosting your development infrastructure. |
| 171 | + |
| 172 | + |
| 173 | +#### Via the OVHcloud Control Panel: |
| 174 | + |
| 175 | +{.thumbnail} |
| 176 | + |
| 177 | + |
| 178 | +{.thumbnail} |
| 179 | + |
| 180 | + |
| 181 | +#### Via the API: |
| 182 | + |
| 183 | +> [!api] |
| 184 | +> |
| 185 | +> @api {POST} /ipLoadbalancing/{serviceName}/http/farm/{farmId}/server |
| 186 | +> |
| 187 | +
|
| 188 | + |
| 189 | +|Setting|Required|Meaning|Example| |
| 190 | +|---|---|---|---| |
| 191 | +|serviceName|Required|Your Load Balancer service ID|loadbalancer-abcdef0123456789| |
| 192 | +|farmId|Required|Your server farm ID|77213| |
| 193 | +|address|Required|Your server's IPv4 address|10.10.2.100| |
| 194 | +|displayName||The name of the server associated with your farm|HTTP B server| |
| 195 | +|port||The server port associated with your farm|8080| |
| 196 | + |
| 197 | +At this stage, here is the configuration status for your two farms: |
| 198 | + |
| 199 | +{.thumbnail} |
| 200 | + |
| 201 | + |
| 202 | +## Front-ends. |
| 203 | + |
| 204 | +The magic of `blue-green`{.action} deployment lies in the configuration of your front-ends. At this stage, we have configure two functionally identical infrastructures. For both infrastructures, you have declared one or more server farms, each with their own set of associated servers. |
| 205 | + |
| 206 | +To switch simply from one infrastructure to another, we will use front-ends. |
| 207 | + |
| 208 | +To do this, we need to declare two front-ends. The first one will give you access to your production infrastructure, whereas the second will give you access to your development infrastructure. You can control access to one infrastructure or the other using the ports you expose to your customers. |
| 209 | + |
| 210 | + |
| 211 | +> [!warning] |
| 212 | +> |
| 213 | +> If the final service you expose to your customers requires several server farms (e.g. ports 80 and 443), you will need to declare a `front-end`{.action} for each of your farms. |
| 214 | +> |
| 215 | +
|
| 216 | + |
| 217 | +### Blue front-end. |
| 218 | +This `front-end`{.action} is dedicated to accessing the production infrastructure. The ports exposed to your customers are the standard ports for accessing the service. In this case, we are exposing a HTTP service, so we will use port 80 (443 if you would like an SSL termination). |
| 219 | + |
| 220 | + |
| 221 | +#### Via the OVHcloud Control Panel: |
| 222 | + |
| 223 | +{.thumbnail} |
| 224 | + |
| 225 | + |
| 226 | +{.thumbnail} |
| 227 | + |
| 228 | + |
| 229 | +#### Via the API: |
| 230 | + |
| 231 | +> [!api] |
| 232 | +> |
| 233 | +> @api {POST} /ipLoadbalancing/{serviceName}/http/frontend |
| 234 | +> |
| 235 | +
|
| 236 | +|Setting|Required|Meaning|Example| |
| 237 | +|---|---|---|---| |
| 238 | +|serviceName|Required|Your Load Balancer service ID|loadbalancer-abcdef0123456789| |
| 239 | +|defaultFarmId||Your production farm’s ID|77212| |
| 240 | +|displayName||The name given to the front-end|Blue front-end| |
| 241 | +|port|Required|The port exposed to your customers by your front-end|80| |
| 242 | +|zone|Required|The zone in which you want to deploy your front-end|all| |
| 243 | + |
| 244 | + |
| 245 | +### Green front-end. |
| 246 | + |
| 247 | +This `front-end`{.action} is dedicated to accessing the development infrastructure. The ports exposed to your customers will be non-standard ports that you can choose arbitrarily. In this case, we will expose the HTTP development service on port 8888. |
| 248 | + |
| 249 | + |
| 250 | +#### Via the OVHcloud Control Panel: |
| 251 | + |
| 252 | +{.thumbnail} |
| 253 | + |
| 254 | + |
| 255 | +{.thumbnail} |
| 256 | + |
| 257 | + |
| 258 | +#### Via the API: |
| 259 | + |
| 260 | +> [!api] |
| 261 | +> |
| 262 | +> @api {POST} /ipLoadbalancing/{serviceName}/http/frontend |
| 263 | +> |
| 264 | +
|
| 265 | +|Setting|Required|Meaning|Example| |
| 266 | +|---|---|---|---| |
| 267 | +|serviceName|Required|Your Load Balancer service ID|loadbalancer-abcdef0123456789| |
| 268 | +|defaultFarmId||Your production farm’s ID|77213| |
| 269 | +|displayName||The name given to the front-end|Green front-end| |
| 270 | +|port|Required|The port exposed to your customers by your front-end|8888| |
| 271 | +|zone|Required|The zone in which you want to deploy your front-end|all| |
| 272 | + |
| 273 | + |
| 274 | +## Manage the deployments. |
| 275 | + |
| 276 | +### Initial deployment. |
| 277 | + |
| 278 | +Once you have finished configuring the components of the OVHcloud Load Balancer service, you now just need to apply your changes. |
| 279 | + |
| 280 | +#### Via the OVHcloud Control Panel: |
| 281 | + |
| 282 | +{.thumbnail} |
| 283 | + |
| 284 | + |
| 285 | +#### Via the API: |
| 286 | + |
| 287 | +> [!api] |
| 288 | +> |
| 289 | +> @api {POST} /ipLoadbalancing/{serviceName}/refresh |
| 290 | +> |
| 291 | +
|
| 292 | +|Setting|Meaning| |
| 293 | +|---|---| |
| 294 | +|serviceName|Your Load Balancer service ID| |
| 295 | + |
| 296 | + |
| 297 | +### The production/pre-production switch. |
| 298 | + |
| 299 | +At this stage, our initial environment is deployed and ready to use. How do we use it? |
| 300 | + |
| 301 | +To put it simply, you just need to switch over your front-ends from one server farm to another. |
| 302 | + |
| 303 | +Let’s take a look at our scenario: |
| 304 | + |
| 305 | +- The production infrastructure (A) is deployed on `HTTP farm A`{.action} (id 77212), which in turn is attached to `HTTP server A`{.action}. This infrastructure can be accessed through the `blue front-end`{.action}. |
| 306 | +- The development infrastructure (B) is deployed on `HTTP farm B`{.action} (id 77213), which in turn is attached to `HTTP server B`{.action}. This infrastructure can be accessed through the `green front-end`{.action}. |
| 307 | + |
| 308 | +Once you have modified/applied updates to `infrastructure B`{.action} and checked that the service is working properly, you decide to put it into production. |
| 309 | + |
| 310 | +To switch between the two farms, you can simply update your different front-ends by modifying the ID of the farm it is attached to, and applying the modification. |
| 311 | + |
| 312 | +The `blue front-end`{.action} (id 70089) will then be associated with `Farm B`{.action} (infrastructure B, new production, id 77213). |
| 313 | + |
| 314 | +The `green front-end`{.action} (id 70090) will then be associated with `Farm A`{.action} (infrastructure A, new development, id 77212). |
| 315 | + |
| 316 | +This should be the result on the Sunrise Control Panel after updating the front-ends and applying the new configuration: |
| 317 | + |
| 318 | + |
| 319 | +{.thumbnail} |
| 320 | + |
| 321 | + |
| 322 | +#### Via the API: updating front-ends and applying modifications#### |
| 323 | + |
| 324 | +> [!api] |
| 325 | +> |
| 326 | +> @api {PUT} /ipLoadbalancing/{serviceName}/http/frontend/{frontendId} |
| 327 | +> |
| 328 | +
|
| 329 | +|Setting|Meaning|Example| |
| 330 | +|---|---|---| |
| 331 | +|serviceName|Your Load Balancer service ID|loadbalancer-abcdef0123456789| |
| 332 | +|frontendId|Your production front-end ID|70089| |
| 333 | +|defaultFarmId|Your development server farm ID|77213| |
| 334 | + |
| 335 | +> [!api] |
| 336 | +> |
| 337 | +> @api {PUT} /ipLoadbalancing/{serviceName}/http/frontend/{frontendId} |
| 338 | +> |
| 339 | +
|
| 340 | +|Setting|Meaning|Example| |
| 341 | +|---|---|---| |
| 342 | +|serviceName|Your Load Balancer service ID|loadbalancer-abcdef0123456789| |
| 343 | +|frontendId|Your production front-end ID|70090| |
| 344 | +|defaultFarmId|Your development server farm ID|77212| |
| 345 | + |
| 346 | + |
| 347 | +#### To apply your changes and effectively switch over the production and development environments: |
| 348 | + |
| 349 | +> [!api] |
| 350 | +> |
| 351 | +> @api {POST} /ipLoadbalancing/{serviceName}/refresh |
| 352 | +> |
| 353 | +
|
| 354 | +|Setting|Meaning| |
| 355 | +|---|---| |
| 356 | +|serviceName|Your Load Balancer service ID| |
| 357 | + |
| 358 | + |
| 359 | +## Go further |
| 360 | + |
| 361 | +You now have an infrastructure you can use to simply and efficiently manage `blue-green deployments`{.action}. |
| 362 | + |
| 363 | +Developers have access to a development environment on port 8888 (or whichever other port you would prefer to define), while your customers continue to access the service in production via the standard HTTP port (80 in our case, for example). |
| 364 | + |
| 365 | +The infrastructure presented here is limited to just one port, but it can be expanded by adding other ports. For example, you can also expose your website on the standard HTTPS port (443). You can do this by defining new farms dedicated to each port you want to expose, and associating them with their corresponding front-ends (one for the standard port exposed in production, the second for the arbitrary port dedicated to development). |
| 366 | + |
| 367 | +Another way to consolidate your infrastructure even further is by multiplying the servers attached to your farms. This way, you can make your services more redundant (guaranteeing availability as a result), and also add a load balancing capacity. |
0 commit comments