cowinr
8/11/2019 - 11:51 AM

AKS, ACR, ACI

Kubernetes cluster architecture

A Kubernetes cluster is divided into two components:

  • Cluster master nodes provide the core Kubernetes services and orchestration of application workloads.
  • Nodes run your application workloads.

Nodes and node pools

To run your applications and supporting services, you need a Kubernetes node.

An AKS cluster has one or more nodes, which is an Azure virtual machine (VM) that runs the Kubernetes node components and container runtime.

az group create --name myResourceGroup --location eastus

# create cluster
az aks create \
    --resource-group myResourceGroup \
    --name myAKSCluster \
    --node-count 1 \
    --enable-addons monitoring \
    --generate-ssh-keys

# install kubectl
az aks install-cli

# download credentials and configurs Kubernetes CLI to use them
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

# verify the connection
kubectl get nodes

# Deploy the application using the kubectl apply
kubectl apply -f app.yaml

# Delete cluser by deleting resource group
az group delete --name myResourceGroup --yes --no-wait
# Dockerfile:
FROM node:8.9.3-alpine
RUN mkdir -p /usr/src/app
COPY ./app/ /usr/src/app/
WORKDIR /usr/src/app
RUN npm install
CMD node /usr/src/app/index.js

# create the container image and tag it as aci-tutorial-app
docker build ./aci-helloworld -t aci-tutorial-app

# Use the docker images command to see the built image:
docker images

# Your newly built image should appear in the list
# REPOSITORY          TAG       IMAGE ID        CREATED           SIZE
# aci-tutorial-app    latest    5c745774dfa9    39 seconds ago    68.1 MB

# run locally
#   -d lets the container run in the background
#   -p maps port 8080 on your computer to port 80 in the container
docker run -d -p 8080:80 aci-tutorial-app
az group create --name myResourceGroup --location eastus

# create registry
az acr create --resource-group myResourceGroup --name <acrName> --sku Basic --admin-enabled true

# log in to registry before pushing images to it
az acr login --name <acrName>

# get the full login server name for ACR - required for tagging
az acr show --name <acrName> --query loginServer --output table
# e.g. <acrName>.azurecr.io

# tag image ready for push to ACR
docker tag aci-tutorial-app <acrName>.azurecr.io/aci-tutorial-app:v1

# Verify tagging
docker images
# REPOSITORY                              TAG       IMAGE ID        CREATED           SIZE
# aci-tutorial-app                        latest    5c745774dfa9    39 minutes ago    68.1 MB
# <acrName>.azurecr.io/aci-tutorial-app   v1        5c745774dfa9    7 minutes ago     68.1 MB

# push to ACR
docker push <acrName>.azurecr.io/aci-tutorial-app:v1

# list images in ACR
az acr repository list --name <acrName> --output table
# Result
# ----------------
# aci-tutorial-app

# To see the tags for a specific image, use the az acr repository show-tags command.
az acr repository show-tags --name <acrName> --repository aci-tutorial-app --output table
# Result
# --------
# v1
# use the az container create command to deploy the container
az container create --resource-group myResourceGroup \
    --name aci-tutorial-app \
    --image <acrName>.azurecr.io/aci-tutorial-app:v1 \
    --cpu 1 --memory 1 --registry-login-server <acrName>.azurecr.io \
    --registry-username <service-principal-ID> \
    --registry-password <service-principal-password> \
    --dns-name-label <aciDnsLabel> \
    --ports 80

# view the state of the deployment
az container show --resource-group myResourceGroup --name aci-tutorial-app --query instanceView.state
"Running"

# view app
az container show --resource-group myResourceGroup --name aci-tutorial-app --query ipAddress.fqdn
"aci-demo.eastus.azurecontainer.io"

# view logs
az container logs --resource-group myResourceGroup --name aci-tutorial-app