All Products
Search
Document Center

Container Service for Kubernetes:Use ACK to quickly deploy a magic cube game application

Last Updated:Jun 20, 2025

Container Service for Kubernetes (ACK) clusters enable you to manage containerized applications running on the cloud in a convenient and efficient manner. This topic describes how to quickly deploy, expose, and monitor a containerized demo application (a magic cube game) in an ACK cluster by using the cluster console or kubectl.

Overview

2024-12-12_16-00-46 (1)In this topic, an application named ack-cube is deployed to run as an online magic cube game. This application is deployed in an ACK Pro cluster using a container image. After completing the steps in this topic, you will have a magic cube game application deployed in an ACK Pro cluster.

  1. Activate ACK, grant permissions to ACK, and create an ACK cluster.

  2. Deploy a magic cube game application using one of two methods: the console or kubectl.

  3. Use the external IP address of the ack-cube Service to access the application over the Internet.

1. Quickly create a cluster

Important

If this is the first time you use ACK, you must activate ACK and grant permissions to ACK. Then, create an ACK cluster and deploy a magic cube game application in the cluster. To ensure that you can use ACK and its features normally, you must first activate ACK and the required cloud services and assign the required default roles to ACK. We recommend that you follow the official guide to configure cluster settings and complete authorization. For more information, see Quickly create an ACK managed cluster. For more information about the billing of ACK clusters and the cloud resources used by ACK clusters, see Billing.

When you create an ACK managed cluster, you can enable the intelligent managed mode. After this mode is enabled, you need to perform only simple planning configurations to create an ACK cluster that complies with best practices with one click. The cluster automatically creates an intelligent managed node pool, and the lifecycle of the nodes in the pool is managed and maintained by ACK. For more information, see Create an ACK managed cluster (intelligent managed mode).

Note

If you need to customize the cluster configuration in detail, you can refer to the complete process in Create an ACK managed cluster to create a cluster.

  1. Log on to the ACK console. On the Clusters page, click Create Cluster.image

  2. In the upper part of the page, click the ACK Managed Cluster tab, click Enable Intelligent Managed. If you need to access the cluster over the Internet, select Expose API Server With EIP. Then, click Confirm Configurations, check the selected configurations, and click Create Cluster.

    image

2. Deploy an application

You can deploy the magic cube game by manually configuring application parameters through the console or kubectl.

  • Console deployment: Deploy and expose an application, and access the application through the console.

  • kubectl deployment: Connect to the cluster using kubectl (CloudShell, kubectl client, or Workbench), deploy and expose an application, and access the application.

Important

The example in this topic uses a public image. To pull public images, your cluster or nodes must have Internet access:

  • Enable Internet access for clusters (recommended): Create an Internet NAT gateway for the VPC where the cluster is located to provide Internet access for all resources in the cluster.

  • Assign static public IP addresses to nodes: Nodes with public IP addresses can pull public images. However, you need to assign public IP addresses to each node where workloads are deployed.

Console deployment

2.1 Deploy and expose an application

This step shows how to deploy a Deployment and how to expose the application to the Internet. The application is a magic cube game. For more information about the parameters used to create a Deployment, see Create a stateless application by using a Deployment.

  1. On the Clusters page, click the name of the ack-demo cluster.

  2. In the left-side navigation pane of the details page, choose Workloads > Deployments.

  3. In the upper-right corner of the Deployments page, click Create from Image.

  4. On the Basic Information wizard page, set the application name to ack-cube.

  5. Click Next. On the Container wizard page, set container parameters.

    image

    Parameter

    Description

    Example

    Image Name

    Enter an image name.

    Enter registry.cn-hangzhou.aliyuncs.com/acr-toolkit/ack-cube:1.0.

    Resource Limit

    Specify the resource limits of the application. This prevents the application from occupying excessive amounts of resources.

    In this example, 1 vCore and 1,024 MiB of memory are specified. Ephemeral Storage is left empty.

    Required Resources

    Specify the amount of resources that are reserved for the application. This prevents application unavailability caused by insufficient resources.

    In this example, 0.5 vCores and 512 MiB of memory are specified. Ephemeral Storage is left empty.

    Port

    Configure container ports.

    • Name: ack-cube.

    • Container Port: 80.

    • Protocol: TCP.

  6. Click Next. On the Advanced wizard page, click Create in the Service section. In the Create Service dialog box, set Service parameters to expose the ack-cube application. After you complete the Service configuration, click OK.image

    Parameter

    Description

    Example

    Name

    Enter a name for the Service.

    ack-cube-svc

    Type

    The type of Service. This parameter specifies how the Service is accessed. Choose Server Load Balancer > Classic Load Balancer (CLB) > Create Resource. You can use default settings for CLB resources in the test environment.

    In this example, the default settings are used.

    Port

    Specify a Service Port and a Container Port. The Container Port must be the same as the one that is exposed in the backend pod.

    • Service Port: 80.

    • Container Port: 80.

    • Protocol: TCP.

  7. After you complete the workload configuration, click Create. After the application is created, you are redirected to the Complete wizard page. You can find the resource objects included in the application and click View Details to view application details.succeed

2.2 Access the application

This step shows how to access the application by using the Service.

Log on to the ACK console. On the Clusters page, click the name of the cluster. In the left-side navigation pane, choose Workloads > Deployments. Find the application named ack-cube in the default namespace. Click the Access Method tab, find the newly created Service (ack-cube-svc), and click the link in the External Endpoint column to access the magic cube game.image

Kubectl deployment

2.1 Connect to the cluster

You can use kubectl, Workbench, or Cloud Shell to connect to the cluster.

CloudShell

When you start Cloud Shell, Cloud Shell automatically creates a Linux VM for you. You can use the Linux VM free of charge. The VM is pre-installed with cloud management tools and system tools. You can use these tools together with Web IDE provided by Cloud Shell to manage cloud resources. This step shows how to connect to the ACK cluster by using Cloud Shell. For more information, see Use kubectl on Workbench or Cloud Shell to connect to ACK clusters.

Log on to the ACK console. In the left-side navigation pane of the console, click Clusters. On the Cluster Information page, choose Basic Information > Open Cloud Shell.

It requires a few seconds to start Cloud Shell. After Cloud Shell is started, you can run kubectl commands on the Cloud Shell interface to manage the cluster and applications in the cluster.

Workbench

You can use Workbench, which is a remote connection tool provided by Alibaba Cloud that allows you to connect to ACK clusters from a browser without the need to install additional software. For more information, see Connect to an instance by using Workbench.

Log on to the ACK console. In the left-side navigation pane of the console, click Clusters. On the Cluster Information page, choose Basic Information > Manage Clusters Using Workbench.

It requires a few seconds to start Workbench. After Workbench is started, you can follow the page instructions to run kubectl commands on the Workbench interface to manage the cluster and applications.

Kubectl client

If you want to connect to the cluster over the Internet, you can install a kubectl client on your on-premises machine. This step shows how to connect to the ACK cluster by using a kubectl client. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.

  1. Install and set up a kubectl client. For more information, see Install and set up kubectl.

  2. Log on to the ACK console. In the left-side navigation pane of the console, click Clusters. On the Clusters page, find the ack-demo cluster and click its name. On the Cluster Information page, click the Connection Information tab. Click Copy on the Public Access tab to copy the credentials used to access the cluster over the Internet. Paste the credentials to the config file in the $HOME/.kube directory of your on-premises machine, save the file, and then exit.

    Note

    If the .kube folder and the config file do not exist in the $HOME/ directory of your on-premises machine, you must manually create the folder and file.

  3. Run a kubectl command to verify the network connectivity of the cluster.

    Run the following command to query the namespaces of the cluster:

    kubectl get namespace

    Expected output:

    NAME              STATUS   AGE
    arms-prom         Active   4h39m
    default           Active   4h39m
    kube-node-lease   Active   4h39m
    kube-public       Active   4h39m
    kube-system       Active   4h39m

2.2 Deploy and expose an application

This step shows how to use kubectl to deploy a Deployment and how to use a LoadBalancer Service to expose the application. For more information about how to expose an application, see Use an automatically created SLB instance to expose an application.

  1. Use the following YAML template to create an ack-cube.yaml file:

    apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
    kind: Deployment
    metadata:
      name: ack-cube # The name of the application.
      labels:
        app: ack-cube
    spec:
      replicas: 2 # The number of replicated pods.
      selector:
        matchLabels:
          app: ack-cube  # You must specify the same value for the selector of the Service that is used to expose the application.
      template:
        metadata:
          labels:
            app: ack-cube
        spec:
          containers:
          - name: ack-cube
            image: registry.cn-hangzhou.aliyuncs.com/acr-toolkit/ack-cube:1.0 # Replace with the address of the image that you want to use in the <image_name:tags> format.
            ports:
            - containerPort: 80 # The container port that you want to expose.
            resources:
              limits: # The resource limits.
                cpu: '1'
                memory: 1Gi
              requests: # The resource requests.
                cpu: 500m
                memory: 512Mi        
  2. Run the following command to deploy the ack-cube demo application:

    kubectl apply -f ack-cube.yaml
  3. Run the following command to verify that the application is running properly:

    kubectl get deployment ack-cube

    Expected output:

    NAME       READY   UP-TO-DATE   AVAILABLE   AGE
    ack-cube   2/2     2            2           96s
  4. Use the following YAML template to create an ack-cube-svc.yaml file. Set selector to the value of matchLabels in the ack-cube.yaml file. In this example, the value is app: ack-cube. This adds the application to the backend of the Service.

    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app: ack-cube
      name: ack-cube-svc
      namespace: default
    spec:
      ports:
      - port: 80
        protocol: TCP
        targetPort: 80
      selector:
        app: ack-cube # You must specify the value of the matchLabels parameter in the YAML file that is used to create the Deployment.
      type: LoadBalancer
  5. Run the following command to create a Service named ack-cube-svc and use the Service to expose the application:

    ACK automatically creates an Internet-facing SLB instance and associates the instance with the Service.

    kubectl apply -f ack-cube-svc.yaml
  6. Run the following command to verify that the LoadBalancer Service is created:

    The application that you created is exposed by using the IP address in the EXTERNAL-IP column in the output.

    kubectl get svc ack-cube-svc

    Expected output:

    NAME           TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)        AGE
    ack-cube-svc   LoadBalancer   172.16.72.161   47.94.xx.xx   80:31547/TCP   32s
  7. Enter the EXTERNAL-IP address (47.94.xx.xx) in the address bar of your browser to access the magic cube game application.

3. (Optional) Release resources

The billable items of ACK Pro clusters include cluster management and cloud resources. ACK charges the cluster management fee. The corresponding cloud services charge the cloud resource fee.

If you no longer need the cluster, you can delete it. Log on to the ACK console. On the Clusters page, choose More > Delete in the Actions column of the cluster. On the Delete Cluster And Associated Resources page, Select The Resources That You Want To Delete and click Delete. For more information about how to delete an ACK cluster, see Delete a cluster.

Important

Intelligent managed clusters have deletion protection enabled by default. Before you delete a cluster, you must disable deletion protection for the cluster.

image

References

  • If the resource requests of your business are unpredictable or periodically change, we recommend that you enable auto scaling for your business. For example, you can enable auto scaling for web applications, gaming services, or online education applications. The auto scaling feature includes workload scaling and compute resource scaling. For more information, see Auto scaling overview.

  • In addition to exposing applications through Services, you can use Ingresses to enable application traffic routing at Layer 7. For more information, see Ingress management.

  • In addition to monitoring container performance, you can monitor the cluster infrastructure, application performance, and operations on your workloads. The observability capability of Kubernetes includes monitoring and logging. Monitoring allows developers to keep track of system operations. Logging facilitates diagnostics and troubleshooting. For more information, see Observability system overview.