You do not need to create or manage nodes in Container Service for Kubernetes (ACK) Serverless clusters. This frees you from maintaining cloud resources for your applications and allows you to focus on your business development instead of managing the underlying infrastructure. This topic describes how to deploy a web application by using NGINX in an ACK Serverless cluster.
The resources that you create incur about USD 0.05 for 30 minutes. After you complete the steps in this topic, you can release the resources that you created.
Prerequisites
An ACK Serverless cluster is created. For more information, see Create an ACK Serverless cluster.
An elastic IP address (EIP) is associated with the API server of the cluster. For more information, see Control public access to the API server of a cluster.
An Internet NAT gateway is created in the virtual private cloud (VPC) in which the cluster resides and SNAT entries are configured. For more information, see Use the SNAT feature of an Internet NAT gateway to access the Internet.
Step 1: Deploy an NGINX application
Use the console
Step 1: Create an NGINX application and expose the application by using a Service
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, click the name of the cluster that you want to manage and choose in the left-side navigation pane.
On the Deployments page, click Create from Image in the upper-right corner.
On the Basic Information wizard page, set the parameters as described in the following table, use default settings for other parameters, and then click Next.
Parameter
Example
Name
nginx-deploy
Replicas
1
On the Container wizard page, set the parameters as described in the following table, use the default settings for other parameters, and then click Next.
Parameter
Example
Image Name
nginx
Image Version
alpine
Required Resources
CPU: 1 Core
Memory: 2 GB
Port
Name: example-port
Container Port: 80
Protocol: TCP
On the Advanced wizard page, create a Service. In the Create Service dialog box, set the parameters in the Port Mapping section as described in the following table. Then, click Create.
Parameter
Example
Name
example-map
Service Port
80
Container Port
80
Protocol
TCP
Click Create. Then, click View Details.
On the Pods tab, wait until the status of the pod changes to Running. Click the Access Method tab and record the external endpoint (public IP address) of the nginx-deploy-svc Service.
Use kubectl
You can use kubectl on your on-premises machine or in Cloud Shell to perform the following operations. If you use kubectl in Cloud Shell, you do not need to configure the config file.
Step 1: Create an NGINX application and expose the application by using a Service
A kubectl client is connected to the ACK Serverless cluster. For more information, see Connect to an ACK cluster by using kubectl.
Create an nginx.yaml file with the following code block:
apiVersion: v1 kind: Service metadata: name: nginx-deploy-svc spec: ports: - port: 80 protocol: TCP selector: app: nginx type: LoadBalancer --- apiVersion: apps/v1 #Specify the API version based on the Kubernetes version of the cluster. kind: Deployment metadata: name: nginx-deploy labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:alpine ports: - containerPort: 80 resources: requests: cpu: "1" memory: "2Gi"
Run the following command to deploy an application by using the nginx.yaml file in the cluster:
kubectl apply -f nginx.yaml
Expected output:
service/nginx-service created deployment.apps/nginx-deploy created
Run the following command to view the details of the application:
kubectl get deploy
Expected output:
NAME READY UP-TO-DATE AVAILABLE AGE nginx-deploy 1/1 1 1 9m32s
Run the following command to view the details of the Service and record the public IP address (EXTERNAL-IP) of the nginx-service Service:
kubectl get svc
Expected output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 172.XX.X.X <none> 443/TCP 10d nginx-service LoadBalancer 172.19.X.XXX 47.57.XX.XX 80:32278/TCP 39s
Step 2: Test access to the NGINX application
Enter the public IP address of the nginx-service Service in the address bar of a browser and press Enter.
If the following page is returned, the NGINX application and the nginx-service Service run as expected.
What to do next
Configure auto scaling policies for the application. For more information, see Configure auto scaling policies for a cluster.
If you do not want to configure auto scaling, you can perform the following steps to release the resources that you created:
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, choose
in the Actions column of the cluster.In the Delete Cluster dialog box, select Delete ALB Instances Created by the Cluster, Delete Alibaba Cloud DNS PrivateZone instances Created by the Cluster, and I understand the above information and want to delete the specified cluster, and then click OK.