Skip to content

Instantly share code, notes, and snippets.

View sumansrivastava's full-sized avatar

Suman Srivastava sumansrivastava

  • India
View GitHub Profile
apiVersion: v1
kind: Namespace
metadata:
name: ns-pruner
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: ns-pruner-sa
namespace: ns-pruner
import subprocess
def run_command(command, shell=False):
"""Run a shell command and raise an error if it fails."""
subprocess.run(command, shell=shell, check=True)
def add_apt_key(url):
"""Add an APT key from a URL."""
run_command(["curl", "-fsSL", url, "|", "sudo", "apt-key", "add", "-"], shell=True)
import subprocess
def test_connectivity(resource_group, vmss_name, instance_id):
log_file = "connectivity_test.log"
try:
# Test connectivity with mcr.microsoft.com on port 443 using netcat
netcat_command = f"az vmss run-command invoke -g {resource_group} -n {vmss_name} --command-id RunShellScript --instance-id {instance_id} --scripts 'nc -zv mcr.microsoft.com 443'"
netcat_result = subprocess.run(netcat_command, shell=True, capture_output=True, text=True)
# Log in to Azure
az login
# Create a resource group
az group create --name myResourceGroup --location eastus
# Create an AKS cluster
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 2 --node-vm-size Standard_D2s_v3
#!/bin/bash
# Check if Azure CLI is installed
if ! command -v az &> /dev/null
then
echo "Azure CLI not found. Installing..."
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
else
echo "Azure CLI already installed."
fi
#!/bin/bash
# Prompt for the namespace
echo "Enter the namespace: "
read namespace
# Check all the resources (pods, Services, Deployment, events)
resources=(pods services deployments events)
for resource in "${resources[@]}"
#!/bin/bash
# Set the name of the namespace
namespace="my-namespace"
# Get the names of all pods in the namespace
pod_list=$(kubectl get pods -n $namespace -o jsonpath='{.items[*].metadata.name}')
# Loop through the pods and check the status of their mounts
for pod in $pod_list; do
#!/bin/bash
# Set the name of the namespace
namespace="my-namespace"
# Create a backup directory
backup_dir="pdb-backup-$(date +%s)"
mkdir $backup_dir
# Get the names of all PDBs in the namespace
import json
import pandas as pd
data = json.load(open('plan.json'))
resource_changes =pd.DataFrame(data["resource_changes"])
print(resource_changes)
resource "random_id" "randomId" {
keepers = {
resource_group = azurerm_resource_group.resourcegroup.name
}
byte_length = 8
}
resource "azurerm_storage_account" "storageaccount" {
name = "diag${random_id.randomId.hex}"