Skip to content

Instantly share code, notes, and snippets.

@dennisseah
Created January 15, 2020 15:12
Show Gist options
  • Save dennisseah/9e78eba5d702c250c15bc1e91b128a8f to your computer and use it in GitHub Desktop.
Save dennisseah/9e78eba5d702c250c15bc1e91b128a8f to your computer and use it in GitHub Desktop.
Capture initial learning on Azure and Bedrock (OSX user)

Getting Started for Mac Users

Install Software

Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install GIT

brew install git

Maybe also Git Desktop

Terraform CLI

brew install terraform
terraform -v
  (check that it is above 0.12.16)

Kubernetes CLI

brew install kubectl

Helm (Package Manager for Kubernetes)

brew install helm@2

remember to set the path to /usr/local/opt/helm@2/bin. and the version should be 2.16.1

Install Azure CLI and login

brew install azure-cli
az login

do upgrade periodically

brew upgrade azure-cli

Install Docker

https://docs.docker.com/docker-for-mac/install/

Familiarize with Docker

Reference skip this if you are familiar with docker and its commandline interface

Install Docker Desktop

Follow instruction here.

Hello World Docker

Note: Please execute these command one at a time

git clone https://github.com/Azure-Samples/azure-voting-app-redis.git
cd azure-voting-app-redis/
docker-compose  up -d
docker images
docker ps

then point your browser to

Teardown

docker-compose down

To remove the images in docker repo. Clean things up

docker images | grep -e "azure-vote-front" -e "redis" -e "tiangolo/uwsgi-nginx-flask" | awk '{print $3}' | xargs docker rmi

Create AKS Cluster and Container Registry

Reference

Note: Get a bash shell by going to Azure Portal, click on the terminal icon on the header bar, select Bash shell and execute the following commands

Create Resource Group

az group create --name myResourceGroup --location eastus

Creating Container Registry

Reference

az acr create --resource-group myResourceGroup --name myContainerRegistry --sku Basic

need to use web UI to do this; commandline gives error related to monitoring. Then continue with the rest of the instruction on my laptop.

az acr login -n myContainerRegistry
az acr list --resource-group myResourceGroup --query "[].{acrLoginServer:loginServer}" --output table
docker tag azure-vote-front mycontainerregistry.azurecr.io/azure-vote-front:v1
docker images
docker push mycontainerregistry.azurecr.io/azure-vote-front:v1
az acr repository list --name myContainerRegistry --output table
az acr repository show-tags --name myContainerRegistry --repository azure-vote-front --output table

Create AKS Cluster

Reference

az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 2 --generate-ssh-keys --attach-acr myContainerRegistry

Be patient and wait for the command to complete. You will get an JSON dump once it is done.

to delete cluster az group delete --name myResourceGroup --yes --no-wait

Getting Kubernete Configuration

az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

once it is done, you can do

cat ~/.kube/config

Getting nodes information

kubectl get nodes

or you can run kubectl on your laptop by

copy Kubernete Configuration to a file in your laptop and export it.

export KUBECONFIG=~/kube.config

where the file is ~/kube.config

Deploying application and scaling

Reference

remember to edit azure-vote-all-in-one-redis.yaml

kubectl apply -f azure-vote-all-in-one-redis.yaml
kubectl get pods

Wait until the two pods are running.

kubectl get service azure-vote-front --watch

To get the external IP address

Scaling

Reference

kubectl scale --replicas=5 deployment/azure-vote-front
kubectl autoscale deployment azure-vote-front --cpu-percent=50 --min=3 --max=10
kubectl get hpa

Increase node

from 2 to 3

az aks scale --resource-group myResourceGroup --name myAKSCluster --node-count 3

this takes a while.

Update application

Reference

vi azure-vote/azure-vote/config_file.cfg
docker-compose up --build -d
docker tag azure-vote-front mycontainerregistry.azurecr.io/azure-vote-front:v2
az acr login -n myContainerRegistry
docker push mycontainerregistry.azurecr.io/azure-vote-front:v2
kubectl set image deployment azure-vote-front azure-vote-front=mycontainerregistry.azurecr.io/azure-vote-front:v2

Read

Notes

  • Password of SP is shown after creation. We can query for it unless we reset the SP
  • use terraform destroy -var-file=testazuresimple.tfvars to teardown the setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment