Best Practices for Spring Cloud Applications in Kubernetes: Deployment (Development and Deployment)
By Guyi, Alibaba Cloud Senior Technical Expert, focusing on EDAS development and user experience optimization
In the article “Cloud-based Practices for Spring Cloud Applications in Kubernetes: Development”, we described how to use two tools to initialize a Spring Cloud application and run it locally. In this article, we will describe how to run the application mentioned in the preceding article on the cloud.
To run an application on the cloud, you need a Kubernetes cluster. The fastest method of using a Kubernetes cluster in Enterprise Distributed Application Service (EDAS) is to import an Alibaba Cloud Container Service Kubernetes (ACK) cluster to EDAS.
If no ACK cluster is available, you can use one of the following methods to create one:
- Log on to the Container Service for Kubernetes console to create an ACK cluster.
- If you already have a cluster created in a cloud or a cluster created from other Internet data centers (IDCs) or vendors, you can import it to Container Service for Kubernetes by clicking Register Existing Cluster.
When the Kubernetes cluster is ready, you need to import the cluster in the EDAS console:
When you import a cluster, EDAS performs the following operations:
- Initializes the cluster controllers and related resources in EDAS, including the Open Application Model (OAM) controllers based on the standards of cloud-native open applications, the agent for log collection, and the information about the Application Real-Time Monitoring Service (ARMS) environment in the monitoring process. Most of the controllers will run in a management cluster that is hosted in and maintained by EDAS. Therefore, they will not occupy any resources in your cluster.
- Defines the relationships between the cluster and the namespaces in EDAS based on your plans. Namespaces in EDAS are used to isolate services and configuration. To put it simply, they can be used to isolate environments in daily research and development, such as development, testing, and production environments. When you import a cluster, you will also confirm the environment where the cluster is used.
When the cluster is ready, you need to initialize a cloud application. Go to the wizard for application creation in EDAS and select the created cluster to create an application. In the Application Runtime Environment section, you will see four types, Custom, Java, Ali-Tomcat, and EDAS Container, as shown in the following figure.
Note: After an application is created, you can no longer change the type of the runtime environment. Here is a brief description of these types:
- Java, Tomcat, and EDAS Container environments: If you choose one of these runtime environments, EDAS will pack the uploaded file and the corresponding base image into an image of the application.
- Custom environment: If you select the runtime environment that uses an image, each deployment will be performed with a specified custom image. A custom image must meet certain specifications. For more information, see Create Docker images for applications in the documentation of Alibaba Cloud. The core is the following code:
# Inherit the official image in EDAS.
# Download the file to the /home/admin/app directory.
ADD http://your.domain.com/file/location.jar /home/admin/app/
Note: When you run applications in EDAS, they are actually deployments in Kubernetes that are controlled by the OAM controllers. Therefore, in addition to the preceding methods of creating EDAS applications, you can also directly convert these deployments into EDAS applications. We will dive into the conversion between EDAS applications and the deployments in Kubernetes in a dedicated section.
Directly Deploy Kubernetes Applications by Using the IDE Plug-In
After initializing the application, you can pack the application and directly deploy it using the IDE plug-in during the development phase. When you deploy applications by using the plug-in, you are provided with corresponding options for the selected runtime environment, as shown in the following figure.
If you are in the development environment, we recommend that you use non-custom images in the IDE plug-in to improve development efficiency. The file upload speed in the IDE plug-in is more than three times faster than that in the console, which is ideal for uploading large deployment packages. Moreover, compared with building or pushing images before deployment, directly submitting WAR or JAR files is much faster.
For more information about how to deploy applications by using the IDE plug-in, see Use Alibaba Cloud Toolkit to deploy applications to EDAS.
Summary and What to Do Next
In this article, we have taken the perspective of developers and described how to deploy application packages to EDAS. In the development environment, we recommend that you directly upload WAR or JAR files by using the plug-in, which is the fastest among all methods of deploying applications in Kubernetes clusters. In the next article, we will take the perspective of O&M staff and describe how to use other tools in EDAS to build deployment procedures.