In the previous article, we have discussed how to deploy a local Java application directly to an Alibaba Cloud ECS instance. For those who are already using Alibaba Cloud Container Service for Kubernetes, you may be wondering how to use this plug-in to deploy applications on Container Service for Kubernetes. In this article, we will answer this question and explain how to deploy applications to Alibaba Cloud Container Service for Kubernetes.
Alibaba Cloud Container Service for Kubernetes provides enterprise-level high-performance and flexible management of Kubernetes containerized applications throughout the application lifecycle. This service simplifies cluster creation and expansion and integrates Alibaba Cloud capabilities in virtualization, storage, network, and security, providing an improved running environment for Kubernetes containerized applications.
This article takes a Java servlet for printing "Hello World" on a Web page as an example to explain the deployment method.
public class IndexServlet extends HttpServlet {
private static final long serialVersionUID = -112210702214857712L;
@Override
public void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
PrintWriter writer = resp.getWriter();
// Demo: Use Alibaba Cloud Toolkit to modify the code of a local application and deploy the application to the cloud.
writer.write("Deploy from alibaba cloud toolkit. 2018-10-24");
return;
}
@Override
protected void doPost( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
return;
}}
You can download the source code through this link.
The preceding code is a standard Java project used to print the string "Hello World" on a Web page.
Write a Dockerfile file (download file) and save it in the root directory of the project.
FROM tomcat:8.5.34-jre8
COPY target/javademo.war /usr/local/tomcat/webapps/
Alibaba Cloud provides an Eclipse-based plug-in to help developers efficiently deploy applications written in the local IDE to Container Service for Kubernetes.
URL of the plug-in: https://www.aliyun.com/product/cloudtoolkit_en
The installation process of this Eclipse-based plug-in is similar to that of a common plug-in, and therefore will not be detailed here.
After installing the plug-in, configure the preferences by choosing:
Top menu > Window > Preferences > Alibaba Cloud Toolkit > Accounts
When the following page is displayed, configure the AK and SK of your Alibaba Cloud account to complete the configuration of preferences.( If you are using a RAM user account, enter the AK and SK of the RAM user.)
Configure a Docker connection to package the project locally as an image.
Choose Top menu > Window > Preferences > Alibaba Cloud Toolkit > Docker
In Eclipse, right-click the project name and choose Alibaba Cloud > Deploy to CS Kubernetes from the shortcut menu. The following deployment window is displayed:
In the Select a package method dialog box, set Context Directory and Dockerfile of the local application (usually automatically identified and set according to your local application), and click Next.
You can select Use Maven build to build an application using Maven according to your requirements.
In the Select a Repository dialog box, select the region, namespace, and image repository of Container Registry, and click Next.
Note: If you do not have an image repository yet, click Create a new repository in the upper-right corner of the dialog box to create an image repository. For more information about the creation procedure, refer to this documentation.
In the Deploy Project to CS Kubernetes dialog box, select the cluster, namespace, and deployment of Container Service for Kubernetes, and click Finish.
Note: If you have not created a deployment for Container Service for Kubernetes, click Create a new Kubernetes deployment in the upper-right corner of the dialog box to go to the Container Service ¨C Kubernetes console and create a deployment. For more information about the creation procedure, refer to this documentation.
Click Finish to deploy the local application to Container Service for Kubernetes.
Alibaba Cloud Blockchain Service Team - January 17, 2019
Alibaba Clouder - June 9, 2020
Alibaba Clouder - August 19, 2019
Alibaba Container Service - April 18, 2024
Xi Ning Wang - March 1, 2019
ProsperLabs - May 10, 2023
Robotic Process Automation (RPA) allows you to automate repetitive tasks and integrate business rules and decisions into processes.
Learn MoreAlibaba Cloud Container Service for Kubernetes is a fully managed cloud container management service that supports native Kubernetes and integrates with other Alibaba Cloud products.
Learn MoreA PaaS platform for a variety of application deployment options and microservices solutions to help you monitor, diagnose, operate and maintain your applications
Learn MoreSelf-driving Database Platform: Self-repair, Self-optimization, and Self-security
Learn MoreMore Posts by Nick(倪超)