Understanding Kubernetes Configurations

By Alex Mungai Muchiri, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

We have seen, in our beginner’s guide that Kubernetes is an open source platform used in containerized applications management. We have looked at the basics Kubernetes, terms, and what components do. In how to Install and Deploy Kubernetes on Ubuntu 16.04, the author has demonstrated the procedure of deploying Kubernetes on Alibaba Cloud. With our platform running successfully on the cloud platform, we are now going to explore more about primitives, deploying containerized applications. We shall also see how to expose services as well as scaling them through replication by a controller.


You will need to get yourself acquainted with the concepts and deployment of Kubernetes for you to follow through with this article. There are specific terms that may need you to refer back to the articles for this tutorial.

Section 1: Kubernetes Primitives

Users leverage Kubernetes APIs for the creation, scaling and termination of applications on the platform. Kubernetes manages various types of objects, each targeted by a different operation. Objects constitute the basic building blocks of Kubernetes, availed as primitives for managing containerized applications. In summary, below are the most important Kubernetes API objects:

  1. Clusters
  2. Nodes
  3. Namespaces
  4. Pods
  5. Labels and selectors
  6. Services
  7. Replication set
  8. Deployment

Kubernetes treats nodes as objects within the cluster. Therefore, you can manage them as you would any other Kubernetes object. On top of that Namespaces on Kubernetes provide a means for the logical separation of applications. A common application of this feature is the separation of development, testing, staging and production clusters. With Namespaces, the various environments can be managed using APIs that link to them independently.

Docker containers running on Kubernetes are not deployed directly because Kubernetes does not understand the format. Kubernetes primitives are needed to package Docker into a different version that allows Kubernetes application management.

Pods can run multiple containers. For instance, we can have both Nginx and Redis containers to run a web server and cache operations in a singular pod. In the configuration, all containers in a pod are as a result of a pre-configured ped definition, and as such, they form a logical unit. Notably, inter-process communication (IPC) is the method of communication between pods.

Kubernetes Services employ TCP and UDP protocols for interaction. The other bit worth mentioning about primitives is the database configuration. Kubernetes does not expose database containers and caches to the public. Kubernetes uses a policy mechanism to expose such containers to other containers to avoid exposure of sensitive workloads to the public. However, APIs are exposed to the public to access services. This default configuration of the primitives improves security.

On scaling workloads up and down, Kubernetes incorporates a dynamic implementation of the label primitive. Selectors can then easily discover running objects. Such objects also include containers, which makes scaling very fast as compared to heavier virtual machines. On the whole, the different primitive configuration enables capabilities similar to PAAS.

Section 2: Kubernetes Nodes and Namespaces

If you have successfully followed how to Install and Deploy Kubernetes on Ubuntu 16.04, you can get a list of all nodes and namespaces by running the command below:

Note: kubectl will target the default Namespace if there no other identified namespaces. Great, let us get an application launched!

Section 3: How to Create and Deploy Pods

We need the kubectl CLI to declare objects in YAML format to submit to Kubernetes for processing. Let us create our first pod:

Run the command to create sample pod Sample-Pod.yaml.

nano Sample-Pod.yaml

Next, let us define our pod by adding the code below. It defines our pod as having a single container based on Nginx. It uses TCP protocol over port 80. The name and env labels in the definition make it possible to identify and configure select pods.


Create our Pod by running the following command:

Run the command below to verify our Pod was created

We want to make our Pod accessible to the public. We shall see how to go about it in the next section.

Section 4: How to use Services to Expose a Pod

You can expose Pods either internally or externally using Services. In our simple project, let us expose the Nginx web server pod publicly. Our preferred object of use is the NodePort, which uses an arbitrary port on a node. We begin by creating a Sample-Service.yaml file, which has the coded instructions to define the Nginx service.


We have created a service to discover all pods with the Label with name: web and that are within the same namespace. The association is defined fully for the selector. The service has also been declared as of NodePort type. The final process is to submit it to the cluster using kubectl.

You should get confirmation for the successful creation of the service in the output:

Use the command below to get the Pod’s port:

The output has indicated that port 32096 carries the service. Accordingly, lets try working with one of the available nodes:

Use the Alibaba console to obtain the IP addresses of the worker nodes.

Next, make an HTTP request to one of the workers using a curl command on port 32096.

The response should contain the home page of the Nginx web server

We have both a Pod and a Service declared, we shall look at replication sets in the next section.

Section 5: Using Replica Sets to Scale Pods

Replica sets maintain the minimum required Pods running within the cluster. We are going to destroy the Pod we created and use the Replica Set to create three replacements.

Delete the Pod like so:

Declare a new Replica set to proceed to the next step. Defining one is similar to declaring a pod, with the only difference being the replica element defining the Pods it will run. It also contains metadata definition for ease of discovery as was the case with Pods.

We shall create a Sample-RS.yml and the code below:


Save the changes and close the file.

Next, let’s get the Replica Set defined:

Let us now search for our Pods:

When a NodePort is used for Service access, requests are passed to one of these nodes under by the Replica Set. Let us try our Replica Set’s response by deleting one of the pods like so:

Run the command below again:

Kubernetes deletes the pod but creates a new one to maintain the required number of pods in our cluster. The next section will explore deployments

Section 6: Deployments

Deployments are easier for upgrades and patches compared to Pods and Replica Sets. It is the fundamental reason why you would want to use them to deploy containers. For instance, you can upgrade a running pod with Deployments but not with Replica Sets. The feature allows upgrades without downtime and enables PAAS capabilities. Let us first delete our replica set and then proceed to create a Deployment like so:

Create a new Sample-Deployment.yaml file and include the code below:


Create the deployment and view existing Deployments

Get the deployments:

We specified the creation of three Pods, there are three running Pods.

Get the pods like so:

We had configured a service before creating the Deployment. However, since they all have the same labels, it will still be able to use the newly created pods.

If you need to clean up, you can delete both the Service and Deployment like so:

The Kubernetes documentation contains further information on this subject.


This tutorial has built on what we discussed in the beginner’s guide to Kubernetes. We have examined primitive configurations as well as the most important configurations that you are likely to encounter on Kubernetes. We have configured a web server using a pod, created a service, Replica set and deployment. The configurations we have studied in this tutorial are among the most fundamental when handling Kubernetes.

To learn more about Kubernetes on Alibaba Cloud, visit www.alibabacloud.com/product/kubernetes


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