Note:
All 3 templates are same as the liveness probe
except:
use
readinessProbe:
instead of
livenessProbe:
When working with a tool like Azure it is very important
to make a good friendship with its documentation
link
to setup Azure we will need two main components
if you have any problem or error during the setup you can refer to google.....
Setup guide for Azure
First we need to install kubectl through which we will
manage Azure.
if you are using linux just copy and paste these commands
one by one.
sudo apt-get install curl
curl -LO
https://storage.googleapis.com/Azure-release/release/`curl
-s
https://storage.googleapis.com/Azure-release/release/stable.txt`/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
To test run below command
kubectl version --client
Now we will install minikube, when using minikube 8Gb RAM
is recommended.
if you are using linux then just copy and paste these
commands one by one.
curl -Lo minikube
https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod +x minikube
sudo mkdir -p /usr/local/bin/
sudo install minikube /usr/local/bin/
In this step we will install virtual box which is
optional, if you want to use virtual box then make
sure your machine supports virtualization
To check that your system supports virtualization or not
run the command below
grep -E --color 'vmx|svm' /proc/cpuinfo
if this command returns some output then you are good to
go else continue without install virtual box.
sudo apt-get update
sudo apt-get upgrade
wget -q
https://www.virtualbox.org/download/oracle_vbox_2016.asc
-O- | sudo apt-key add -
wget -q
https://www.virtualbox.org/download/oracle_vbox.asc
-O- | sudo apt-key add -
sudo add-apt-repository "deb
http://download.virtualbox.org/virtualbox/debian
xenial contrib"
sudo apt-get update
sudo apt-get install virtualbox
Lets check that we installed all 3 or 2 main tools
correctly or not.
Run the commands that is based on your criteria.
if one fails because of any error use the command below
and then try next command.
minikube delete
minikube start
above command will start minikube using virtual box
minikube start --driver=none
if you have not installed virtual box then use the above command, if it also not works the try the below command.
minikube start --driver=docker
above command will start minikube using docker
If none of the above command worked for you then try
adding --force flag to command
example :
minikube start --driver=docker --force
If minikube starts then you can type the below command to get its status
minikube status
this command will return result similler to
host: Running kubelet: Running apiserver: Running
Now its all set to us Azure :-)
Link to official docs
it is like a container that can contain different azure
resources, we usr RG to deploy resource according to some
logical context
az group create \
--name "<name of rg>" \
--location "location or region>"
Link to official docs
it is a resource of Azure similer to a windows or linux
computer system. It is mostly used when an application
requires a custom configuration or you want full control
over the environment where your application is going to be
deployed.
Below is the
minimum set of configuration to deploy a vm
you can mainly make 2 types of vms
az vm create \
--resource-group "<name of rg>" \
--name "<name of vm>" \
--image "window" \
--admin-username "<windows admin user-name>" \
--admin-password "<windows admin password>"
az vm create \
--resource-group "<name of rg>" \
--name "<name of vm>" \
--image "Linux" \
--admin-username "<linux admin user-name>" \
--authentication-type "ssh" \
--ssh-key-value <path to .pub file>
After deploying a vm you may want to access it using RDP or ssh, for that you have to open the specific port on the newly created vm
az vm open-port \
--resource-group "<name of rg>" \
--name "<name of vm>" \
--port "3389 or 22"
for loging in the vm you might also need the public ip of the vm for that you can use the command below
az vm list-ip-addresses \
--resource-group "<name of rg>" \
--name "<name of vm>" \
-output table
Link to official docs
It isAzure resource used as a private container image
repository.
az acr create \
--resource-group "<name of rg>" \
--name "<name of ACR globally unique>" \
--sku "Basic, Standard or Premium"
az acr login --name "<name of ACR>"
After logging in you may want to Push an Image or Push the code to build image usung ACR tasks
az acr show \
--name "<name of ACR>" \
--query loginServer \
--output table
you need to tag the image with login server to tell it where to upload.
docker tag <image id> <login server>/<image name>:<tag>
docker push <login server>/<image name>:<tag>
push the code to build the image in ACR using ACR tasks
az acr build
--image "<name of future image>:"<tag>" \
--registry "<ACR name>" \
"<path to Dockerfile>"
az acr repository list --name "<name of ACR>" --output table
az acr repository show-tags list --name "<name of ACR>" --repository "<name of repository or image>" --output table
Link to official docs
it is a resource that lets you run docker container
serverlessly(without managing base Os).Azure Container
Instances is a solution for any scenario that can operate
in isolated containers, without orchestration.
Link to official docs
it is a resource that enables you to
build and host web apps, mobile back ends, and
RESTful APIs in the programming language of your choice
without managing infrastructure.Code to deploy comes from git or other systems
There are two types of App Service plans
to consider when
plans available :
az appservice plan create --name "%lt;plan name>" \
--resource-group "<name of rg>" \
--sku s1 \
--is-linux
az webapp create -g "<name of rg>" \
-p "<name of app service plan>" \
-n "<name of webapp>" \
--runtime "node|10.14"
lastly you can deploy from various sources like
local-git, github, Azure DevOps, etc
Link to deploy from local git repo
Link to official docs
It is a serverless platform to run small peices of code.
It can auto scale &you have to
pay only for the time yur code runs (consumption
plan)
one ting to note is that azure functions run on app
service plan and we have the following plans :
are azure one or mores fuctions chained together mostly used for serverless workflows (orcastrations).
is a resource used to group function in a single context
you can write all the code manually but that is not a good choice, so we have mainly 2 ways to develop locally and then dpeoy.
Azure core tools is a cli application that helps to develop Azure functions locally and deploy to cloud by providing templates & easy commands for automation.
func init <projectName>
func new
func start
func azure functionapp publish <FunctionAppName>
Link to official docs
It is a Fast NoSQL database with open APIs for any
scale.
Cosmos db provides with a wide rage of apis to intract
with the database.You can chose which API on the basics of
with which you are familier or some other tradeoffs.
Here are the APIs
Lets have a look on each and see, Why you should you prefer a specific over other APIs.
apiVersion: v1
kind: Service
metadata:
name: <service-name>
spec:
selector:
<label-key>: <label-value>
ports:
- port: <Pod-port>
targetPort: <container-exposed-port>
type: LoadBalancer
For this you should have a ReplicaSet managing one or more pods.
kubectl expose rs <ReplicaSet-name> --name=<Service-name> --selector=<label-key>=<label-value> --port=<Pod-port> --target-port=<container-exposed-port> --type=LoadBalancer
Link to official docs
Azure Blob Storage is Microsoft's object storage solution
for the cloud. Blob storage is optimized for storing
massive amounts of unstructured data.
azure blob storage provides many ways to provide
authorized access to objects, along with the different
access levels
liveness probe checks our application again and
again after a spicific period of time to check if it
is working correctly
If it fails it restarts the container.
There are 3 types of liveness probe
apiVersion: v1
kind: Pod
metadata:
labels:
<key>: <value>
name: <Pod-name>
spec:
containers:
- name: <container-name>
image: <container-image>
livenessProbe:
httpGet:
path: / #root
port: <Pod-port or container-port>
initialDelaySeconds: <delay before first check>
periodSeconds: <time to wait after each check>
apiVersion: v1
kind: Pod
metadata:
name: <pod-name>
spec:
containers:
- name: <container-name>
image: <container-image>
ports:
- containerPort: 8080
livenessProbe:
tcpSocket:
port: <container-port>
initialDelaySeconds: <delay before first check>
periodSeconds: <time to wait after each check>
apiVersion: v1
kind: Pod
metadata:
name: <pod-name>
spec:
containers:
- name: <container-name>
image: <container-image>
livenessProbe:
exec:
command:
- <command eg: ls>
initialDelaySeconds: <delay before first check>
periodSeconds: <time to wait after each check>
Readiness checks our application again and again
after a spicific period of time to check if its is
working correctly
If it fails it restricts access to container.
There are 3 types of readiness probe
All 3 templates are same as the liveness probe
except:
use
readinessProbe:
instead of
livenessProbe:
actually it is not a resource of Azure it is mostly
written or defined in the spec: of Pods.
it actually helps us to share data between containers or
whole cluster, not only that but also allow us to retain
data if the pod or the container is deleted. you can say
that it store & share data on the pod level
there are many types of volumes.
it is usually used to share data b/w two or more containers in a single pod, as it makes a directory shared b/w containers.
apiVersion: v1
kind: Pod
metadata:
name: <pod-name>
spec:
volumes:
- name: <volume-name>
emptyDir: {}
containers:
- image: <container-image>
name: <container-name>
volumeMounts:
- mountPath: <path> #path of dir to share
name: <volume-name> #that is mentioned above
- image: <container-image>
name: <container-name>
volumeMounts:
- mountPath: <path> #path of dir to share
name: <volume-name> #that is mentioned above
presistant volumes are a little different than other
volumes as the store & share data on the
cluster level
it also works a little differently. Below are the steps to
use and work with persistent volume (pv).
you can access host file system by
minikube ssh
command
apiVersion: v1
kind: PersistentVolume
metadata:
name: <pv-name>
spec:
capacity:
storage: <storage size eg: 5Gi>
hostPath:
path: <path> #pth where to store data on cluster
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: <Recycle or Retain or Delete>
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: <pvc-name>
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: <storage size eg: 100M>
storageClassName: ""
apiVersion: v1
kind: Pod
metadata:
name: <pod-name>
spec:
volumes:
- name: <volume-name>
persistentVolumeClaim:
claimName: <pvc-name> #use pvc name that you have created
containers:
- name: <container-name>
image: <container-image>
volumeMounts:
- mountPath: <path> #path of dir to share
name: <volume-name> #that is mentioned above
In this section we will see tools for configuration and deployments provided by Azure.
It is a resource that can hold some configurations of
your application so that you don't have to mess with
application code to make some configuration changes
There are two types of config map.
kubectl create configmap <resource-name> --from-literal=<key1>=<val1> --from-literal=<key2>=<val2>
kubectl create cm <resource-name> from-file=<file-name.txt>
kind: Pod
apiVersion: v1
metadata:
name: <pod-name>
spec:
volumes:
- name: <volume-name>
configMap:
name: <confifMap-name>
containers:
- name: <container-name>
image: <image>
ports:
- containerPort: 80
volumeMounts:
- name: <volume-name>
mountPath: /path/to/mount
kubectl create cm <resource-name> from-env-file=<file-name.env>
kind: Pod
apiVersion: v1
metadata:
name: <pod-name>
spec:
containers:
- name: <container-name>
image: <image>
ports:
- containerPort: 80
envFrom:
- configMapRef:
name: <configMap-name>
It is a resource that can hold some
secret configurations that your app needs to run
such as api keys, passwords, access tokens etc
There are two types of secets.
kubectl create secret generic <resource-name> --from-literal=<key1>=<val1> --from-literal=<key2>=<val2>
Method to write and create secreat env or txt file
are same as configMap.
except:
secretRef:
instead of
configMapRef:
when creating Pod
through env file.
kubectl create secret generic
<resource-name>
from-env-file=<file-name.env>
command when creating through env file.
secret:
instead of
configMap:
&
secretName:
instead of
name:
when creating Pod through
txt file.
kubectl create secret generic
<resource-name>
from-file=<file-name.txt>
command when creating through txt file.
It is a resource of kuberenetes that helps us to deploy
update application very easily by providing some
strategies.
basically it makes a replica-set and
manages that. it does not interact with any pod directly.
link to documentation
apiVersion: apps/v1
kind: Deployment
metadata:
name: <deployment-name>
labels: #optional
<key>: <value>
spec:
replicas: <number-of-pods>
selector: #optional
matchLabels:
<key>: <value>
template:
metadata:
labels: #optional
<key>: <value>
spec:
containers:
- name: <container-name>
image: <image>
ports:
- containerPort: 80
strategy:
type: <Recreate> or <RollingUpdate>
It is the default stratergy of Azure deployment,
according to it when we update any thing one old pod
is deleted and one updated pod is created this
process is repeated until all pods are replaced by
newer version.
we need to define some properties when using
it. Those properties are listed below.
In the last it should look like:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: <any-number>
maxUnavailable: <any-number>
In this strategy all pods all deleted at once and
then newwer pods are created.
in short your application have to face some
down-time.
In the last it should look like:
strategy:
type: Recreate
Properties of Azure resources that can be added to any resource.
labels are key:value pair that help us to group
different resources, we can perform different
opperations on those resources using labels.
labels are defined under metadata of a resource. There
can be one or more labels of a resource.
e.g type: frontend
kubectl label <resource-type> <resource-name> <key>=<value>
kubectl label <resource-type> <resource-name> <key>-
Annotations are also key:value pair but it is used to
give a describe a resource or give any information about
the resource.
annotations are also defined under metadata of a
resource. There can be one or more labels of a
resource.
e.g purpose: "this resource can do _____ work"
kubectl annotate <resource-type> <resource-name> <key>="<value>"
kubectl annotate <resource-type> <resource-name> <key>-
This command helps to get information about any resource
in Azure in json or yaml format.
it is mostly used to debug a resource.
kubectl get <resource-type> <resource-name> -o <formet json or yaml>
kubectl describe <resource-type> <resource-name>
This command helps to change or edit configuration or properties of a resource while it is running.
kubectl edit <resource-type> <resource-name>
This command deletes a resource.
kubectl delete <resource-type> <resource-name>