Last active
October 12, 2017 03:25
-
-
Save rbigeard/ec0725e6ed4d7e4e332a12e76893effe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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