Creating and Scaling Kubernetes Pods on Alibaba Cloud

In this article, we will be learning the core concept of a Kubernetes Pod by configuring one on an Alibaba Cloud Elastic Compute Service instance. We will also be briefly looking at Clusters, Deployments, and ReplicaSets.

Kubernetes on Alibaba Cloud

There are two ways to get Kubernetes set up on Alibaba Cloud: through Container Service (built-in) and the other through an Elastic Compute Service (ECS) instance (self-built). You can to Alibaba Cloud Kubernetes vs. self-built Kubernetes to learn more about the differences of the two options.

For this article, we will choose the self-built Kubernetes approach. We have setup one master node and minion node which is running on the Alibaba Cloud ECS cluster.

The following reference deployment shows one ECS instance set up as kube-master and two ECS instances named minion1 and minion 2 up and running in an Alibaba cloud environment.

Kubernetes Concepts

Before talking about Pods, let’s take a step back and look at the cluster we just created.

Image for post
Image for post

From the architecture diagram above, what can we say about Kubernetes Clusters? Kubernetes coordinates a highly available cluster of computers that are connected to work as a single unit. A Kubernetes cluster consists of two types of resources:

  1. The Master coordinates the cluster
  2. Nodes are the workers that run applications

A Pod on the other hand, is the basic building block of Kubernetes. According to Kubernetes, Pods are the smallest and simplest unit in the Kubernetes object model that you create or deploy, which represents a running process on your cluster.

A Pod always runs on a Node. A Node is a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster. Each Node is managed by the Master. A Node can have multiple pods, and the Kubernetes master automatically handles scheduling the pods across the Nodes in the cluster.

Exploring Kubernetes Cluster

Let’s first run kubectl, the main command line interface (CLI) tool for running commands and managing Kubernetes clusters. We can find out the information of our cluster as follows:

We can also verify nodes that have joined the cluster

A resource is an endpoint in the Kubernetes API that stores a collection of API objects of a certain kind. For example, the built-in pods resource contains a collection of Pod objects. We can list all resources in the name space with the following command:

To List all supported resource types along with their shortnames and API group, run the kubectl api-resourcescommand:

Exploring ReplicaSets

ReplicaSets ensure that a specified number of pod replicas are running at any given time. Start a single Nginx instance with one ReplicaSet.

You can see if we actually have a Kubernetes pods up and running:

The output shows that the Nginx pod is being created. If you run the same command again, you can see that the pods are up and running

We can retrieve a lot more information about each of these pods using the kubectl describe pod command:

Here you can see configuration information about the container and Pod, as well as status information about the container and Pod.

The container state is either Waiting, Running, or Terminated. Here you can see that for a container in Running state, the system tells you when the container started.

“Ready” tells you whether the container passed its last readiness probe.

Replicas help us protect your application from being lost due to misoperations or disasters. We can get the deployment configuration of Nginx with the command:

During the initializing state we have told the Kubernetes to maintain one replica only by setting the flag --replicas=1

Let’s try deleting our pod.

Query on pod still shows one pod is running with different ID. This is because we have set up our Kubernetes to keep one running replica. This can be useful to protect your production server from accidently being destroyed.

Scaling the Pods

Scaling Up the Pods

To scale up the pods, tell kubectl how many current replicas are there (current-replicas) and how many needs to be scaled (replicas)

DESIRED =3, CURRENT =1

When you run this code, two new pods will be created and deployed.

After creating the containers check the status of these pods

You can also follow a similar step to scale down the Pods:

In the output below, we can see that two pods are terminating.

After scaling down only one Nginx pod is running.

Adding a New Node to a Cluster

To add new node to the Kubernetes cluster, you need a token and discovery-token-ca-cert-hash.

First, create a token using the kubeadm command in the kube-master setup,

Get rootCA cert fingerprint

The produced discovery-token-ca-cert-hash value:

Once the Token is created, join the new node, kube-minion2 using the token and the discovery-token-ca-cert-hash value:

Now in this cluster we have two minion nodes and one master node

Even after adding nodes, you can still scale up your Pods.

Look for the Events to verify on the new node pods are created and Nginx are deployed

Reference:https://www.alibabacloud.com/blog/creating-and-scaling-kubernetes-pods-on-alibaba-cloud_594020?spm=a2c41.12067566.0.0

Written by

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store