All Products
Search
Document Center

Elastic Container Instance:Build a WordPress application on an elastic container instance

Last Updated:Mar 18, 2024

You can use Cloud Shell to manage Elastic Container Instance resources. This topic describes how to use Cloud Shell to create an ACK serverless cluster and create an elastic container instance in the cluster to deploy a WordPress application on the instance.

Background information

WordPress is a blog-publishing system that is written in the PHP language. You can use WordPress as a content management system (CMS) or use WordPress to build websites on servers that support the PHP language and the MySQL database.

Cloud Shell is a CLI provided by Alibaba Cloud. You can run Cloud Shell on a browser to manage Alibaba Cloud resources. For more information about Cloud Shell, see What is Cloud Shell?

Create an ACK Serverless cluster

  1. Open Cloud Shell, confirm the message that appears, and clone the tutorial script to Cloud Shell.

  2. Go to the directory in which the WordPress tutorial is located.

    cd eci-wordpress
  3. (Optional) Modify the configuration file of the cluster.

    vim create.json

    The create.json file contains the parameters for creating an ACK Serverless cluster. The following code provides the default configurations of the parameters.

    {
    	"cluster_type": "ManagedKubernetes",
    	"profile": "Serverless",
    	"name": "wordpress-demo",
    	"region_id": "cn-hangzhou",
    	"endpoint_public_access": true,
    	"snat_entry": true,
    	"addons": [{
    		"name": "csi-provisioner",
    		"config": ""
    	}],
    	"zoneid": "cn-hangzhou-j"
    }

    The following parameters can be modified:

    • name: the name of the cluster.

    • region_id: the ID of the region in which the cluster resides.

    • endpoint_public_access: specifies whether to enable Internet access for the API server.

    • snat_entry: specifies whether to create a NAT gateway and configure Source Network Address Translation (SNAT) rules.

    • zoneid: the ID of the zone in which the cluster resides.

  4. Run the following command to create the ACK Serverless cluster:

    aliyun cs POST /clusters --header "Content-Type=application/json" --body "$(cat create.json)"

    After the cluster is created, a message similar to the following message is returned. cluster_id indicates the cluster ID.

    {
    	"cluster_id": "c5789a864e71848ab9fa57013********",
    	"instanceId": "c5789a864e71848ab9fa57013********",
    	"request_id": "C5044E47-7AAD-5D6F-A8D9-2249F1******",
    	"task_id": "T-6528e986ba8151096d******"
    }
  5. View the properties of the cluster.

    aliyun cs GET /clusters/<YOUR-CLUSTER-ID>

Deploy the WordPress application

Important

Make sure that the ACK Serverless cluster that you created is initialized before you install WordPress in the cluster. The initialization requires 3 to 5 minutes.

  1. Manage the ACK Serverless cluster.

    source use-k8s-cluster ${Cluster ID}

    Replace {Cluster ID} in the preceding command with the ID of your cluster. Example:

    source use-k8s-cluster c5789a864e71848ab9fa57013********
  2. Deploy the WordPress application.

    Important

    When you use the wordpress-all-in-one-pod.yaml file to deploy a WordPress application, the system automatically creates an elastic IP address (EIP) and associates the EIP with the Elastic Container Instance-based pod to which the WordPress application corresponds.

    kubectl apply -f wordpress-all-in-one-pod.yaml
    Note

    When you open Cloud Shell, you are prompted to clone the YAML script of the application to Cloud Shell. Clone the wordpress-all-in-one-pod.yaml script from the eci-wordpress directory.

  3. View the deployment progress.

    kubectl get pods

    The following result is returned. If the status of the pod changes to Running, the WordPress application is deployed.

    NAME        READY   STATUS    RESTARTS   AGE
    wordpress   2/2     Running   0          5m59s
  4. View the EIP of the WordPress application.

    kubectl get -o json pod wordpress |grep "k8s.aliyun.com/allocated-eipAddress"

    The following output is returned:

    "k8s.aliyun.com/allocated-eipAddress": "47.99.XX.XX"
  5. Configure the security group for the WordPress application.

    1. Obtain the ID of the security group.

      kubectl get -o json pod wordpress |grep "k8s.aliyun.com/eci-security-group"

      The following output is returned:

      "k8s.aliyun.com/eci-security-group": "sg-bp1fw6ecxb0obm******"
    2. Enable port 80 for the security group.

      aliyun ecs AuthorizeSecurityGroup --RegionId ${Region ID} --SecurityGroupId ${Security group ID} --IpProtocol tcp --PortRange 80/80 --SourceCidrIp 0.0.0.0/0 --Priority 100

      Replace {Region ID} and {Security group ID} in the command with an actual region ID and security group ID in your business scenario. Example:

      aliyun ecs AuthorizeSecurityGroup --RegionId cn-hangzhou --SecurityGroupId sg-bp1fw6ecxb0obm******  --IpProtocol tcp --PortRange 80/80 --SourceCidrIp 0.0.0.0/0 --Priority 100

Install WordPress and log on to the WordPress application

  1. Access the WordPress application.

    Enter the EIP of the WordPress application in the browser. Example: http://47.99.XX.XX.

  2. Select a language, click Continue, enter the basic information about the WordPress website that you want to open, and then click Install WordPress.

    wordpress2

    You must configure the following parameters:

    • Site Title: the name of the WordPress website.

    • Username: the username that you want to use to log on to WordPress. Make sure that your username is secure.

    • Password: the password that you want to use to log on to WordPress. We recommend that you specify a strong password.

    • Your Email: the email that you want to use to receive notifications.

  3. Click LOGIN.

  4. Enter the username and password that you specified when you installed WordPress, and then click LOGIN.

    After you log on to WordPress, you can open the WordPress website that you specified.

    wordpress3