- Simple Layer-7 protocol load balancing
- Web routing service
- Services in a container cluster access each other using Layer-7 protocol by means of communication proxy and Server Load Balancer
See the following figure. When you create a cluster, a Server Load Balancer instance is assigned to the cluster by default. The Server Load Balancer instance adds all the nodes in the cluster to the backend. Port 80 is exposed at the frontend, and port 9080 is exposed on the machines of all the backend nodes. Container Service starts a routing application
acsrouting, namely, the Alibaba Cloud Container Service Routing. This routing application has only one service, the routing service. The routing service is global, which means a copy of this service (or image), namely, a container, is deployed on each node (a node is also called a host or a virtual machine (VM) instance of Elastic Compute Service (ECS)). Each node uses this container to route HTTP services or HTTPS services.
As shown in the preceding figure, for HTTP services, the mapping between Server Load Balancer instance frontend and backend ports is
80:9080, and the port mapping between the host and the container used for routing is
9080:80, indicating that port 80 is exposed on the containers used for routing. Any ports can be exposed on the other containers used as the web service. After you set the port mapping between host and container during container startup, the routing service can obtain the corresponding port for request routing. For a complete example about how to expose HTTP services, see Create an Nginx webserver from an image.
Note: Make sure that the following kernel parameters (in the
/etc/sysctl.conffile) of the related Container Service nodes are set to 0. Otherwise, the nodes might not be accessed.
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.eth0.rp_filter = 0
Set by Services > Update
Log on to the Container Service console.
Click Services in the left-side navigation pane.
Select the cluster in which the service to be exposed resides from the Cluster list.
Click Update at the right of the service to be exposed (wordpress in this example).
Configure the port mapping between host and container on the Update Service page.
The host port is empty, indicating that a random port on the host is exposed (when HTTP or HTTPS services are exposed, you do not need to know what port is exposed on the host, because the container port can be directly accessed by using an overlay network or Virtual Private Cloud (VPC) network). The container port is 80. Use port 80 of the wordpress service to provide the HTTP service. The protocol used is TCP.
Routing configuration exposes the service by using a domain name. Specify the port to be exposed (port 80 of the wordpress service in this example). Enter the domain name prefix in the Domain field. If the domain name prefix is
XXX, the domain name
XXX.$cluster_id.$region_id.alicontainer.comis obtained for testing. In this example, the domain name
wordpress.cb668bde43f054cd7bd515c8739f38310.cn-hangzhou.alicontainer.comis obtained. You can enter your own domain name, which needs to add the resolution to the IP address of the corresponding Server Load Balancer instance. For how to configure the container port used for routing and the domain name of HTTP services, see routing label.
Click Update after completing the configurations.
Click the service name on the Service List page and then click the access endpoint to access the wordpress page.
The wordpress welcome page appears.
Set by application template editor
Log on to the Container Service console.
Click Applications in the left-side navigation pane.
Select the cluster from the Cluster list.
Click Update at the right of the application (wordpress in this example).
Add a routing label in Template, define the corresponding domain name or domain name prefix, update the application version, and confirm whether or not to pull the latest Docker image. Then, click OK to update the domain name.
Click the application name on the Application List page and then click the Routes tab.
Click the route address to access the wordpress welcome page.