0% found this document useful (0 votes)
37 views

Ops Autoscaling

Uploaded by

tinytribe20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Ops Autoscaling

Uploaded by

tinytribe20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Practice: Create a Load Balancer and Configure

Autoscaling

Try this hands-on lab with the Oracle Cloud Free Tier. If you do not have a free
account, click here to get one.

Overview
In this practice, you create a load balancer. When you create a load balancer, you choose its
shape (size) and specify subnets from different Availability Domains. This ensures that the
load balancer is highly available.

Tasks
1. Log in to the OCI free tier account
2. From the OCI Services menu, select Load Balancers under Networking.
3. Click Create Load Balancer. Fill out the dialog box:
Under Add Details
 Load Balancer Name: Enter a name for your load balancer, for example, opslb.
 Choose Visibility Type: Select Public.
 Virtual Cloud Network: Choose the OpsVCN Virtual Cloud Network.
 Subnet: Choose the Public Subnet.
Click Next Step.
4. Under Choose Backends:
 Specify a Load Balancing Policy: Weighted Round Robin
 Add Backends: Don't add any backend. This will be managed by the instance pool.

Copyright © 2021, Oracle and/or its affiliates.

Oracle Cloud Infrastructure Operations Associate Workshop 1


5. Under SPECIFY HEALTH CHECK POLICY:
 PROTOCOL: HTTP
 Port: 80
 URL PATH (URI): /
Leave the other options as default. Click Next Step.

Copyright © 2021, Oracle and/or its affiliates.

2 Oracle Cloud Infrastructure Operations Associate Workshop


6. Under Configure Listener:
 Specify The Type Of Traffic Your Listener Handles: HTTP
 Specify The Port Your Listener Monitors For Ingress Traffic: 80
Leave the other options as default.

7. Manage Logging – Disable Logging


8. Click Submit to Create Load Balancer.
Wait for the load balancer to become active and then note down its Public IP address.
9. From the OCI Services menu, select Virtual Cloud Network under Networking. Locate
OpsVCN you created earlier. Click the VCN name to display the VCN detail page.
10. Click Security Lists, and locate the Default Security List.
11. Click Default Security List, and then click Add Ingress Rule. Enter the following ingress
rule; ensure that you leave the STATELESS flag deselected.
 Source Type: CIDR
 Source CIDR: Enter 0.0.0.0/0
 IP Protocol: Select TCP
 Source Port Range: All
 Destination Port Range: Enter 80 (the listener port).
12. Click Add Ingress Rule.

Copyright © 2021, Oracle and/or its affiliates.

Oracle Cloud Infrastructure Operations Associate Workshop 3


Practice: Configure Instance Pool and Autoscaling

Overview
Configuring an instance pool requires creating an instance configuration.

Tasks
1. From the OCI services menu, select Instances under Compute.
2. Click Create Instance. Fill out the dialog box:
 Name your instance: opsauto
 Compartment: Ensure that the Compartment assigned to you is selected.
 Availability Domain: Select any Availability Domain.
 Image Operating System: Use the default, the latest Oracle Linux available.
 Shape: Select - VM.Standard.E2.1.Micro. Ensure to use Virtual Machine instance
type and change the shape if this is not selected by default.
 Configure Networking:
 Network: Choose Select existing cloud network.
 VCN Compartment: The same that has been allocated to you
 For VCN: Select OpsVCN created earlier.
 Subnet: Select the Public Subnet of your VNC.
 Select Assign a public IP address.
 SSH Key: Select the Paste public keys option and paste the public ssh key you had
created earlier using Cloud Shell.
 Boot Volume: Use the default; leave this section as is.

Copyright © 2021, Oracle and/or its affiliates.

4 Oracle Cloud Infrastructure Operations Associate Workshop


3. Click Show Advanced Options. Under Management:
 User Data: Select 'Paste cloud-init script' and paste the below script.
Cloud-init script will be executed at the first boot only to configure the instance.
Basically, we’ll add a new YUM repository, install a couple of packages, and initialize
our web server.
#cloud-config

yum_repos:
# The name of the repository
epel-testing:
# Any repository configuration options
# See: man yum.conf
#
# This one is required!
baseurl:
https://yum$ociregion.oracle.com/repo/OracleLinux/OL7/developer_
EPEL/$basearch/
enabled: true
failovermethod: priority
gpgcheck: false
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
name: Extra Packages for Enterprise Linux 5 - Testing

packages:
- httpd
- stress

runcmd:
- [sh, -c, echo "<html>Web Server IP `hostname --ip-
address`</html>" > /var/www/html/index.html]
- [firewall-offline-cmd, --add-port=80/tcp]
- [systemctl, start, httpd]
- [systemctl, restart, firewalld]

Copyright © 2021, Oracle and/or its affiliates.

Oracle Cloud Infrastructure Operations Associate Workshop 5


4. Click Create.
5. Once the instance is in Running state, select Create Instance Configuration from the
Action menu.
Fill out the dialog box:
 Create In Compartment: Choose your compartment.
 Instance Configuration Name: Auto-scale-config

Copyright © 2021, Oracle and/or its affiliates.

6 Oracle Cloud Infrastructure Operations Associate Workshop


6. Click Create Instance Configuration.
7. On the Instance Configuration page, click Create Instance Pool.
A new dialog box will appear. This is used to create an initial configuration of the instance
pool such as how many compute instance to create initially, VCN, and the Availability
Domain the instance pool should be created in. Fill out the dialog box:
 Create in Compartment: Choose your compartment.
 Instance Pool Name: Provide a suitable name.
 Number of Instances: 0
(This is the number of computes that should be launched when the pool is created.
We will start with no compute.)
 Availability Domain: Choose the AD in which you want to place the instances. (You
can choose the first AD if in Multi AD region.)
 Virtual Cloud Network Compartment: Choose VCN's compartment.
 Virtual Cloud Network: Choose your VCN.
 Subnet Compartment: Choose your compartment.
 Subnet: Choose the Public Subnet.
 Note: The following step of adding a second AD applies only if you are working in
Multi AD Region. This step should be skipped for Single AD Region.
 Click + Additional Selection and select a different Availability Domain for the
instance pool. Then, specify the VCN details for the second Availability Domain.
We configured instances to be deployed in two different Availability Domains
although they can be deployed in the same Availability Domain as long as service
limits allow it.
For this lab, use two different Availability Domains.
8. Finally, click Create Instance Pool. Wait for Instance Pool to be in RUNNING state (turns
green).

Copyright © 2021, Oracle and/or its affiliates.

Oracle Cloud Infrastructure Operations Associate Workshop 7


9. On the Instance Pool page, select “Load Balancers” from the Resources menu on the left.
Click Attach a Load Balancer.

10. Select the Load Balancer you created previously, and then the only Backend Set in the
menu. Enter port 80 and then “Primary VNIC”. Click Attach.

11. On the Instance Pool Details page, from the More Actions menu, select Create Auto
Scaling Configuration. Fill out the dialog box:
 Compartment: Choose your compartment.
 Autoscaling Configuration Name: Provide a name.
 Instance Pool: This should show your instance pool name created earlier.
Copyright © 2021, Oracle and/or its affiliates.

8 Oracle Cloud Infrastructure Operations Associate Workshop


 Keep the default “Metric-based Autoscaling.
 Cooldown In Seconds: 300 (This is the minimum period of time between scaling
actions.)
 Autoscaling Policy Name: Provide a name.
 Performance Metric: CPU Utilization (This is the Metric to use for triggering scaling
actions.)
 Minimum Number of Instances: 1 (This is the minimum number of instances that
the pool will always have.)
 Maximum Number of Instances: 2 (This is the maximum number of instances that
the pool will always have.)
 Initial Number of Instances: 1 (This is how many instances will be created in the
instance pool initially.)
 Scale-Out Operator: Greater than (>)
 Threshold Percentage: 40
 Number of Instances To Add: 1
 Scale-In Operator: Less than (<)
 Threshold Percentage: 10
 Number Of Instances To Remove: 1
 Leave the other fields as is.
 Click Create.

We have now created an autoscaling policy that will start with creating one compute instance
in the designated pool.
 Once the CPU utilization is determined to be above 40% for at least 300 seconds
another compute instance will be launched automatically.
 Once the CPU utilization is determined to be less than 10% for 300 seconds, one
compute instance will be removed.
 At all times, there will be at least one compute instance in the pool.
 The original image can be deleted because it's not part of the pool.

Copyright © 2021, Oracle and/or its affiliates.

Oracle Cloud Infrastructure Operations Associate Workshop 9


Practice: Test the Setup

Tasks
This test may not succeed on always free-account because of limits, however the process
done here will give you idea on auto-scaling with load-balancers, scaling rules, backend
sets
1. Click Instance Pools under Compute and then your pool name. You should see a
Compute instance created. You may have to wait a few minutes for it to be provisioned.
Click the Compute Instance name.
2. Note down the Public and Private IP of compute instance from the details page (under the
Primary VNIC Information section).
3. Open a web browser and enter load balancer's public IP address. You should see the
message: Web Server IP: <instance private IP>. If you get an error such as
“502 Invalid Gateway”, wait a few minutes for the compute instance to be fully
initialized and try again.
Note: In case you wait 10 minutes and still encounter an error, check the back-end pool
status. Check the assigned port number.
4. Connect to the instance from the local machine, use the Terminal.
$ ssh –i <path-of-pub-ssh-key> opc@<Public_IP_of_Compute>
5. Now start CPU stress; enter the command:
$ sudo stress --cpu 4 --timeout 700
Spawn 4 workers spinning on sqrt() with a timeout of 700 seconds.
6. Switch back to OCI console and navigate to the Instance Pool Details page. Click your
instance name and scroll down to the Metric screen. You should see CPU spiking up after
a minute or so.

Copyright © 2021, Oracle and/or its affiliates.

10 Oracle Cloud Infrastructure Operations Associate Workshop


7. Navigate to your Instance Pool Details page. In about 3-4 minutes (time configured when
you created autoscale configuration), status of Pool should change to Scaling and a
second compute instance should launch.
This is since your criteria of CPU utilization > 40 was met.

8. When the second instance is up and running and the instance pool status is Running,
switch to the web browser and refresh the page multiple times and observe the load
balancer balancing traffic between the two web servers.
9. Switch back to the terminal window and if the stress tool is still running, press Ctrl + C to
stop the script.
10. Switch back to the OCI console window and navigate to your compute instance details
page. Verify that the CPU utilization goes down after a minute.
11. Navigate to the Instance Pool Details page and after 3-4 minutes, the Instance pool status
will change to Scaling. Additional compute instances will be deleted.
This is because your criteria of CPU utilization < 10 is met.

This is the end of course practices.

Copyright © 2021, Oracle and/or its affiliates.

Oracle Cloud Infrastructure Operations Associate Workshop 11

You might also like