Skip to content

Instantly share code, notes, and snippets.

@fitzgeraldsteele
fitzgeraldsteele / vmss-flex-spot-create.py
Created February 6, 2024 06:41
Create VMSS Flex with Spot Instances sample
# Import the needed credential and management objects from the libraries.
from azure.identity import AzureCliCredential
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.compute.models import OrchestrationMode
import os
print(f"Provisioning a virtual machine scale set...some operations might take a minute or two.")
@fitzgeraldsteele
fitzgeraldsteele / simpleVMSSApplicationHealth.yaml
Last active July 21, 2023 20:02
Simple cloud init for application health
#cloud-config
package_upgrade: true
packages:
- nginx
write_files:
- path: /var/www/html/index.html
content: |
<!DOCTYPE html>
version: '3.4'
services:
yarpreverseproxy:
image: vmssapplicationhealth.azurecr.io/yarpreverseproxy:ds1
container_name: yarpreverseproxy
ports:
- 80:7176
links:
#cloud-config
package_upgrade: true
packages:
- nginx
- nodejs
- npm
write_files:
- owner: www-data:www-data
path: /etc/nginx/sites-available/default
content: |
@fitzgeraldsteele
fitzgeraldsteele / getUnhealthyInstances.ps1
Created March 16, 2021 18:22
Find all unhealth instances in a VMSS
$allInstances = Get-AzVmssVM -InstanceView -ResourceGroupName $rg -VMScaleSetName $vmssName
$unhealthyInstances = $allInstances | where {$_.InstanceView.VmHealth.Status.Code -eq "HealthState/unhealthy"}
Write-Output "Total instances: $($allInstances.Count)"
Write-Output "Unhealthy instances: $($unhealthyInstances.Count)"
@fitzgeraldsteele
fitzgeraldsteele / vmss-availability.ps1
Created June 9, 2020 19:06
Azure Virtual Machine Scale Sets: Check Availability constructs
Connect-AzAccount
$mysub = "my-subscription-name"
$rg = "my-resourcegroup-name"
$vmssname = "my-vmss-name"
Set-AzContext -Subscription $mysub
$vmssmodel = Get-AzVmss -ResourceGroupName $rg -VMScaleSetName $vmssname
Write-Output($vmssmodel.Id)
Write-Output("FD Count: " + $vmssmodel.PlatformFaultDomainCount)
[Unit]
Description=Azure Metadata app
[Service]
ExecStart=/usr/bin/node /var/www/azuremetadata/app.js
#Restart=always
StandardOut=syslog
StandardError=Syslog
User=nobody
# Note Debian/Ubuntu uses 'nogroup', RHEL/Fedora uses 'nobody'
@fitzgeraldsteele
fitzgeraldsteele / default-nginx-config
Created November 11, 2019 07:58
nginx simple default config
server {
listen 80;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
@fitzgeraldsteele
fitzgeraldsteele / azure-metadata-cloud-init.yml
Last active June 30, 2021 17:31
cloud-init for Azure Metadata service
#cloud-config
package_upgrade: true
packages:
- nginx
- nodejs
- npm
write_files:
- owner: www-data:www-data
path: /etc/nginx/sites-available/default
content: |
@fitzgeraldsteele
fitzgeraldsteele / app.js
Last active November 12, 2019 18:00
Simple node app to return data from Azure Metadata service
var express = require('express')
var app = express()
var os = require('os');
app.get('/', function (req, res) {
const request = require('request');
const options = {
url: 'http://169.254.169.254/metadata/instance?api-version=2019-03-11',
headers: {
'Metadata': 'true'