Deploying and Accessing an Application to an AKS Cluster

In this blog post, I will create an AKS cluster. Then, apply a deployment to that cluster to include replicas, a pod template that uses an NGINX container image, and resource limits. Then, I will add a `LoadBalancer` service to provide an external IP, so we can reach our application.

Design Overview

The audience should be familiar with the following to use this hands-on lab:

  • Docker and Containers
  • Kubernetes Deployments, Pods and Services
  • YAML
  • Azure Kubernetes Service
  • Azure Cloud Shell
  • Azure Command Line Interface

To complete this lab you will need to use manifest files when creating the deployment and the service. Once you have accessed the lab environment add the deployment.yaml and service.yaml to your Azure Cloud Shell environment.

If you will be using the Azure Cloud Shell you will need to configure the storage.

  1. Open up the Azure Cloud Shell.
  2. In the welcome screen, select either Bash or PowerShell.
  3. Select “Show advanced settings”.
  4. Set the Cloud Shell region to the same location as the existing resource group
  5. Under “Storage account” make sure “Create new” is selected.
  6. Manually provide a unique name for the Storage account.
  7. Under “File share” make sure “Create new” is selected.
  8. Manually provide a unique name for the File share.
  9. Select “Create storage”.

Create AKS Cluster

Create just the cluster, without any integrations with Azure Monitor, or Azure Policy.

You can use either the provided Service principal or a System-assigned managed identity.

The cluster can be created with the Azure Portal, CLI, PowerShell, or ARM template.

az aks create --resource-group $RG --name ABCluster001 --node-count 3 --generate-ssh-keys --node-vm-size Standard_B2s --enable-managed-identity

link Azure CLI to kubectl command line

az aks get-crrdentials –name ABCluster001 –resource-group $RG

Verification cluster Information

Kubectl get nodes
Kubectl cluster-info

Deploy the Application

Create a deployment to include two replicas of the application. The deployment can be applied in the Azure Portal or with the Azure Cloud Shell.

The application should use the NGINX public Docker Hub image.

Include resource minimum and maximum limits.

touch deployment.yaml 

apiVersion: apps/v1
 # The type of workload we are creating 
kind: Deployment
metadata:
  # Name of deployment - Required
  name: aks-web-app-deployment 
spec:
  replicas: 2
  selector:
    matchLabels: 
      app: aks-web-app
  # Pod template which decribes the pod you want to deploy
  template: 
    metadata:
      # Used to logically group pods together
      labels: 
        app: aks-web-app
    # Specific details about the containers in the Pod
    spec: 
      containers:
      - name: aks-web-app-container
        # Docker Hub image to use
        image: nginx 
        # Define ports to expose
        ports: 
        - containerPort: 80
          # Reference name of port
          name: http 
        resources:
          # Minimum amount of resources we want
          requests: 
            cpu: 100m
            memory: 128Mi
          # Maximum amount of resources we want
          limits: 
            cpu: 250m
            memory: 256Mi

Deploy the application with kubectl

kubectl apply -f ./deployment.yaml

Creating a LocaBalanacer Service by using YAML file

touch service.yaml

apiVersion: v1
 # The type of workload we are creating 
kind: Service
metadata:
# Name of Service - Required
  name: aks-web-app-service
# Specific details about the Service
spec:
# Type of Service to be deployed
  type: LoadBalancer
  ports:
  - port: 80
  # Used to tell the Service which Pods to associate with
  selector:
    app: aks-web-app

Verification deployment

Kubectl get pods -o wide
Kubectl get deploy aks-web-app-deployment

Deploy service.yaml by using kubectl

Once service deployment is completed, we can access nginx web server with the service external IP address

How to get a newly created service public ip address via Azure portal?

View service information with CLI

Kubectl get service

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay Connected

108FansLike
341FollowersFollow
87SubscribersSubscribe

Latest Articles