[JAVA] Porting Kubernetes to container services using Cloud Toolkit.x

This article will show you how to use the Cloud Toolkit to deploy your application on the Container Service for ** Kubernetes **.

In the previous article, I showed you how to deploy your local Java application directly to your Alibaba Cloud ECS instance. For those who are already using Alibaba Cloud Container Service for Kubernetes, use this plugin to deploy the application on Container Service for Kubernetes. You may be curious about how to do it. This article answers this question and explains how to deploy your application to Alibaba Cloud Container Service for Kubernetes.

image.png

About Kubernetes container service

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, integrates Alibaba Cloud capabilities in virtualization, storage, networking, and security to improve the execution environment for Kubernetes containerized applications.

Local development of application

In this article, I will explain how to deploy using a Java Servlet for printing "Hello World" on a web page as an example.

image.png

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;
    }}

[This link](https://alicloud-common.oss-ap-southeast-1.aliyuncs.com/Cloud_Toolkit_Blog/IndexSer...%5B%E9%93%B6%E6%97%B6%5D.1540514368. You can download the source code from zip? spm = a2c65.11461447.0.0.540f69c3aAQxL1 & file = IndexSer ...% 5B% E9% 93% B6% E6% 97% B6% 5D.1540514368.zip).

The code above is a standard Java project for displaying the string "Hello World" on a web page.

Dockerfile file ([Download file](https://alicloud-common.oss-ap-southeast-1.aliyuncs.com/Cloud_Toolkit_Blog/Dockerfi ...% 5B%E9% 93% B6% E6% 97% B6% 5D .1541638004.zip? Spm = a2c65.11461447.0.0.540f69c3aAQxL1 & file = Dockerfi ...% 5B% E9% 93% B6% E6% 97% B6% 5D.1541638004.zip)) and save it in the root directory of your project. I will.

FROM tomcat:8.5.34-jre8
COPY target/javademo.war /usr/local/tomcat/webapps/

Plugin installation

Alibaba Cloud provides Eclipse-based plugins for developers to efficiently deploy applications written in the local IDE to the Container Service for Kubernetes.

Plugin URL: https://www.aliyun.com/product/cloudtoolkit_en

The procedure for installing this Eclipse-based plug-in is similar to a typical plug-in, so we won't go into details here.

Plugin preferences

After installing the plugin, select it and configure the preferences.

Top Menu> Window> Preferences> Alibaba Cloud Toolkit> Account

When the following page is displayed, set the AK and SK of the Alibaba Cloud account, and the setting of the environment setting is completed (If you are using a RAM user account, enter the AK and SK of the RAM user ).

image.png

Set up a Docker connection to package your project locally as an image.

Select Top Menu> Window> Preferences> Alibaba Cloud Toolkit> Docker.

image.png

Deploy application

image.png

Right-click on the project name in Eclipse and select Alibaba Cloud> Deploy to CS Kubernetes from the shortcut menu. The following deployment screen will be displayed.

step 1

image.png

Choosing a packaging method: In the dialog box, set the context directory and Dockerfile for your local application (usually automatically identified and set according to your local application) and click Next.

You can select Use Maven build to build your application using Maven according to your requirements.

Step 2

image.png

Select repository: In the dialog box, select the container registry region, namespace, and image repository, and then click Next.

Note: If you do not already have an image repository, click Create New Repository in the upper right corner of the dialog box to create an image repository. Please refer to this document for the details of the creation procedure.

Step 3

image.png

In the Deploy Project to CS Kubernetes dialog box, select the Container Service for Kubernetes cluster, namespace, and deployment, and then click Finish.

Note: If you have not created a Container Service for Kubernetes deployment, 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. Please refer to this document for the details of the creation procedure.

Click Finish to deploy your local application to Container Service for Kubernetes.

image.png

Recommended Posts

Porting Kubernetes to container services using Cloud Toolkit.x
Introduction to Docker / Kubernetes Practical Container Development