This topic shows how to quickly deploy a stateless application with an Nginx image. You can create an application from the console, pull the Nginx image, and create a service and an Ingress to configure the network. Then, you can access the application through a domain name.
Prerequisites
You need a Container Compute Service (ACS) cluster in which no Ingress is bound to the domain namefoo.bar.com.
Step 1: Create an Nginx application
-
Log on to the ACS console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of the target cluster. In the left navigation pane, choose Workloads > Deployments.
-
On the Deployments page, click Create from Image in the upper-right corner. Configure the application by using the parameters in the following table. This table describes only the key parameters; you can keep the default values for all others.
Wizard step
Description
Example value
Instructions
Basic Information
Set the application name and click Next.
nginxtest
Set Application Name to
nginxtestand click Next.Container
Select an Nginx image:
-
In the Image Name section, click Select Image.
-
Click Artifact center.
-
Search for nginx.
-
Select the nginx image, click Select Image Version , select a version, and then click OK .
-
Configure other settings as needed and click Next.
nginx
Advanced
Create a service:
-
To the right of Services, click Create.
-
Add a port mapping.
-
Name: http
-
Service Port: 80
-
Container Port: 80
-
-
Click Create.
-
Service Name: nginxtest-svc
-
Port Name: http
-
Service Port: 80
-
Container Port: 80
For Type, select Load Balancer and Public Access. Select New SLB (the specification defaults to slb.s1.small). For External Traffic Policy, select Local.
Create an Ingress (optional):
-
To the right of Ingresses, click Create.
-
Set Domain to foo.bar.com. Under Service, select the service you just created from the Name drop-down list.
-
Set Ingress Class to the name of the Ingress Class created by the Application Load Balancer (ALB). For more information, see Quick start for ALB Ingresses.
-
Click Create.
-
Domain: foo.bar.com
-
Name: nginxtest-svc
In the Create Ingress form, set Name to
nginxtest-ingressand select80for Port.Configure Horizontal Pod Autoscaler (HPA):
-
Enable HPA.
-
Set Min. Replicas to 2.
-
Then, click Create.
-
HPA: Enabled
-
Minimum Replicas: 2
Set Metric to CPU Usage, the Trigger Condition to 70%, and Maximum Replicas to 10.
-
The application is created. The deployment, service, Ingress (nginxtest-ingress), and HPA are now active. Click View Application Details to view the application details page.
Step 2: Access the test website
Configure the hosts file
-
Log on to the ACS console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of the target cluster. In the left navigation pane, choose Workloads > Deployments.
-
On the Deployments page, click the name of the application that you created in Step 1.
-
Click the Access Method tab and record the External Endpoint of the Service.
-
Locate the hosts file on your computer and add a binding entry in the following format: Gateway IP addressDomain name. For example,
39.104.XX.XX foo.bar.com. You can then access the service directly by using the domain name.Windows
-
Open File Explorer and enter
C:\WINDOWS\system32\drivers\etcin the address bar to navigate to the etc directory. Locate the hosts file. -
Open the hosts file in Notepad, add
39.104.XX.XX foo.bar.comto the last line, and then save the file.
macOS
-
From the top menu bar, choose Go > Go to Folder, enter
/private/etc, and press Enter. -
Find the hosts file and copy it to your desktop to modify it.
-
Right-click the hosts file on your desktop, select Open With, and then click TextEdit.
-
Add
39.104.XX.XX foo.bar.comto the last line of the hosts file. After saving your changes, move the edited file from your desktop back to the/private/etcfolder, replacing the original file.
-
-
Open the website in a browser.
Open a browser and clear its cache, or open a private browsing window. Enter the domain name
http://foo.bar.comto open the website. After you accessfoo.bar.com, the page displaysWelcome to nginx!, which confirms that the hosts entry and service deployment were successful.
ALB DNS resolution
-
On the Deployments page, click the name of the application that you created in Step 1.
-
Click the Access Method tab and record the Endpoint of the Ingress.
-
Next, add a CNAME record.
-
Log in to the DNS Console.
-
On the Manage DNS page, click Add Zone.
-
In the Add Zone dialog box, enter your host domain and click OK.
You must complete TXT record verification for your host domain.
-
In the Actions column of the target domain, click Settings.
-
On the Settings page, click Add Record.
-
In the Add Record panel, configure the following parameters to add the CNAME record, and then click OK.
|
Parameter |
Description |
|
Record Type |
From the drop-down list, select CNAME. |
|
Hostname |
The prefix for your domain name, such as |
|
Query Source |
Retain the default value. |
|
Record Value |
Enter the CNAME address for the domain name, which is the endpoint you copied. |
|
TTL |
TTL stands for Time To Live. This value specifies how long a DNS record is cached on a DNS server. For this tutorial, keep the default value. |
-
Open the website in a browser.
In a new private browsing window, navigate to http://foo.bar.com.
If you receive a message similar to "This website is inaccessible because it has not been filed with the Ministry of Industry and Information Technology (MIIT) as required by law," check if the load balancer (LB) for the Ingress has a public IP address. If it does, you must complete the ICP filing for your domain name with the MIIT. The domain can be accessed only after the filing is approved.