Azure Kubernetes Service (AKS)

**What on earth is Kubernetes **

kubernets is an orchestration technology used to manage deploy and scale containers

Here we are to learn about kubernetes, first we learn about creating kubernetes cluster. Go Azure-portal (portal.azure.com)

click on kubernetes services and then click on create kubernetes-cluster

After clickiing on create create a resource group for kubernetes cluter and give the Name of your cluster as shown in below screen-shot

Afetr that, slide down and select node count range accourding to your requirement

Now click on Next: Node pools >

Here, im using default Node pool as given as agentpool, if you want you can create new

Now click on next on access leave as default and then click on next Networking

Here select on kubenet,

what is Kubenet: In many environments, you have defined virtual networks and subnets with allocated IP address ranges. These virtual network resources are used to support multiple services and applications. To provide network connectivity, AKS clusters can use kubenet (basic networking) or Azure CNI (advanced networking).

With kubenet, only the nodes receive an IP address in the virtual network subnet. Pods can't communicate directly with each other.

Now click on Review and create

Now my cluster is AKS cluster is created

click on connect after that on right hand side you can see some commands by using that commands you can configure and connect to Azure-cli to do that

Now click on cloudshell on your azure-portal

click on Reconnect, now you can see terminal

first copy and paste this command to authenticate to your Azure subscription

After that copy and paste the second command in your terminal to connect to your cluster

Now you're ready to create pods, in organizations we run applications as pods in kubernetes in Dokcer we call it as container but in kubernetes we call as pods

what is pod ?

Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.

A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers.

To create a pod we have two ways one is imperative way and another one is Declarative way, first we learn of creating a pod in Declarative way

First create one file in kubernetes we call as manifest file, vi nginx-deploy.yaml we write in yaml format

this is the way of creating pod in declarative way, in this file we mentioned apiVersion and kind as pod and metadata (app name =nginx) and spec (specifications) = we have given in which port that nginx app should run. now save this file and apply the below command

#kubectl apply -f nginx-deploy.yaml

Now you can see pod is created as pod/nginx ( Here nginx is application name)

#kubectl get pods (This command helps to see list of pods)

Now we create Namespaces

What is Namespace ?

It is Kubernetes objects which is used to create multiple virtual clusters within same physical cluster. We can deploy Pods, deployment, service within each Virtual Cluster called as Kubernetes Namespace.

Let's try to create namespaces in our cluster

To create Name-space the command is #kubectl create namespace -name kubesystem ( here kubesystem name im referring to the namespace, you can give any name)

How to get namespaces,

#kubectl get namespace

Now let's create pod in "kubesystem" namespace

In this way, you can create your pods in different name-spaces.

Now as i shown in below image one pod is running in cluster, but now we got request from client that in next few days we may expect huge traffic, so in kubernetes to manage these pods we use deployment object

previously when we created a pod kind: pod, i given kind= pod, but now we are using deployment object, so that we should refer kind: Deployment

Im using in imperative way now

in the above screenshot i created deployment object and using replicas i scaled pods to 2, you can scale-up using replicas.

Now apply this command to get deployments # kubectl get deploy

Now ill sele-up the pods from 2 >>>>> 5

#kubectl scale --replicas=5 deployment/nginx-deploy

As we shown in the below image now scaled our pods to 5, our app is running on all these five pods

Til now we created pods and we manged the pods, now its time to expose these pods, in kubernetes we expose pods using services, here we have different service those are:

In kubernetes to expose pods within the cluster we use cluster-ip and if you want expose the pods to out-side world we use Node-port, and to expose outside world from cloud we use Load-Balancer service

Now let's expose using services

we created service and exposed our pod in this if you observe we used kind as service as shown in below screen-shot

using this command you can access pod within the cluster # curl nginx-svc

Now to expose outside world we use Load-Balancer to do that first we have to change service form cluster-ip to Load-Balancer

#kubectl edit service nginx-svc

Here in this file we need to change from cluster-ip to Load-Balancer

and save the file and now try #kubect get svc

Now you can see External-ip is visible if you paste this ip address in web-page you should access nginx-web-server

Now we are accessing the application using Load-Balancer service.

ondemandlabskubernetestraininginhyderabad.PNG