All Products
Search
Document Center

Container Service for Kubernetes:Use a YAML template to deploy an NGINX application, use an Ingress to expose the NGINX application, and use Simple Log Service to collect and view logs

Last Updated:Nov 15, 2023

The Container Service for Kubernetes (ACK) console provides extensive features to help you manage and maintain clusters and applications. This topic describes how to deploy an NGINX application, configure an Ingress, and query log data in the ACK console.

Prerequisites

Step 1: Deploy an NGINX application

  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 YAML in the upper-right corner. Then, configure the parameters and click Create.

    • In the upper part of the page, set Namespace to default and Sample Template to Resource - basic Deployment.

    • Configure log collection. For more information about how to configure log collection parameters, see Collect log data from containers by using Simple Log Service.

      Add the following content to the spec field in the template.

      Note

      In the following sample code, aliyun_logs_log-nginxvarlog specifies that the name of the created Logstore is log-nginxvarlog. The value stdout specifies that the Logstore collects standard outputs of containers from the specified path.

      env:
      - name: aliyun_logs_log-nginxvarlog
        value: stdout
      配置日志采集
    • Change the version of the image that is used to deploy the NGINX application to 1.9.1.设置镜像

    After the NGINX application is created, you can click the image.pngicon in the upper-left corner of the page to view the application on the Deployments page.

Step 2: Create a Service and release the NGINX application

  1. In the left-side navigation pane of the details page, choose Network > Services

  2. On the Services page, click Create in the upper-right corner. In the Create Service dialog box, configure the parameters and click Create.

    Parameter

    Description

    Example

    Name

    Enter a name for the Service.

    nginxservice

    Type

    Multiple types are supported. In this case, set Type to Cluster IP.

    Cluster IP

    Backend

    Select nginx-deployment-basic from the drop-down list.

    nginx-deployment-basic

    Port Mapping

    Enter a name for the port. Set Service Port to 80, Container Port to 80, and Protocol to TCP.

    • test

    • 80

    • 80

    • TCP

Step 3: Create an NGINX Ingress to expose the NGINX application

  1. In the left-side navigation pane of the details page, choose Network > Ingresses.

  2. On the Ingresses page, click Create Ingress.

  3. Set Gateway Type to Nginx, configure the Ingress as described in the following section, and then click OK.

    The following section describes only the key parameters. For more information about how to configure other parameters, see Create an NGINX Ingress.

    • Name: Enter a name for the Ingress. The name is set to ingress-demo in this example.

    • Rules: Leave the Domain Name parameter empty, set Path to /, use the default match rule, use the nginxservice Service that you created in Step 2, and set Port to 80.

    Wait about 1 minute. The Ingress IP address is displayed in the Endpoint column of ingress-demo on the Ingresses page Enter the Ingress IP address into the address bar of the browser. If the following page is displayed, the Ingress is created.Nginx

Step 4: View the access log of the NGINX application

After the NGINX application is released and exposed, the NGINX Ingress controller allows you to stream all HTTP request log data to standard outputs. You can view the access log of the NGINX application and monitor the real-time status of the NGINX Ingress in the Simple Log Service console.

  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 click Cluster Information in the left-side navigation pane.

  3. On the page that appears, click the Cluster Resources tab, find Log Service Project, and then click its ID to check the Logstore.

  4. On the Logstores tab, select log-nginxvarlog to view the latest access log of the application.

    日志