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
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.
.
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.
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.
Go to the logon page of the Alibaba Cloud console.
Enter the sub-user account and click Next.
Enter the sub-user password and click Log on.
After you successfully log on to the console, the following page is displayed.
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.
Select US (Silicon Valley) and click Create Elastic Container Group.
Select a region and configure a network, as shown in the following figure.
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
To add the second container, click Add Container. Configure the container, as shown in the following figure.
Click Other Settings.
Set the EIP. Three EIPs have been created before the experiment, and the user can choose one at will.
Then, click Confirm Order.
Wait for about one minute. Then, you can see that the container is running properly.as shown in the following figure.
Select the container group to view its details.
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.
In the left-side navigation pane, choose Network & Security > Security Groups. On the Security Groups page, click Add Rules in the Actions column.
On the page that appears, click Add Rule.
Configure parameters and click Save, as shown in the following figure.
Copy the EIP of the container group.
Enter the following link in the browser. Please note that you must replace YOUR-EIP with your own.
YOUR-EIP:5000/json
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
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
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.
On the File System List page, select US (Silicon Valley) and click Create File System.
If the following error occurs, it doesn’t matter, it may be caused by the network. In fact, it has been created successfully.
After the file system is created, click Manage in the Actions column.
The mount target is successfully added, as shown in the following figure.
Return to the ECI console and click Create Elastic Container Group.
Set the network and security group first.
Set Volume and select the created NAS file system.
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.
Configure the second container named flask and mount the created volume to the /mnt directory of the container.
Click Other Settings.
Click Confirm Order, as shown in the following figure.
Wait for about one minute. Then, you can see that the container group has started properly.
Log on to the flask container first, as shown in the following figure.
Run the following command. You can see that the NAS file system has been successfully mounted in the/mnt directory.
df -h
Run the following command to create a file named flag.txt in the/mnt directory.
touch /mnt/flag.txt
Then, log on to the nginx container and run the following command.
ls /mnt
<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.
Click Create Cluster, as shown in the following figure.
On the Serverless Kubernetes (Preview) tab page, configure the parameters, as shown in the following figure. Then, click Create.
Now, the cluster begins to be created. Click Back.
Wait for about three minute. Then, you can see that the cluster has been successfully created.
Create a Deployment object, as shown in the following figure.
Configure parameters and click Next, as shown in the following figure.
Configure parameters and click Next, as shown in the following figure.
Click Create to create a service, as shown in the following figure.
Configure parameters and click Create, as shown in the following figure.
Click Create to complete the creation.
You can see that the service has been successfully created. Click View Details.
You can see that Pods have been started successfully.
Click the endpoint of the service that you just created, as shown in the following figure.
You can now successfully access nginx.
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.
<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.
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.