Monday, July 8, 2019

Azure Kubernetes service (AKS)

Azure Kubernetes Service (AKS) is a managed container orchestration service, based on the open source Kubernetes system, which is available on the Microsoft Azure public cloud. An organization can use AKS to deploy, scale and manage Docker containers and container-based applications across a cluster of container hosts.

AKS features and benefits 


The primary feature of AKS is its flexibility, reduced management overhead and automation . For example AKS automatically configures "master and nodes" for kubernetecs and also it will handle other processes like Azure AD intergration and connection monitoring services  during the deployment . Also microsoft will take care the kubernetics upgrade as AKS is a managed services . In addition, AKS nodes can scale up or down to accommodate fluctuations in resource demands. For additional processing power, AKS also supports node pools enabled by graphics processing units (GPUs). This can be vital for compute-intensive workloads, such as scientific applications.


















Creating AKS using Azure portal 

1. In the top left-hand corner of the Azure portal, select + Create a resource > Containers
>Kubernetes Service.


















2. On the Basics page provide kubernetes clustername , azure subscription and resource group details
















3. In the below colum we need to provide the number of VM's needed for cluster  this will attach minimum number of nodes available in the cluster.  The VM size cannot be changed once the cluster is deployed ..
















4. There is another window which will allow us to enable the scaling option with in the cluster. If we enable virtual nodes it will allow the cluster to add more containers in the back end of the cluster. Vm scale set's will allow auto scaling option .


















5. In the Authentication session we have to configure service principal ( either a new one or attach the existing one) . This service principal is used to manage resources attached to the cluster.  
  • The service principal for Kubernetes is a part of the cluster configuration. However, don't use the identity to deploy the cluster.
  • By default, the service principal credentials are valid for one year. You can update or rotate the service principal credentials at any time.
  • On the agent node VMs in the Kubernetes cluster, the service principal credentials are stored in the file /etc/kubernetes/azure.json
  • When you delete an AKS cluster that was created by az aks create, the service principal that was created automatically is not deleted.

















6. Next in the networking tag i have enabled http enabled routing which will configure DNS public access for the applications . When the add-on is enabled, it creates a DNS Zone in your subscription.




















7. Next enable the monitoring as below



















8. Mention the tagging and click on create option . It will create the cluster deployment
































9. Once cluster is created we can connect to azure cli and check the status as below 

unixchipsazure@Azure:~$ az aks get-credentials --resource-group unixchips --name unixchipsaks
Merged "unixchipsaks" as current context in /home/unixchipsazure/.kube/config


unixchipsazure@Azure:~$ kubectl get nodes
NAME                       STATUS   ROLES   AGE     VERSION
aks-agentpool-54305753-0   Ready    agent   6h20m   v1.12.8
aks-agentpool-54305753-1   Ready    agent   6h20m   v1.12.8

10. Now we have to load an application in the cluster . There is a sample app called voting app which is available from the GIT hub .  Copy the below code to a file called azure-vote.yml 

*******************************************************
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: azure-vote-back
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: azure-vote-back
    spec:
      containers:
      - name: azure-vote-back
        image: redis
        ports:
        - containerPort: 6379
          name: redis
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-back
spec:
  ports:
  - port: 6379
  selector:
    app: azure-vote-back
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: azure-vote-front
spec:
  replicas: 3
  strategy:
    rollingUpdate:
      maxSurge: 60%
      maxUnavailable: 60%
  template:
    metadata:
      labels:
        app: azure-vote-front
    spec:
      containers:
      - name: azure-vote-front
        image: microsoft/azure-vote-front:v1
        ports:
        - containerPort: 80
        env:
        - name: REDIS
          value: "azure-vote-back"
        - name: MY_POD_NAMESPACE
          valueFrom: {fieldRef: {fieldPath: metadata.namespace}}
      imagePullSecrets:
      - name: k8s
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-front
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: azure-vote-front
*******************************************************

11. Let's create the app using the above mentioned yml file 

unixchipsazure@Azure:~$ kubectl apply -f  azure-vote.yml
deployment.apps/azure-vote-back created
service/azure-vote-back created
deployment.apps/azure-vote-front created
service/azure-vote-front created

12. We will verify the pod details and it should be in running as below 

unixchipsazure@Azure:~$ kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
azure-vote-back-746d4bc54b-dcbll    1/1     Running   0          4m13s
azure-vote-front-68d68d697d-dwbkm   1/1     Running   0          4m12s
azure-vote-front-68d68d697d-hlct4   1/1     Running   0          4m12s
azure-vote-front-68d68d697d-mtxbl   1/1     Running   0          4m12s

13. Now we have to check the service details which will show the public IP to access the app

unixchipsazure@Azure:~$ kubectl get service azure-vote-front --watch
NAME               TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
azure-vote-front   LoadBalancer   10.0.205.35   <pending>     80:30211/TCP   103s
azure-vote-front   LoadBalancer   10.0.205.35   52.186.71.216   80:30211/TCP   2m2s



14. Login to the browser and access the public IP, we can see the app



















We have successfully configured the AKS and hosted an APP using that.

Thank you for reading .....

No comments:

Post a Comment