Create a Containerized App on Alibaba Cloud Container Service for Kubernetes
Orchestrating and managing containerized application environments with virtual management tools, such as Kubernetes and Docker Swarm, allows developers to manage and monitor enterprise production and development environments made up of multiple of containerized applications that have been built directly into the Alibaba Cloud Container Service.
In this tutorial, we will show you how to build a Kubernetes application environment which runs on Alibaba Cloud’s Container Service for Kubernetes. Alibaba Cloud’s Container Service for Kubernetes is made up of a Virtual Private Cloud (VPC) containing clusters of Alibaba Cloud Elastic Compute Service (ECS) instances on which Kubernetes orchestrates and manages industry scale containerized environments.
Before you can run Kubernetes containerized application environments on Alibaba Cloud’s Container Service for Kubernetes, you need an Alibaba Cloud Container Service Kubernetes cluster.
What Is Alibaba Cloud’s Container Service?
Alibaba Cloud’s Container Service is a scalable and reliable, high-performance, container management service that allows you to orchestrate and manage containerized application lifecycles with either Kubernetes or Docker Swarm.
Alibaba Cloud’s Container Service offers multiple application release methods, including continuous integration, and it also supports a microservices architecture. Container Service for Kubernetes provides enterprise-level performance and flexibility for the management of Kubernetes containerized applications at every stage of the development lifecycle.
Alibaba Cloud’s Container Service for Kubernetes simplifies cluster creation, management, and allows for easy upscale too. It also auto-integrates with Alibaba Cloud’s virtualization, storage, network, and security services which improve and simplify the overall running environment for Kubernetes containerized applications.
Alibaba Cloud’s Container Service is one of the first cloud container services to have passed the Certified Kubernetes Conformance Program.
What Is Kubernetes (K8s)?
Kubernetes is a large-scale, open source, automated orchestration platform for multi-container applications. It eliminates the manual work involved in deploying and scaling containerized applications. Kubernetes allows DevOps professionals to orchestrate, manage, and monitor extensive, enterprise-grade, clusters of nodes that together run containerized application stacks made up of container pods. A pod is just one of a group of containers deployed on the same host.
Kubernetes organizes containers into logical units for easy administration. It deals with the computing, networking, and storage infrastructure required by user workloads and is highly flexible and scalable too. Kubernetes functions as both Platform as a Service (PaaS) and Infrastructure as a Service (IaaS) and is simple to use and portable.
Kubernetes usually orchestrates applications built up of Docker containers, but it will also support any container system conforming to the Open Container Initiative (OCI) standards for container image formats and runtimes.
Why Do We Need a Cluster?
Before we can install and run Kubernetes container stacks with Alibaba Cloud’s Container Service, we need to have an Alibaba Cloud Container Service Kubernetes cluster ready and available for our containerized application stacks to live on. For this tutorial, we will use a ready-built default Alibaba Cloud Kubernetes cluster which has three master nodes and three worker nodes. These orchestrate and maintain the containerized application stacks by scheduling the container pods on the worker nodes in the cluster.
In a previous tutorial, we described the preliminary step of building out such a Kubernetes cluster. In some other tutorials, we described the steps of building a Docker Swarm cluster and applications on Alibaba Cloud’s Container Service. In this tutorial, we will take you through the steps required to set up and run a basic demo containerized application with Kubernetes on Alibaba Cloud’s Container Service for Kubernetes.
You will need an Alibaba Cloud account. If you don’t already have one, head over to the Free Trial page to get $300–1,200 worth of Alibaba Cloud products to play around with in the Alibaba Cloud Free Trial.
If you haven’t yet set up the Kubernetes cluster, before you do so you will have to activate Alibaba Cloud’s Container Service, the Resource Orchestration Service (ROS), Resource Access Management (RAM), and Elastic Scaling Service (ESS) service. Once these things are done, go ahead and set up your cluster. Once the cluster is running, you can then build out a Kubernetes managed containerized enterprise environment.
Let’s get started.
Check If Your Cluster Is Running
First, head over to the Products page and click Container Service.
You will arrive at the Container Service console page. Your healthy running cluster will be visible on the Cluster List page.
Make Sure Kubernetes Is Accessible from the Command Line
kubectl offers direct access to the cluster nodes and a simple and easy way to bring up pods and containers.
Open a terminal application and make sure you can
ssh into the cluster.
Click the Cluster Name.
The cluster is accessible via the Master node IP address which is also the Server Load Balancer (SLB) IP address.
ssh into the cluster with root access and the password you set when you set up the cluster.
Make sure you also have the most flexible command line access to your Kubernetes cluster with
Create a Kubernetes Application Stack
Go back to the Cluster List page and click Deployment.
Click Create By Image.
In the Basic Information tab, add details for the Application Name, and select the correct Cluster it is to run on.
We’ll leave the defaults for Namespace, Replicas, and Type.
In the Container tab, we can add multiple container stacks to the Kubernetes environment.
Click select Image.
nginx and click OK.
Alibaba Cloud will provide default values for Image Version but you can specify as required.
If you want to ensure that Kubernetes always pull the latest image, select Always pull image.
Configure values for Resource Limit and Resource Request which reflect the nature of your deployment.
If you need an
Init Container, select it here.
We have left the configuration options as default, but you can configure optional Environment Variables.
You can enable optional Liveness and Readiness Health Checks if required.
You can monitor these health checks via
kubectl or via HTTP Requests.
See https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/ for more details on Health Checks.
You can configure lifecycle rules here.
If you need Data Volumes, you can configure them here also.
If you want logging, configure the optional Log Service and make sure that the cluster has deployed the log plugins described in the link.
Here is an example Log Service configuration which we haven’t used for this tutorial.
When you are happy with your configurations, click Next.
Now you can configure the Advanced settings. We have left these blank in favor of command line configuration with
Access Control allows you to configure Service and Ingress details.
You have the option of Horizontal Pod Autoscaling (HPA) configurations that deal with varying application loads.
You can configure also optional Scheduling of Node and Pod Affinity where pods and nodes can be mapped to preferred nodes and clusters.
Check all the details and, when you’re ready, click Create.
Success. Click View Details.
Alternative set up if the port does not bind correctly: run the following command in the terminal.
kubectl run k8s-project --replicas=2 --labels="run=load-balancer-example" --image=nginx --port=8080
You will see the configuration details of the container pod application you just created.
Scroll down and you will see your
nginx replica set at the bottom with a running status.
Now let’s check the deployment details with
Let’s get more details on our
We can also see status information and more details about the replica sets.
Now, let’s create a Service object that exposes the deployment.
kubectl expose deployment k8s-project --type=LoadBalancer --name=my-service
We can ask for more details on the Service object.
Also, back in the UI, you will see details of the Service object in the Deployment details under the Access tab.
You can request more info on the service from
From these details, make a note of the external IP address (
LoadBalancer Ingress) exposed by the service.
In our example, the external IP address is
22.214.171.124. We can use this address to access the
nginx application and check if it is running.
You can now go ahead and set up more containers in the Kubernetes cluster to build out an enterprise scale application environment. If you have enabled logs and monitoring, you will be able to monitor your cluster nodes and pods via the Alibaba Cloud Container Service for Kubernetes UI.
First, we told you how, along with Docker Swarm applications, you can now build Kubernetes containerized applications with Alibaba Cloud’s Container Service.
We informed you that, before you can build out a detailed Kubernetes application environment, you must have a Container Service cluster ready for Kubernetes to run on. We advised you to look up our previous tutorial that details the steps you need to take to build a prerequisite cluster. We also told you about previous tutorials where we showed you how to build a Docker Swarm cluster and application with Alibaba Cloud’s Container Service.
We gave you some information about Alibaba Cloud’s Container Service, specifically the Container Service Kubernetes product which manages large-scale containerized applications. We told you a little bit about what Kubernetes does and then we took you through the step-by-step process of setting up a Container Service Kubernetes application on a ready-made Container Service cluster in Alibaba Cloud.
You are now ready to build out scalable Kubernetes containerized application environments. Keep your eyes out for more tutorials on Alibaba Cloud’s Container Service products and other cloud product offerings.