Container Service for Kubernetes (ACK) clusters allow you to manage containerized applications that run on the cloud in a convenient and efficient manner. This topic describes how to use the ACK console to quickly deploy, expose, and monitor a magic cube game application in an ACK cluster.
Overview
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 by using a container image. After you perform the following steps in this topic, a magic cube game application is deployed in an ACK Pro cluster.
Activate ACK, grant permissions to ACK, and create an ACK cluster.
Deploy a magic cube game application by using the ACK console, Resource Orchestration Service (ROS), or kubectl.
Use the external IP address of the ack-cube Service to access the application over the Internet.
Procedure
Select one of the following methods to deploy a magic cube game application:
Use the ACK console: You can quickly create a cluster, deploy and expose an application, and access the application in the ACK console.
Use ROS: You can use ROS to deploy the cluster environment and access the application with a few clicks.
Use kubectl: You can use kubectl to quickly create a cluster, connect to the cluster, deploy and expose an application, and access the cluster. You can also use Cloud Shell or Workbench to connect to the cluster.
ACK console
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.
1. Quickly create a cluster
To ensure that you can use ACK and the features of ACK as normal, 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.
If you want to quickly create an ACK cluster, you can use default settings for the cluster parameters. If you want to create a cluster in the production environment, refer to Create an ACK managed cluster.
Log on to the ACK console. On the Clusters page, click Create Cluster.
In the upper part of the page, click the ACK Managed Cluster tab. Select Professional for Cluster Specification. If you need to access the cluster over the Internet, select Expose API server with EIP. Then, click Next:Node Pool Configurations in the lower-right corner of the page.
In the Instance Type section, select an instance type that provides 4 vCores and 8 GiB of memory, such as ecs.c6.xlarge, which belongs to the c6 compute-optimized instance family. Then, click Next:Component Configurations in the lower-right corner of the page.
Select ACK Cluster Monitoring Basic Edition for Monitor container. ACK Cluster Monitoring Basic Edition is free of charge. Then, click Next:Confirm Order in the lower-right corner of the page.
Click Create Cluster in the lower-right corner of the page.
2. Deploy and expose an application
This step shows how to deploy a stateless application by using 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.
On the Clusters page, click the name of the ack-demo cluster.
In the left-side navigation pane of the details page, choose .
In the upper-right corner of the Deployments page, click Create from Image.
On the Basic Information wizard page, set the application name to ack-cube.
Click Next. On the Container wizard page, set container parameters.
Parameter
Description
Example
Image Name
Enter an image name.
In this example,
registry.cn-hangzhou.aliyuncs.com/acr-toolkit/ack-cube:1.0
is specified.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 Mapping
Configure container ports.
In this example, TCP port 80 is configured and named ack-cube.
Click Next. On the Advanced wizard page, click Create to the right of Services.
In the Create Service dialog box, set Service parameters and click Create. This creates a Service to expose the ack-cube application.
Parameter
Description
Example
Name
Enter a name for the Service.
ack-cube-svc
Service Type
The type of Service. This parameter specifies how the Service is accessed. Choose SLB > CLB > Create Resource. You can use default settings for Classic Load Balancer (CLB) resources in the test environment.
In this example, the default settings are used.
Port Mapping
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.
In this example, the Service port and container port are both set to 80.
In the lower-right corner of the Advanced wizard page, 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.
3. 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 that you created. In the left-side navigation pane, choose Click the ack-cube application in the default namespace. Click the Access Method tab. Select the ack-cube-svc Service and click the hyperlink in the External Endpoint column to start the magic cube game. .
ROS
ROS allows you to use templates to quickly deploy an ACK cluster and a magic cube game application in the cluster within 10 minutes. A public IP address is allocated to the SLB instance created for the application. You can use your browser to access this IP address to start the magic cube game.
To ensure that you can use ACK and the features of ACK as normal, 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.
Click the quick configuration link to go to the ROS console. The Create Stack page appears. In the upper part of the page, select the region where you want to create a stack. In this example, China (Hohhot) is selected. Set other parameters and click Create.
Parameter
Description
Example
Stack Name
You can enter a custom name.
stack_2023-06-12_cBesTX8FB
Cluster Name
You can enter a custom name.
NoteYou cannot specify the name of an existing cluster.
ack-demo-cube
VSwitch Available Zone
Select a zone.
Zone A
Instance Type
Select an instance family.
You can filter instance types by the number of vCores and memory size. You can also set the Architecture and Type parameters to filter instance types.
General-purpose Type g6
Worker System Disk Category
Select a system disk type for nodes.
The available disk types vary based on the instance type that you select. For more information about the disk types supported by different instance types, see Overview of instance families. Disk types not displayed in the drop-down list are not supported by the instance types that you select.
cloud_essd
Instance Password
Enter a password that is used to log on to the nodes.
Enter a password.
If Created is displayed in the Status parameter on the Stack Information tab, the stack is created.
If Created is not displayed in the Status parameter on the Stack Information tab, the stack is not created. You can click Quick Diagnostics to view the diagnostic details.
Test access to the application.
Wait until Created is displayed in the Status parameter on the Stack Information tab. Then, click the Outputs tab on the right of the Stack Information tab. Click the hyperlink next to CubeAddress to start the magic cube game.
kubectl
1. Quickly create a cluster
To ensure that you can use ACK and the features of ACK as normal, 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.
If you want to quickly create an ACK cluster, you can use default settings for the cluster parameters. If you want to create a cluster in the production environment, refer to Create an ACK managed cluster.
Log on to the ACK console. On the Clusters page, click Create Cluster.
In the upper part of the page, click the ACK Managed Cluster tab. Select Professional for Cluster Specification. If you need to access the cluster over the Internet, select Expose API server with EIP. Then, click Next:Node Pool Configurations in the lower-right corner of the page.
In the Instance Type section, select an instance type that provides 4 vCores and 8 GiB of memory, such as ecs.c6.xlarge, which belongs to the c6 compute-optimized instance family. Then, click Next:Component Configurations in the lower-right corner of the page.
Select ACK Cluster Monitoring Basic Edition for Monitor container. ACK Cluster Monitoring Basic Edition is free of charge. Then, click Next:Confirm Order in the lower-right corner of the page.
Click Create Cluster in the lower-right corner of the page.
2. Connect to the cluster
You can use kubectl, Workbench, or Cloud Shell to connect to the cluster.
CloudShell
If you want to connect to the cluster over the Internet but do not want to configure a kubectl client, you can use Cloud Shell, which is a web-based command-line tool provided by Alibaba Cloud. 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 Cloud Shell to manage ACK clusters.
Log on to the ACK console. In the left-side navigation pane, click Clusters. Then, click the name of the cluster you created. On the Cluster Information page, choose .
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.
kubectl
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.
Install and set up a kubectl client. For more information, see Install and set up kubectl.
Log on to the ACK console. In the left-side navigation pane, 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.
NoteIf 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.
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
Workbench
If you do not need to connect to the cluster over the Internet, 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 through Workbench.
Log on to the ACK console. In the left-side navigation pane, click Clusters. Then, click the name of the cluster you created. On the Cluster Information page, choose .
It requires a few seconds to start Workbench. After Workbench is started, you can run kubectl commands on the Workbench interface to manage the cluster and applications in the cluster.
3. Deploy and expose an application
This step shows how to use kubectl to deploy a stateless application by creating 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.
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 pod replicas. 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 the value 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
Run the following command to deploy the ack-cube application:
kubectl apply -f ack-cube.yaml
Run the following command to query the status of the application:
kubectl get deployment ack-cube
Expected output:
NAME READY UP-TO-DATE AVAILABLE AGE ack-cube 2/2 2 2 96s
Use the following YAML template to create an ack-cube-svc.yaml file. Set
selector
to the value ofmatchLabels
in the ack-cube.yaml file. In this example, the value isapp: 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
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
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
(Optional) Release resources
The billable items of ACK Pro clusters include cluster management and cloud resources. The cluster management fee is charged by ACK. The cloud resource fee is charged by the corresponding cloud services.
If you no longer need the cluster, you can delete the cluster. Log on to the ACK console. On the Clusters page, choose More > Delete in the Actions column of the cluster to delete 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.
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 Create an NGINX Ingress.
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.