Deploy a WordPress application using ECI

更新时间:
复制 MD 格式

You can manage ECI instances using Cloud Shell. This topic uses a WordPress deployment as an example to show how to use Cloud Shell to create an ACK Serverless cluster and quickly create an ECI instance to deploy a containerized application.

Background

WordPress is a blog platform developed in PHP. You can use WordPress to build a website on a server that supports PHP and MySQL, or you can use it as a content management system (CMS).

Cloud Shell is a command-line tool provided by Alibaba Cloud. You can use Cloud Shell in a browser to run commands and manage your Alibaba Cloud resources. For more information about Cloud Shell, see Cloud Shell.

Create an ACK Serverless cluster

  1. Open Cloud Shell. In the dialog box that appears, confirm that you want to clone the tutorial script to Cloud Shell.

  2. Go to the directory for the WordPress tutorial.

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

    vim create.json

    The create.json file contains the parameters to create the ACK Serverless cluster. The default configuration is as follows:

    {
    	"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 file contains the following parameters:

    • name: The name of the cluster.

    • region_id: The ID of the region where the cluster is deployed.

    • endpoint_public_access: Specifies whether to expose the API server to the internet.

    • snat_entry: Specifies whether to create a NAT gateway and configure SNAT rules.

    • zoneid: The ID of the zone where the cluster is deployed.

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

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

    A successful command returns a response similar to the following. The cluster_id field is the ID of the new cluster.

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

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

Deploy the WordPress application

Important

Make sure that the ACK Serverless cluster is initialized before you install WordPress. The initialization process typically takes 3 to 5 minutes.

  1. Connect to the ACK Serverless cluster.

    source use-k8s-cluster ${CLUSTER_ID}

    Replace ${CLUSTER_ID} with the ID of your cluster. For 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 the WordPress application, an EIP is automatically created and associated with the application's ECI pod.

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

    When you open Cloud Shell, Cloud Shell prompts you to clone the required scripts. The wordpress-all-in-one-pod.yaml file is located in the eci-wordpress directory.

  3. Check the deployment status.

    kubectl get pods

    The following is the expected output. The deployment is successful when the pod status is Running.

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

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

    Expected output:

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

    1. Get the security group ID.

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

      Expected output:

      "k8s.aliyun.com/eci-security-group": "sg-bp1fw6ecxb0obm******"
    2. Add a rule to the security group to allow access over port 80.

      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} with your region ID and security group ID. For example:

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

Install and log in to WordPress

  1. Access the WordPress application.

    In the address bar of your browser, enter the EIP address of the WordPress application. For example, http://47.99.XX.XX.

  2. Select a language and click Continue. Then, enter the required information and click Install WordPress.

    This includes the following:

    • Site Title: The name of your WordPress website.

    • Username: The username used to log in to WordPress. Make sure that the username is secure.

    • Password: The password used to log in to WordPress. We recommend that you set a strong password.

    • Your Email: The email address used to receive notifications.

  3. Click Log In.

  4. Enter the username and password that you set during the WordPress installation, and then click Log In.

    After you successfully log in, the WordPress dashboard appears.