×
Community Blog Deploying an Application to Container Service for Kubernetes

Deploying an Application to Container Service for Kubernetes

In this article, we will show you how to deploy applications on Container Service for Kubernetes using Cloud Toolkit.

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.

1

About 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.

Develop an Application Locally

This article takes a Java servlet for printing "Hello World" on a Web page as an example to explain the deployment method.

2

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/

Install Plug-in

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.

Configure the Plug-in Preferences

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.)

3

Configure a Docker connection to package the project locally as an image.

Choose Top menu > Window > Preferences > Alibaba Cloud Toolkit > Docker

4

Deploy the Application

5

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:

Step 1

6

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.

Step 2

7

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.

Step 3

8

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.

9

0 0 0
Share on

Nick(倪超)

9 posts | 1 followers

You may also like

Comments

Nick(倪超)

9 posts | 1 followers

Related Products