EDAS allows you to create a PHP application from source code and deploy the application to a Container Service Kubernetes cluster or serverless Kubernetes (ASK) cluster. EDAS provides diverse features for you to manage applications, such as application scaling, monitoring and alerting, load balancing, and throttling and degradation. The steps of deploying a PHP application to a Container Service Kubernetes cluster are similar to those of deploying a PHP application to an ASK cluster. In this topic, an example is used to build a PHP application from source code and deploy the application to a Container Service Kubernetes cluster.
- Both EDAS and Container Service for Kubernetes are activated for your Alibaba Cloud account. For more information, see the following topics:
- A namespace is created. For more information, see Namespace management.
- Role authorization is complete in Container Service for Kubernetes. For more information, see ACK default roles.
Step 1: Create a Container Service Kubernetes cluster
To create a Serverless Kubernetes cluster, set VPC to Create VPC and set Service Discovery to PrivateZone. This allows the Serverless Kubernetes cluster to use Alibaba Cloud Service Mesh after the cluster is imported to EDAS. If you set VPC to Select Existing VPC, check whether the cluster contains the virtual private cloud (VPC) and vSwitch resources after you create the cluster.
Step 2: Import the Container Service Kubernetes cluster to the EDAS console
By default, the ack-ahas-sentinel-pilot, ack-arms-pilot, and ack-arms-prometheus components are installed when you add a Kubernetes cluster to EDAS in the EDAS console. The ack-ahas-sentinel-pilot component is an application protection component for throttling and degradation. The ack-arms-pilot component is an Application Real-Time Monitoring Service (ARMS) monitoring component. The ack-arms-prometheus component is a Prometheus monitoring component.
- Log on to the EDAS console.
- In the left-side navigation pane, choose .
- In the top navigation bar, select the region where you want to import the cluster, and click Synchronize Container Service Kubernetes Cluster.
- In the Actions column of the Container Service Kubernetes cluster that you want to import, click Import.
- In the Import Kubernetes Cluster dialog box, select the destination namespace from the Namespace drop-down list, turn
on or off Service Mesh, and then click Import.If the value of Cluster Status is Running and the value of Import Status is Imported. for the Container Service Kubernetes cluster, the Container Service Kubernetes cluster is imported to EDAS.
Step 3: Deploy your PHP application to the Container Service Kubernetes cluster
- Log on to the EDAS console.
- In the left-side navigation pane, click Applications. In the top navigation bar, select a region. In the upper part of the page, select a namespace. In the upper-left corner of the Applications page, click Create Application.
- In the Basic Information step, specify the Cluster Type and Application Runtime Environment parameters for
the application that you want to create and click Next.
Parameter Description Cluster Type Select Kubernetes Clusters. Application Runtime Environment In this topic, PHP is selected. An image built by using EDAS provides a runtime environment for PHP 7.3 and Apache 2.4. Some frequently used PHP plug-ins are installed in the runtime environment.
- In the Configurations step, configure the environment information, basic information, source code, and
image parameters for your application and click Next.
Parameter Description Namespace Select a namespace that you have created. If you have not created a namespace or do not select a namespace, the namespace is set to Default. Cluster From the drop-down list on the right side, select the imported Container Service Kubernetes cluster. K8s Namespace Internal system objects are allocated to different namespaces to form logically isolated projects, groups, or user groups. This way, different groups can be separately managed and can also share the resources of the entire cluster.
- default: The default namespace. If no namespace is specified for an object, the default namespace is used.
- kube-system: The namespace of the objects that are created by the system.
- kube-public: The namespace that is automatically created by the system. This namespace can be read by all the users, including the users who are not authenticated.
In this example, default is selected.
Application Name Enter an application name. The name must start with a letter and can contain digits, letters, and hyphens (-). The name must be 1 to 36 characters in length. Application Description Enter a description of the application. The description can be a maximum of 128 characters in length. Source of Deployment Package By default, Source Code is selected. Version You can use the timestamp as the version number or specify a custom version number. Code Repository URL Enter the public endpoint of the code repository that you want to use for your PHP application. HTTPS and Git protocols are supported. Authentication Method If your code repository is a private repository, you must configure this parameter.
- Username and Password: Select a secret that you have created. If no secret is available, perform the following
steps to create a secret:
- On the right side of the field, click Create Secret.
- In the Create Secret dialog box, specify the Secret Name, Username, and Password parameters.
- Then, in the dialog box, click Create.
- SSH Key: Specify the SSH key provided by EDAS in the code repository.
Branch or Tag Enter a branch or a tag of the code repository. Advanced Configuration (optional) Turn on Advanced Configuration and configure the following parameters:
- Clone Submodule: Submodules allow you to use a Git repository as a subdirectory of another Git repository. This feature allows you to clone a repository to your project and separately commit your application code.
- Working Directory: Specify a directory where the files you are processing are to be stored. All the operations related to Git are completed in this directory.
- Output Path: Specify a directory where Git output files are to be stored.
Total Pods Specify the number of pods on which the application is to be deployed. Single-pod Resource Quota Specify the amount of CPU and memory resources that you want to reserve for a pod. To set a limit, enter a numeric value. The default value 0 indicates that no limit is set.
- Optional:Configure the advanced settings for the application. Then, click Create Application.
- Specify environment variables. When you create the application, pass the environment variables that you specify to the container to be generated. This way, you do not need to repeatedly add commonly used environment variables.
- If you want to specify the parameters for the JVM heap memory, JVM property parameters,
Java agent parameters, and other parameters, add the parameters in this step:
- Variable Name: CATALINA_OPTS.
- Variable Value: [Parameters to be added] $(EDAS_CATALINA_OPTS).
- If you use a MySQL image, you can add the following environment variables:
- MYSQL_ROOT_PASSWORD (required): allows you to set a MySQL root password.
- MYSQL_USER and MYSQL_PASSWORD (optional): allows you to add an account in addition to the root account and set a password.
- MYSQL_DATABASE (optional): allows you to specify the database that you want to create when the container is generated.
- If you are using another type of image, specify the environment variables as needed.
- If you want to specify the parameters for the JVM heap memory, JVM property parameters, Java agent parameters, and other parameters, add the parameters in this step:
- Configure persistent storage.
In Container Service Kubernetes clusters, the physical storage of a native volume object is not persistent. This means that the volume object is a temporary storage object and has the same lifecycle as a Kubernetes pod. You can use Apsara File Storage NAS (NAS) to persistently store instance data. This way, if an instance is upgraded or migrated, the instance data is retained.Note Before you configure persistent storage, make sure that you have activated NAS for your Alibaba Cloud account that you use to access the EDAS service. To use the NAS service, make sure that the Alibaba Cloud account has sufficient balance or the billing method is pay-as-you-go. For more information about NAS billing rules, see Billable item and billing methods.
Parameter Description Storage Type The default value is Apsara File Storage NAS. The value of the parameter cannot be changed. Storage Service Type Only the SSD (Performance-type) option is supported. The value of the parameter cannot be changed. Select NAS
- Buy New NAS: Select a NAS mount directory and a local mount directory. A single region supports up to 10 NAS file systems. If the number of NAS file systems in a single region reaches 10, your attempt to create more NAS file systems fails. If you want to create more NAS file systems, submit a ticket.
- Use Existing NAS: Select an existing NAS file system. You can create up to two mount points. Only the NAS file systems that meet the requirements appear in the drop-down list.
Mount Directory Specify a mount directory and a mount mode.
- Configure application lifecycle management.
Parameter Description PostStart A container hook. The hook is immediately triggered after a container is created. The hook notifies the container that the hook is created. The hook does not pass parameters to the corresponding hook handler. If the corresponding hook handler fails to be executed, the container is stopped and the restart policy of the container is used to determine whether to restart the container. For more information, see Container lifecycle hooks. PreStop A container hook. The hook is triggered before a container is deleted. The corresponding hook handler must be completely executed before the request to delete the container is sent to the Docker daemon. The Docker daemon sends an SIGTERM signal to itself to delete the container, regardless of the execution result of the corresponding hook handler. For more information, see Container lifecycle hooks. Liveness A probe that monitors your container status. The probe checks whether your applications are healthy. If an application is unhealthy, its corresponding container is deleted and re-created. For more information, see Pod lifecycle. Readiness A probe that monitors your container status. The probe checks whether your applications have been started and are running as expected. If an application is not running as expected, the container status is updated. For more information, see Pod lifecycle.
- Specify environment variables.
- After you configure the settings, click Create Application. In the Creation Completed step, click Create Application. It takes several minutes to create an application. During the procedure, you can check the progress on the Change List page. After the application is created, the Application Overview page appears. You can check the status of the instance pod. If the pod is in the Running state, the application is released as expected. You can click the status of the pod to view the advanced settings of the application instance, such as Deployment, Pod, and Startup Command.
FAQHow do I view the log records about the errors of creating images?
If you fail to create an image when you deploy an application, you can view the log records on the Change List page. For more information, see View application changes.
What to do next
After the application is created, you can add an Internet-facing Server Load Balancer (SLB) instance to it for Internet access. You can also add an internal-facing SLB instance so that all nodes in the same VPC can access your application by using this internal-facing SLB instance. For more information, see Bind SLB instances or Reuse an SLB instance.