All Products
Search
Document Center

Container Service for Kubernetes:Deploy a web application by using NGINX

Last Updated:Aug 25, 2023

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.

Important

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

Step 1: Deploy an NGINX application

Use the console

Step 1: Create an NGINX application and expose the application by using a Service

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, click the name of the cluster that you want to manage and choose Workloads > Deployments in the left-side navigation pane.

  3. On the Deployments page, click Create from Image in the upper-right corner.

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

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

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

  7. Click Create. Then, click View Details.

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

Note

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

  1. A kubectl client is connected to the ACK Serverless cluster. For more information, see Connect to an ACK cluster by using kubectl.

  2. 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"
  3. 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
  4. 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
  5. 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.

E0BAA015-8D49-48B7-B379-046ABA6BAB27.png

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:

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, choose More > Delete in the Actions column of the cluster.

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