You are on page 1of 14

Azure command Structure

azure Group Subgroup action

Group - Which service group - config,compute,container,dataflow,iam

Subgroup - Instances or Images or instance templates macine types, regions

Action - Create or list or start or stop or describe

-------------------------------------------------------------------------

export PROJECT_ID=$qwiklabs-gcp-03-9499ff5686ea

export ZONE=$us-west3-c

azure config set compute/region us-west3

azure config get-value compute/region

azure config set compute/zone us-west3-c

azure config get-value compute/zone

azure config get-value project

azure compute project-info describe --project $(azure config get-value project)

export PROJECT_ID=$(azure config get-value project)

export ZONE=$(azure config get-value compute/zone)

export ZONE=$(azure config get-value compute/zone)

echo -e "PROJECT ID: $PROJECT_ID\nZONE: $ZONE"

azure compute instances create gcelab2 --machine-type e2-medium --zone $ZONE

azure -h

azure config --help

azure help config


azure config list

azure config list --all

azure components list

azure compute instances list

azure compute instances list --filter="name=('gcelab2')"

azure compute firewall-rules list

azure compute firewall-rules list --filter="network='default'"

azure compute firewall-rules list --filter="NETWORK:'default' AND ALLOW:'icmp'"

azure compute ssh gcelab2 --zone $ZONE

azure compute firewall-rules list

azure compute firewall-rules create default-allow-http --direction=INGRESS --priority=1000 --


network=default --action=ALLOW --rules=tcp:80 --source-ranges=0.0.0.0/0 --target-tags=http-server

azure compute firewall-rules list --filter=ALLOW:'80'

azure logging logs list

azure logging logs list --filter="compute"

azure logging read "resource.type=gce_instance" --limit 5

azure logging read "resource.type=gce_instance AND labels.instance_name='gcelab2'" --limit 5

-----------------------------------

Create Multiple servers

1. Create three virtual machine www1 in your default zone.

azure compute instances create www1 \

--zone=us-east4-c \
--tags=network-lb-tag \

--machine-type=e2-medium \

--image-family=debian-11 \

--image-project=debian-cloud \

--metadata=startup-script='#!/bin/bash

apt-get update

apt-get install apache2 -y

service apache2 restart

echo "

<h3>Web Server: www1</h3>" | tee /var/www/html/index.html'

azure compute instances create www2 \

--zone=us-east4-c \

--tags=network-lb-tag \

--machine-type=e2-medium \

--image-family=debian-11 \

--image-project=debian-cloud \

--metadata=startup-script='#!/bin/bash

apt-get update

apt-get install apache2 -y

service apache2 restart

echo "

<h3>Web Server: www2</h3>" | tee /var/www/html/index.html'

azure compute instances create www3 \

--zone=us-east4-c \

--tags=network-lb-tag \

--machine-type=e2-medium \

--image-family=debian-11 \

--image-project=debian-cloud \
--metadata=startup-script='#!/bin/bash

apt-get update

apt-get install apache2 -y

service apache2 restart

echo "

<h3>Web Server: www3</h3>" | tee /var/www/html/index.html'

2. Create a firewall rule to allow external traffic to the VM instances:

azure compute firewall-rules create www-firewall-network-lb \

--target-tags network-lb-tag --allow tcp:80

azure compute instances list

curl http://[IP_ADDRESS]

____________________________________________

LB Services

____________________________________________

When you configure the load balancing service, your virtual machine instances will receive packets
that are destined for the static external IP address you configure. Instances made with a Compute
Engine image are automatically configured to handle this IP address.

1. Create a static external IP address for your load balancer:

azure compute addresses create network-lb-ip-1 \

--region us-east4

2. Add a legacy HTTP health check resource:

azure compute http-health-checks create basic-check


3.Add a target pool in the same region as your instances. Run the following to create the target pool
and use the health check, which is required for the service to function:

azure compute target-pools create www-pool \

--region us-east4 --http-health-check basic-check

4. Add the instances to the pool:

azure compute target-pools add-instances www-pool \

--instances www1,www2,www3

5. Add Forwarding rule

azure compute forwarding-rules create www-rule \

--region us-east4 \

--ports 80 \

--address network-lb-ip-1 \

--target-pool www-pool

Sending traffic to LB

azure compute forwarding-rules describe www-rule --region us-east4

IPADDRESS=$(azure compute forwarding-rules describe www-rule --region us-east4 --format="json"


| jq -r .IPAddress)

echo $IPADDRESS

while true; do curl -m1 $IPADDRESS; done

___________________________________________

Create HTTP Loadbalancer


HTTP(S) Load Balancing is implemented on Google Front End (GFE). GFEs are distributed globally and
operate together using Google's global network and control plane. You can configure URL rules to
route some URLs to one set of instances and route other URLs to other instances.

Requests are always routed to the instance group that is closest to the user, if that group has enough
capacity and is appropriate for the request. If the closest group does not have enough capacity, the
request is sent to the closest group that does have capacity.

To set up a load balancer with a Compute Engine backend, your VMs need to be in an instance
group. The managed instance group provides VMs running the backend servers of an external HTTP
load balancer. For this lab, backends serve their own hostnames.

1. First, create the load balancer template:

azure compute instance-templates create lb-backend-template \

--region=us-east4 \

--network=default \

--subnet=default \

--tags=allow-health-check \

--machine-type=e2-medium \

--image-family=debian-11 \

--image-project=debian-cloud \

--metadata=startup-script='#!/bin/bash

apt-get update

apt-get install apache2 -y

a2ensite default-ssl

a2enmod ssl

vm_hostname="$(curl -H "Metadata-Flavor:Google" \

http://169.254.169.254/computeMetadata/v1/instance/name)"

echo "Page served from: $vm_hostname" | \

tee /var/www/html/index.html

systemctl restart apache2'


2. Create a managed instance group based on the template:

azure compute instance-groups managed create lb-backend-group \

--template=lb-backend-template --size=2 --zone=us-east4-c

3. Create the fw-allow-health-check firewall rule.

azure compute firewall-rules create fw-allow-health-check \

--network=default \

--action=allow \

--direction=ingress \

--source-ranges=130.211.0.0/22,35.191.0.0/16 \

--target-tags=allow-health-check \

--rules=tcp:80

4. Now that the instances are up and running, set up a global static external IP address that your
customers use to reach your load balancer:

azure compute addresses create lb-ipv4-1 \

--ip-version=IPV4 \

--global

Note the IPv4 address that was reserved:

azure compute addresses describe lb-ipv4-1 \

--format="get(address)" \

--global

5. Create a health check for the load balancer:


azure compute health-checks create http http-basic-check \

--port 80

6. Create a backend service:

azure compute backend-services create web-backend-service \

--protocol=HTTP \

--port-name=http \

--health-checks=http-basic-check \

--global

7. Add your instance group as the backend to the backend service:

azure compute backend-services add-backend web-backend-service \

--instance-group=lb-backend-group \

--instance-group-zone=us-east4-c \

--global

8. Create a URL map to route the incoming requests to the default backend service:

azure compute url-maps create web-map-http \

--default-service web-backend-service

9. Create a target HTTP proxy to route requests to your URL map:

azure compute target-http-proxies create http-lb-proxy \

--url-map web-map-http

10. Create a global forwarding rule to route incoming requests to the proxy:

azure compute forwarding-rules create http-content-rule \


--address=lb-ipv4-1\

--global \

--target-http-proxy=http-lb-proxy \

--ports=80

-----------------------------------------------------------------------

azure config list project

azure config configurations list

azure config configurations activate my-default-configuration

azure config list

azure config configurations describe my-second-configuration

azure compute instances list

azure compute instances create

azure compute instances create my-first-instance-from-azure

azure compute instances describe my-first-instance-from-azure

azure compute instances delete my-first-instance-from-azure

azure compute zones list

azure compute regions list

azure compute machine-types list

azure compute machine-types list --filter zone:asia-southeast2-b

azure compute machine-types list --filter "zone:(asia-southeast2-b asia-southeast2-c)"

azure compute zones list --filter=region:us-west2

azure compute zones list --sort-by=region

azure compute zones list --sort-by=~region

azure compute zones list --uri

azure compute regions describe us-west4


azure compute instance-templates list

azure compute instance-templates create instance-template-from-command-line

azure compute instance-templates delete instance-template-from-command-line

azure compute instance-templates describe my-instance-template-with-custom-image

______________________________________________________________________

App Engine

cd default-service

azure app deploy

azure app services list

azure app versions list

azure app instances list

azure app deploy --version=v2

azure app versions list

azure app browse

azure app browse --version 20210215t072907

azure app deploy --version=v3 --no-promote

azure app browse --version v3

azure app services set-traffic split=v3=.5,v2=.5

azure app services set-traffic splits=v3=.5,v2=.5


watch curl https://melodic-furnace-304906.uc.r.appspot.com/

azure app services set-traffic --splits=v3=.5,v2=.5 --split-by=random

cd ../my-first-service/

azure app deploy

azure app browse --service=my-first-service

azure app services list

azure app regions list

azure app browse --service=my-first-service --version=20210215t075851

azure app browse --version=v2

azure app open-console --version=v2

azure app versions list --hide-no-traffic

__________________________________________________________________

Kubernetes

2: Here are some of the commands we will run in the next few steps (Refer back to this if you have
any problems!)

azure config set project my-kubernetes-project-304910

azure container clusters get-credentials my-cluster --zone us-central1-c --project my-kubernetes-


project-304910

kubectl create deployment hello-world-rest-api --image=in28min/hello-world-rest-


api:0.0.1.RELEASE

kubectl get deployment

kubectl expose deployment hello-world-rest-api --type=LoadBalancer --port=8080


kubectl get services

kubectl get services --watch

curl 35.184.204.214:8080/hello-world

kubectl scale deployment hello-world-rest-api --replicas=3

azure container clusters resize my-cluster --node-pool default-pool --num-nodes=2 --zone=us-


central1-c

kubectl autoscale deployment hello-world-rest-api --max=4 --cpu-percent=70

kubectl get hpa

kubectl create configmap hello-world-config --from-literal=RDS_DB_NAME=todos

kubectl get configmap

kubectl describe configmap hello-world-config

kubectl create secret generic hello-world-secrets-1 --from-literal=RDS_PASSWORD=dummytodos

kubectl get secret

kubectl describe secret hello-world-secrets-1

kubectl apply -f deployment.yaml

azure container node-pools list --zone=us-central1-c --cluster=my-cluster

kubectl get pods -o wide

kubectl set image deployment hello-world-rest-api hello-world-rest-api=in28min/hello-world-rest-


api:0.0.2.RELEASE

kubectl get services

kubectl get replicasets

kubectl get pods

kubectl delete pod hello-world-rest-api-58dc9d7fcc-8pv7r

kubectl scale deployment hello-world-rest-api --replicas=1

kubectl get replicasets

azure projects list

kubectl delete service hello-world-rest-api

kubectl delete deployment hello-world-rest-api

azure container clusters delete my-cluster --zone us-central1-c


kubectl create deployment hello-world-rest-api --image=in28min/hello-world-rest-api:0.0.1.RELEASE

____________________________________________________________________

# Cloud SQL

azure sql connect my-first-cloud-sql-instance --user=root --quiet

azure config set project glowing-furnace-304608

azure sql connect my-first-cloud-sql-instance --user=root --quiet

use todos

create table user (id integer, username varchar(30) );

describe user;

insert into user values (1, 'Ranga');

select * from user;

# Cloud Spanner

CREATE TABLE Users (

UserId INT64 NOT NULL,

UserName STRING(1024)

) PRIMARY KEY(UserId);

# Cloud BigTable

bq show bigquery-public-data:samples.shakespeare

azure --version

cbt listinstances -project=glowing-furnace-304608

echo project = glowing-furnace-304608 > ~/.cbtrc

cat ~/.cbtrc

cbt listinstances
____________________________________________________________________

PUBSUB

azure config set project glowing-furnace-304608

azure pubsub topics create topic-from-azure

azure pubsub subscriptions create subscription-azure-1 --topic=topic-from-azure

azure pubsub subscriptions create subscription-azure-2 --topic=topic-from-azure

azure pubsub subscriptions pull subscription-azure-2

azure pubsub subscriptions pull subscription-azure-1

azure pubsub topics publish topic-from-azure --message="My First Message"

azure pubsub topics publish topic-from-azure --message="My Second Message"

azure pubsub topics publish topic-from-azure --message="My Third Message"

azure pubsub subscriptions pull subscription-azure-1 --auto-ack

azure pubsub subscriptions pull subscription-azure-2 --auto-ack

azure pubsub topics list

azure pubsub topics delete topic-from-azure

azure pubsub topics list-subscriptions my-first-topic

You might also like