Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# k8WordPressAzureTest.ps1
# Romain Bigeard romain.bigeard@gmail.com 2017
# Start up a simple 2 node K8 cluster in Azure and deploy a Wordpress stack spread over two containers
# Two parameters are needed:
# azureSshKey = path to private ssh key that will be used to connect to VMs running containers
# kubeWordPressLocation = path to Kuberetes wordpress example (https://github.com/kubernetes/examples/tree/master/mysql-wordpress-pd)
# Also deploys OMS agents on underlying Linux servers if oms parameters are not null
param (
[string]$omsWorkspaceKey = "",
[string]$omsWorkspaceId = "",
[string]$azureSshKey = "",
[string]$kubeWordPressLocation = "",
[string]$mysqlPass = ""
)
$sshKeyPath = Convert-Path -Path $azureSshKey
$publicsshKeyPath = Convert-Path -Path "$($azureSshKey).pub"
Write-Host "Creating myKubeGroup Resource Group"
az group create --name myKubeGroup --location eastus
Write-Host "Creating Kubernetes Cluster"
az acs create --orchestrator-type=kubernetes --resource-group myKubeGroup `
--name myK8sCluster --ssh-key $publicsshKeyPath --master-count 1 --agent-count 1
Start-Sleep -Seconds 60
Write-Host "Getting Kubernetes Credentials"
az acs kubernetes get-credentials --name myK8sCluster --resource-group myKubeGroup --ssh-key $sshKeyPath
Write-Host "Creating mysql secret"
cd $kubeWordPressLocation
if (! $mysqlPass) {
Write-Host "Using generic password as no password was passed on as parameter"
kubectl create secret generic mysql-pass --from-literal=password=kubetest
}
else {
kubectl create secret generic mysql-pass --from-literal=password=$mysqlPass
}
Write-Host "Deploying Mysql"
kubectl create -f .\mysql-deployment.yaml
Start-Sleep -Seconds 30
Write-Host "Deploying WordPress"
kubectl create -f .\wordpress-deployment.yaml
Start-Sleep -Seconds 60
Write-Host "Display Status of Deployments"
kubectl get deployment,pod,svc,endpoints,pvc -o wide ; kubectl get secret mysql-pass ; kubectl get pv
if ($omsWorkspaceKey) {
Write-Host "Installing OMS Agent on all VMs"
$machines = (az vm list -g myKubeGroup | ConvertFrom-Json)
foreach ($machine in $machines.name) {
az vm extension set --resource-group myKubeGroup --vm-name $machine --name OmsAgentForLinux `
--publisher Microsoft.EnterpriseCloud.Monitoring `
--version 1.3.127-7 --protected-settings '{\"workspaceKey\": \"$omsWorkspaceKey\"}' `
--settings '{\"workspaceId\": \"$omsWorkspaceId\"}'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.