Elastic Container Instance (ECI) is seamlessly integrated with Container Service for Kubernetes (ACK). You can use an ACK Serverless cluster or an ACK managed cluster to experience the container runtime capabilities of ECI. This topic demonstrates how to use ECI with an ACK Serverless cluster.
Before you begin
Before you start, you must activate the required services and grant the necessary permissions:
-
Activate Container Service for Kubernetes (ACK), grant the default roles, and activate related cloud products. For more information, see Create an ACK managed cluster.
-
Log on to the Elastic Container Instance console and follow the prompts to activate the ECI service.
Create an ACK Serverless cluster
The following steps describe only the basic settings for creating an ACK Serverless cluster. For production environments, configure parameters and install components based on your business needs. For more information, see Create a cluster.
-
Go to the cluster creation page.
-
Log on to the Container Service for Kubernetes (ACK) console.
-
In the navigation pane on the left, click Cluster.
-
In the upper-right corner of the Clusters page, click Create Kubernetes Cluster.
-
-
Click the ACK Serverless tab, configure the cluster settings, and then click Next: Component Configurations.
The following table describes the key parameters. Configure other parameters based on your requirements.
Parameter
Example
Description
Cluster Name
test
Enter a name for the cluster.
Region
China (Beijing)
Select the region where you want to create the cluster.
VPC
Create VPC
Specify the VPC for the cluster.
-
Create VPC: You must select a zone. The system then automatically creates a VPC, a vSwitch in the selected zone, a NAT gateway, and configures SNAT rules.
-
Select Existing VPC: Select an existing VPC and vSwitch.
Configure SNAT
Configure SNAT for VPC
Configure SNAT if your cluster requires public internet access.
-
If you select Create VPC, SNAT is automatically configured.
-
If you use an existing VPC, choose whether to configure SNAT based on your needs.
Service CIDR
172.21.0.0/20
Specify a Service CIDR block that does not overlap with the CIDR block of the VPC or the CIDR blocks of other Kubernetes clusters in the same VPC. This setting cannot be changed after the cluster is created. For more information, see Plan networks for ACK managed clusters.
Access to API Server
Expose API server with EIP
Choose whether to expose the API server by using an EIP. The API server provides HTTP REST APIs for creating, updating, deleting, and watching resource objects such as Pods and services.
-
If you enable this option, an EIP is created and associated with a Server Load Balancer (SLB) instance. This exposes the Kubernetes API server on port 6443 of the EIP. You can use a kubeconfig file to connect to and manage the cluster from the internet.
-
If you do not enable this option, an EIP is not created. You can use a kubeconfig file to connect to and manage the cluster only from within the VPC.
-
-
Configure the components and click Next: Confirm Configuration.
Configure components based on your needs. Using optional components may incur fees. For this tutorial, no additional components are required.
-
Review your settings, read and select the Terms of Service check box, and then click Create Cluster.
Return to the Clusters page. The cluster is ready when its status changes to Running.
Deploy to an ACK Serverless cluster
The following steps guide you through deploying an NGINX application to an ACK Serverless cluster.
-
On the Clusters page, find your ACK Serverless cluster and click its name.
-
Create a Deployment for the NGINX application.
-
In the navigation pane on the left, choose Workloads > Deployments.
-
In the upper-right corner, click Create from YAML.
-
Modify the YAML template as needed and click Create.
By default, the Resource-basic Deployment sample template is selected. The YAML in this template declares a Deployment that contains two Pods. Each Pod has the label app: nginx and runs an NGINX container.
NoteIn the sample template,
image: nginx:1.7.9specifies the NGINX 1.7.9 image to be pulled from Docker Hub. If your cluster does not have public internet access, it cannot pull this image. Replace it with an image from within your VPC, such asimage: registry-vpc.cn-beijing.aliyuncs.com/eci_open/nginx:1.14.2.apiVersion: apps/v1 # for versions before 1.0.0 use apps/v1beta1 kind: Deployment metadata: name: nginx-deployment-basic labels: app: nginx spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: # nodeSelector: # env: test-team containers: - name: nginx image: nginx:1.7.9 # replace it with your image and tag ports: - containerPort: 80 resources: limits: cpu: "500m" resources: limits: cpu: "500m" -
Verify the Deployment.
-
On the Deployments page, view the Deployment information.
The value
2/2in the Pods column indicates that both Pods in the Deployment are running. -
On the Deployments page, click the Deployment name to view its details.
On the Pods tab, you can see that the status of both Pods is Running. Click a Pod name to view its details.
-
Each Pod corresponds to an ECI instance. You can view the corresponding ECI instances on the Container Group page of the Elastic Container Instance console.
The status of the corresponding ECI instances is Running.
-
-
-
Create a service to expose the NGINX application.
-
In the navigation pane on the left, choose Network > Services.
-
In the upper-right corner, click Create Resources in YAML.
-
Copy the following YAML and click Create.
The following YAML creates a service of the LoadBalancer type. It exposes port 80 and routes traffic to the Pods that have the app: nginx label.
apiVersion: v1 kind: Service metadata: name: nginx-service spec: ports: - port: 80 protocol: TCP selector: app: nginx type: LoadBalancer -
Verify the service.
On the Services page, click the service name to view its details. The service is automatically associated with the Deployment created in the previous step. The backend endpoints are the two Pods from that Deployment.
The service type is LoadBalancer, and its External Endpoint is an IP address such as
47.94.xxx:80, which you can use to access the service from the internet. The endpoints table shows that both Pods are running on the virtual-kubelet node. This confirms that the application is running in serverless mode.
-
-
Access the NGINX application.
Enter the external endpoint's
IP address:portin your web browser to access the NGINX application.After successful access, your browser displays the default NGINX welcome page with the title Welcome to nginx!. This indicates that the NGINX application is deployed and running correctly.