arrow

Use ECI And Serverless Kubernetes

1. Experiment

1.1 Knowledge points

This experiment mainly uses Alibaba Cloud Elastic Container Instance (ECI) to describe its basic usage. ECI is an agile and secure serverless container instance service. It allows you to run containers without managing servers. With it, you only need to provide container images to get started and pay for the resources that have been consumed by the containers.

In addition, a serverless Kubernetes cluster is created by using Container Service (CS) at the end of the experiment. Serverless Kubernetes clusters are based on the Alibaba Cloud elastic computing architecture and are fully compatible with the Kuberentes API, combining the security, elasticity, and Kubernetes ecosystem of virtualized resources.

1.2 Experiment process

  • Access cross-container data.
  • Add a volume.
  • Create a serverless Kubernetes cluster.

1.3 Scene architecture diagram

image desc

1.4 Cloud resources required

  • CS
  • Simple Log Service (SLS)
  • ECI
  • NAS

1.5 Prerequisites

  • Before starting the experiment, confirm that the previous experiment has been closed normally and exited.

2. Start the experiment environment

Click Start Lab in the upper-right corner of the page to start the experiment.

image desc.

After the experiment environment is successfully started, the system has deployed the resources required by this experiment in the background, including the ECS instance, RDS instance, Server Load Balancer instance, and OSS bucket. An account consisting of the username and password for logging on to the Alibaba Cloud console is also provided.

image desc

After the experiment environment is started and related resources are deployed, the experiment countdown starts. You have two hours to perform experimental operations. After the countdown ends, the experiment stops and related resources are released. During the experiment, pay attention to the remaining time and arrange your time wisely. Then, use the username and password provided by the system to log on to the Alibaba Cloud console and view related resources.

openCole

Go to the logon page of the Alibaba Cloud console.

image desc

Enter the sub-user account and click Next.

image desc

Enter the sub-user password and click Log on.

image desc

After you successfully log on to the console, the following page is displayed.

image desc

3. Access cross-container data

First, create an ECI container group that contains two containers named flask and redis. The flask container creates and obtains data that is in the redis container based on the frontend request.

Choose Products > Elastic Container Instance.

image desc

Select US (Silicon Valley) and click Create Elastic Container Group.

image desc

Select a region and configure a network, as shown in the following figure.

image desc

Set Container Group Name to labex-group, as shown in the following figure. Set the name of the first container to flask and select the image address as follows.

registry-intl.us-west-1.aliyuncs.com/labex/flask

image desc

image desc

To add the second container, click Add Container. Configure the container, as shown in the following figure.

image desc

Click Other Settings.

image desc

Set the EIP. Three EIPs have been created before the experiment, and the user can choose one at will.

image desc

Then, click Confirm Order.

image desc

image desc

Wait for about one minute. Then, you can see that the container is running properly.as shown in the following figure.

image desc

Select the container group to view its details.

image desc

image desc

Before testing the service in the container group, modify security group rules.

To do this, choose Products > Elastic Compute Service to go to the ECS console.

image desc

In the left-side navigation pane, choose Network & Security > Security Groups. On the Security Groups page, click Add Rules in the Actions column.

image desc

On the page that appears, click Add Rule.

image desc

Configure parameters and click Save, as shown in the following figure.

image desc

Copy the EIP of the container group.

image desc

Enter the following link in the browser. Please note that you must replace YOUR-EIP with your own.

YOUR-EIP:5000/json

image desc

In the preceding figure, you can see that the container group has been successfully started. Enter the following links in the browser one by one. Please note that you must replace YOUR-EIP with your own.

YOUR-EIP:5000/setKey?key=Country&value=China
YOUR-EIP:5000/setKey?key=Province&value=Beijing
YOUR-EIP:5000/setKey?key=district&value=HaiDian

image desc

image desc

image desc

Enter the following link to check whether the keys that you just set have taken effect. Please note that you must replace YOUR-EIP with your own.

YOUR-EIP:5000/getValue?key=Country
YOUR-EIP:5000/getAll

image desc

image desc

The preceding figure shows that the flask container can normally access the content in the redis container, because containers in the same container group share the same IP address.

4. Add a volume

Choose Products > NAS to go to the NAS console and create a file system.

image desc

On the File System List page, select US (Silicon Valley) and click Create File System.

image desc

image desc

image desc

image desc

image desc

If the following error occurs, it doesn’t matter, it may be caused by the network. In fact, it has been created successfully.

image desc

After the file system is created, click Manage in the Actions column.

image desc

The mount target is successfully added, as shown in the following figure.

image desc

Return to the ECI console and click Create Elastic Container Group.

image desc

Set the network and security group first.

image desc

Set Volume and select the created NAS file system.

image desc

Set the container group name and configure the first container named nginx, as shown in the following figure. Mount the created volume to the /mnt directory of the container.

image desc

image desc

Configure the second container named flask and mount the created volume to the /mnt directory of the container.

image desc

image desc

Click Other Settings.

image desc

image desc

Click Confirm Order, as shown in the following figure.

image desc

Wait for about one minute. Then, you can see that the container group has started properly.

image desc

Log on to the flask container first, as shown in the following figure.

image desc

image desc

Run the following command. You can see that the NAS file system has been successfully mounted in the/mnt directory.

df -h

image desc

Run the following command to create a file named flag.txt in the/mnt directory.

touch /mnt/flag.txt

image desc

Then, log on to the nginx container and run the following command.

ls /mnt

image desc

<font color='red'>The user can cut off the above result picture when doing the experiment and send it to the teacher, indicating that the part of the current chapter has been completed.</font>

You also can see the flag.txt file that was created in the flask container.

So far, you have tested the directory sharing of different containers in the same container group.

5. Create a serverless Kubernetes cluster

Refer to the figure below to go to the container service console.

image desc

Click Create Cluster, as shown in the following figure.

image desc

On the Serverless Kubernetes (Preview) tab page, configure the parameters, as shown in the following figure. Then, click Create.

image desc

image desc

image desc

Now, the cluster begins to be created. Click Back.

image desc

Wait for about three minute. Then, you can see that the cluster has been successfully created.

image desc

Create a Deployment object, as shown in the following figure.

image desc

image desc

Configure parameters and click Next, as shown in the following figure.

image desc

Configure parameters and click Next, as shown in the following figure.

image desc

Click Create to create a service, as shown in the following figure.

image desc

Configure parameters and click Create, as shown in the following figure.

image desc

Click Create to complete the creation.

image desc

You can see that the service has been successfully created. Click View Details.

image desc

You can see that Pods have been started successfully.

image desc

Click the endpoint of the service that you just created, as shown in the following figure.

image desc

You can now successfully access nginx.

image desc

Return to the ECI console. You can see that two new container groups are added, which are exactly the pods created by the serverless Kubernetes cluster.

image desc

<font color='red'>Users can cut off the above result picture when they are doing the experiment and send it to the teacher, indicating that the current experiment has been completed.</font>

Reminder:
Before you leave this lab, remember to log off from your Alibaba RAM account before you click the stop button of your lab. Otherwise, you will encounter some issues when opening a new lab session in the same browser.

image descimage desc

6. Experiment summary

This experiment mainly describes how to use ECI and Serverless Kubernetes. Serverless Kubernetes uses ECI to provide pods, which is the Kubernetes core object, with elasticity. It provides powerful Kubernetes management capabilities and supports the Deployment, StatefulSet, Job, and CroJob workloads. You can abstract the application and component architectures and relieve yourself from server management. For example, you do not have to create machines, manage, maintain, or upgrade the infrastructure, or make capacity plans. Instead, you only need to focus on the applications. Serverless Kubernetes supports auto scaling based on application types, and provides the finer-grained management of resource provision and consumption, which greatly reduces the use cost.