Skip to content

Commit

Permalink
AKS and find VM demo files
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthebrit committed Jul 3, 2020
1 parent dec0b24 commit b226364
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
83 changes: 83 additions & 0 deletions AKS/azure-vote.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough
apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-vote-back1
spec:
replicas: 1
selector:
matchLabels:
app: azure-vote-back1
template:
metadata:
labels:
app: azure-vote-back1
spec:
containers:
- name: azure-vote-back1
image: redis
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 6379
name: redis
---
apiVersion: v1
kind: Service
metadata:
name: azure-vote-back1
spec:
ports:
- port: 6379
selector:
app: azure-vote-back1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-vote-front1
spec:
replicas: 1
selector:
matchLabels:
app: azure-vote-front1
template:
metadata:
labels:
app: azure-vote-front1
spec:
containers:
- name: azure-vote-front1
image: microsoft/azure-vote-front:v1
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 80
env:
- name: REDIS
value: "azure-vote-back1"
---
apiVersion: v1
kind: Service
metadata:
name: azure-vote-front1
annotations:
service.beta.kubernetes.io/azure-load-balancer-tcp-idle-timeout: "4"
# service.beta.kubernetes.io/azure-load-balancer-internal: "true"
# service.beta.kubernetes.io/azure-load-balancer-internal-subnet: "svc"
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: azure-vote-front1
13 changes: 13 additions & 0 deletions AKS/demo.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
az aks get-credentials --resource-group RG-AKS --name aks-ussc-sav
az aks isntall-cli

kubectl cluster-info
kubectl get nodes

kubectl apply -f azure-vote.yaml

kubectl get pods -o wide
kubectl get service

#note the endpoints for the frontend points to the IP of the frontend pod IP
kubectl get endpoints azure-vote-front1
54 changes: 54 additions & 0 deletions AzureFindVMs/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

#Import Az.ResourceGraph (not required as loaded via requirements.psd1)

# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."

#Set initial status
$statusGood = $true

# Interact with query parameters or the body of the request.
$ostype = $Request.Query.OSType

if (-not $ostype) {
$ostype = $Request.Body.OSType
}

#Find the VM resource via the computername
$GraphSearchQuery = "Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| where properties.storageProfile.osDisk.osType =~ '$ostype'
| join kind=inner (ResourceContainers | where type=='microsoft.resources/subscriptions'| project SubName=name, subscriptionId) on subscriptionId
| project name, OSType = properties.storageProfile.osDisk.osType,CompName = properties.osProfile.computerName, RGName = resourceGroup,SubID = subscriptionId, SubName
"
$VMresources = Search-AzGraph -Query $GraphSearchQuery

if($VMresources -eq $null)
{
$statusGood = $false
$body = "Could not find a matching VM resource"
}
else
{
$body = $VMresources
}

if(!$statusGood) {
$status = [HttpStatusCode]::BadRequest
}
else {
$status = [HttpStatusCode]::OK
}

$BodyJSON = ConvertTo-Json($body)


# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $status
Body = $BodyJSON
})
5 changes: 5 additions & 0 deletions AzureFindVMs/testrun.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$URIValue = "https://savtechosexecute.azurewebsites.net/api/VMList?code==="
$BodyObject = [PSCustomObject]@{"ostype"="Linux"}
$BodyJSON = ConvertTo-Json($BodyObject)
$response = Invoke-WebRequest -Uri $URIValue -Method POST -Body $BodyJSON -ContentType 'application/json'
$response.content

0 comments on commit b226364

Please sign in to comment.