Kubernetes Guides

Running Kubernetes on Microsoft Azure

This is in continuation of the Kubernetes article series. In the earlier posts, we have seen how to create & deploy a simple cluster. Now in this post, we are going to look at recently launched offerings from Microsoft Azure.

Azure Kubernetes Service (AKS) is managed Kubernetes offering from Azure. As a hosted Kubernetes service, Azure handles all heavy lifting of all the complexity, the operational overhead of managing a Kubernetes cluster for you.

As a managed Kubernetes service, AKS provides:

  • Automated Kubernetes version upgrades and patching
  • Easy cluster scaling
  • Self-healing hosted control plane (masters)
  • Cost savings – pay only for running agent pool nodes

In short, AKS would provide a container hosting environment by using open-source tools and technologies. To this end, standard Kubernetes API standard endpoints are exposed and you can leverage any software that is capable of talking to a Kubernetes cluster. Like for example,kubectl

Now we can see how to create a simple cluster using AKS.

Running Kubernetes on Microsoft Azure

This quickstart assumes a basic understanding of Kubernetes concepts, please refer earlier posts for understanding on Kubernetes & how to create, deploy & rollout updates to the cluster.

Step#1.Launch Azure Cloud Shell

Once you login to Azure Portal, on the upper right corner, there is an option to Azure Cloud Shell. Azure Cloud Shell is a free Bash shell that has the Azure CLI preinstalled and configured to use with your account. Learn more about Azure Migration Services and Azure Windows Virtual Desktop.

Image – Launch Azure Cloud Shell

 

Image – Azure Portal

Step#2.Enable AKS Preview

From the Azure Shell, enable AKS preview by the below command.

az provider register -n Microsoft.ContainerService
Image – Enable AKS Preview

On the registrationState the field you can see that its ‘Registering’, you can check the status of the registration by the following command.

az provider show -n Microsoft.ContainerService

Image – AKS Registration Successful

Once registration is complete, we are now ready to create a Kubernetes cluster with AKS.

Step#3.Resource group creation

Before we create the cluster & nodes, we would need to create an Azure resource group which is nothing but a logical group in which Azure resources are deployed and managed.

Create new resources using the below command.

az group create --name k8SResourceGroup --location westus2

Image – Azure create new resource group command

Before proceeding to the next step, check the provisioningState on the output. It should be “Succeeded”

Step#4.Kubernetes cluster creation

Create a sample cluster named myK8sCluster with one node.

az aks create --resource-group k8SResourceGroup --name myK8sCluster --node-count 1 --generate-ssh-keys
Image – Azure create cluster

The above command would take some time to create the cluster, once the command completes and returns JSON-formatted information about the cluster.

Image – JSON-formatted output about the cluster
Image – JSON-formatted output about the cluster

Step#5.Connect to Kubernetes cluster

For us to connect, manage the Kubernetes cluster, we are going to use kubectl, the Kubernetes command-line client. Azure cloud shell has already built-in kubectl so we don’t have to install them separately.

To configure kubectl to connect to our Kubernetes cluster, run the following command. This step downloads credentials and configures the Kubernetes CLI to use them.

az aks get-credentials --resource-group k8SResourceGroup --name myK8sCluster

Image – Connect to Kubernetes cluster

To verify kubectl configuration, check the version of kubectl

Image – kubectl version

Step#6. Deploy the new application on the cluster

Now we are going to create new Kubernetes manifest file that defines the desired state for the cluster, including what container images should be running etc.,

Create a file named Deployment.yml, you can use vi editor to create this file.

Image – Deployment manifest file
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80

Use the kubectl create command to deploy the application.

Image – Create new Deployment

In this example:

  • A Deployment named nginx-deployment is created, indicated by the metadata: name field.
  • The Deployment creates 1 replicated Pods, indicated by the replicas field.
  • The Pod template’s specification, or template: spec field, indicates that the Pods run one container, nginx, which runs the nginx Docker Hub latest image (you can also specify the version ex.1.7.9.)
  • The Deployment opens port 80 for use by the Pods.

Now that deployment is created, let’s check the deployment information using kubectl get deployment command :

Image – kubectl get deployment command

When you inspect the Deployments in your cluster, the following fields are displayed:

  • NAME lists the names of the Deployments in the cluster.
  • DESIRED displays the desired number of replicas of the application, which you define when you create the Deployment. This is the desired state.
  • CURRENT displays how many replicas are currently running.
  • UP-TO-DATE displays the number of replicas that have been updated to achieve the desired state.
  • AVAILABLE displays how many replicas of the application are available to your users.
  • AGE displays the amount of time that the application has been running.

Describe the deployment using kubectl describe deployment command to check the details on the deployment.

Image – kubectl describe deployment command

Step#7. Create service

Kubernetes Service is an abstraction that defines a logical set of Pods and a policy by which to access them  (micro-service). The set of Pods targeted by a Service is determined by a Label Selector

Kubernetes has powerful networking capabilities that control how applications communicate. These networking configurations can also be controlled via YAML. The Service selects all applications with the label Nginx. As multiple replicas, or instances, are deployed, they will be automatically load-balanced based on this common label. The Service makes the application available via a NodePort.

Create a new file named svc.yml to define load balancers & apps.

Image – Service Yaml file
apiVersion: v1
kind: Service
metadata:
 name: nginx-svc
 labels:
 app: nginx
spec:
 type: LoadBalancer
 ports:
 - port: 80
 selector:
 app: nginx

Use kubectl create command to create a new service based on the svc.yaml file created in the previous step.

Image – Create new service

Once the External-IP is available, we can browse the Nginx page.

Image – Once External IP is assigned we can browse Nginx page

Image – Nginx landing page

Step#8. Clean up

Finally, now its time to clean up the resources what we have created:

kubectl delete service my-nginx
kubectl delete deployment my-nginx
Image – kubectl detele service command

 

Image – kubectl detele deployment command

Like this post? Don’t forget to share it!

Additional Resources :

Summary
Article Name
Running Kubernetes on Azure
Description
In this post,we are going to learn about managed Kubernetes offering from Azure (AKS) & also on how to create simple application deployment.
Author
Publisher Name
upnxtblog
Publisher Logo
Karthik

Allo! My name is Karthik,experienced IT professional.Upnxtblog covers key technology trends that impacts technology industry.This includes Cloud computing,Blockchain,Machine learning & AI,Best mobile apps, Best tools/open source libs etc.,I hope you would love it and you can be sure that each post is fantastic and will be worth your time.

Share
Published by
Karthik

Recent Posts

Navigating Volatility: Investing in Crypto Derivatives and Risk Management Strategies

The cryptocurrency market is famed for its volatility, presenting each opportunity and demanding situations for…

1 week ago

How Game Developers Use AI in Mobile Games in 2024?

Games since time immemorial have been winning at captivating the users and teleporting them onto…

2 weeks ago

The Impact of AI on Software Development

We are living within an innovation curve wherein cutting-edge technologies are making a hustle and…

2 weeks ago

AI Tools for Research Paper Writing: Learn What They Can Do

Whether it’s the healthcare industry or the automobile sector, artificial intelligence has left its impact…

4 weeks ago

Embracing Innovation: 5 Ways AI is Transforming the Landscape in 2024

Facts only- The big Artificial Intelligence push is unraveling in 2024. No, it wasn’t merely…

4 weeks ago

The Startup Guide to Acquiring Exceptional Developers

In the fiercely competitive world of Hire Developers for Startup, success hinges not just on…

2 months ago

This website uses cookies.