You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
5.7 KiB

6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
5 years ago
6 years ago
  1. Param(
  2. [parameter(Mandatory=$false)][string]$registry,
  3. [parameter(Mandatory=$false)][bool]$installIstioOnSystem=$false,
  4. [parameter(Mandatory=$false)][string]$dockerUser,
  5. [parameter(Mandatory=$false)][string]$dockerPassword,
  6. [parameter(Mandatory=$false)][string]$externalDns="aks",
  7. [parameter(Mandatory=$false)][string]$dnsname="eshoptestistio",
  8. [parameter(Mandatory=$false)][string]$appName="eshop",
  9. [parameter(Mandatory=$false)][bool]$deployInfrastructure=$true,
  10. [parameter(Mandatory=$false)][string]$kialiuser="admin",
  11. [parameter(Mandatory=$false)][string]$kialipasswrd="admin",
  12. [parameter(Mandatory=$false)][bool]$clean=$true,
  13. [parameter(Mandatory=$false)][string]$aksName="",
  14. [parameter(Mandatory=$false)][string]$aksRg="",
  15. [parameter(Mandatory=$false)][string]$imageTag="latest",
  16. [parameter(Mandatory=$false)][bool]$useLocalk8s=$false
  17. )
  18. $dns = $externalDns
  19. # Instalamos Istio
  20. # Specify the Istio version that will be leveraged throughout these instructions
  21. $ISTIO_VERSION="1.1.1"
  22. # Windows
  23. $ProgressPreference = 'SilentlyContinue';
  24. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  25. Invoke-WebRequest -URI "https://github.com/istio/istio/releases/download/$ISTIO_VERSION/istio-$ISTIO_VERSION-win.zip" -OutFile "istio-$ISTIO_VERSION.zip"
  26. Remove-Item istio-$ISTIO_VERSION -Recurse -ErrorAction Ignore
  27. Expand-Archive -Path "istio-$ISTIO_VERSION.zip" -DestinationPath .
  28. Pause
  29. if($installIstioOnSystem -eq $true) {
  30. New-Item -ItemType Directory -Force -Path "C:\Program Files\Istio"
  31. mv ./istio-$ISTIO_VERSION/bin/istioctl.exe "C:\Program Files/Istio/"
  32. $PATH = [environment]::GetEnvironmentVariable("PATH", "User")
  33. [environment]::SetEnvironmentVariable("PATH", $PATH + "; C:\Program Files\Istio", "User")
  34. }
  35. # Primero Desinstalamos cualquier cosa que haya en el cluster
  36. if ($clean -eq $true) {
  37. Write-Host "Cleaning previous helm releases..." -ForegroundColor Green
  38. helm delete --purge $(helm ls -q)
  39. kubectl delete -f istio-$ISTIO_VERSION/install/kubernetes/helm/istio/templates/crds.yaml -n istio-system
  40. Write-Host "Previous releases deleted" -ForegroundColor Green
  41. }
  42. Write-Host "Generating Kiali Credentials" -ForegroundColor Green
  43. #generamos la credenciales para que kiali arranque sin problemas
  44. kubectl -n istio-system create secret generic kiali --from-literal=username=$kialiuser --from-literal=passphrase=$kialipasswrd
  45. Write-Host "Deploying Istio in the cluster" -ForegroundColor Green
  46. helm install istio-$ISTIO_VERSION/install/kubernetes/helm/istio --wait --name istio --namespace istio-system --set global.mtls.enabled=false --set global.controlPlaneSecurityEnabled=false --set grafana.enabled=true --set tracing.enabled=true --set kiali.enabled=true
  47. Write-Host "Setting Up Gateway"
  48. kubectl delete gateway istio-autogenerated-k8s-ingress -n istio-system
  49. kubectl apply -f ./istio/gateway.yml
  50. if ($useLocalk8s -eq $true) {
  51. $dns="localhost"
  52. $externalDns="localhost"
  53. }
  54. else {
  55. Write-Host "Resolving DNS to Gateway public IP" -ForegroundColor Green
  56. $ipaddress = $(kubectl get service istio-ingressgateway -n istio-system)[1] | %{ $_.Split(' ')[9];}
  57. $query = "[?ipAddress!=null]|[?contains([ipAddress], '$ipaddress')].[id]"
  58. $resid = az network public-ip list --query $query --output tsv
  59. $jsonresponse = az network public-ip update --ids $resid --dns-name $dnsname
  60. $externalDns = ($jsonresponse | ConvertFrom-Json).dnsSettings.fqdn
  61. Write-Host "$externalDns is pointing to Cluster public ip $ipaddress"
  62. }
  63. $useCustomRegistry=$false
  64. if (-not [string]::IsNullOrEmpty($registry)) {
  65. $useCustomRegistry=$true
  66. if ([string]::IsNullOrEmpty($dockerUser) -or [string]::IsNullOrEmpty($dockerPassword)) {
  67. Write-Host "Error: Must use -dockerUser AND -dockerPassword if specifying custom registry" -ForegroundColor Red
  68. exit 1
  69. }
  70. }
  71. Write-Host "Begin eShopOnContainers installation using Helm" -ForegroundColor Green
  72. $infras = ("sql-data", "nosql-data", "rabbitmq", "keystore-data", "basket-data")
  73. $charts = ("eshop-common", "apigwmm", "apigwms", "apigwwm", "apigwws", "basket-api","catalog-api", "identity-api", "locations-api", "marketing-api", "mobileshoppingagg","ordering-api","ordering-backgroundtasks","ordering-signalrhub", "payment-api", "webmvc", "webshoppingagg", "webspa", "webstatus", "webhooks-api", "webhooks-web")
  74. if ($deployInfrastructure) {
  75. foreach ($infra in $infras) {
  76. Write-Host "Installing infrastructure: $infra" -ForegroundColor Green
  77. helm install --values app.yaml --values inf.yaml --set app.name=$appName --set inf.k8s.dns=$externalDns --name="$appName-$infra" $infra
  78. }
  79. }
  80. foreach ($chart in $charts) {
  81. Write-Host "Installing: $chart" -ForegroundColor Green
  82. if ($useCustomRegistry) {
  83. helm install --set inf.registry.server=$registry --set inf.registry.login=$dockerUser --set inf.registry.pwd=$dockerPassword --set inf.registry.secretName=eshop-docker-scret --values app.yaml --values inf.yaml --values $ingressValuesFile --set app.name=$appName --set inf.k8s.dns=$dns --set image.tag=$imageTag --set image.pullPolicy=Always --name="$appName-$chart" $chart
  84. }
  85. else {
  86. if ($chart -ne "eshop-common") { # eshop-common is ignored when no secret must be deployed
  87. helm install --values app.yaml --values inf.yaml --set app.name=$appName --set inf.k8s.dns=$externalDns --set image.tag=$imageTag --set image.pullPolicy=Always --name="$appName-$chart" $chart
  88. }
  89. }
  90. }
  91. Write-Host "helm charts installed." -ForegroundColor Green
  92. Write-Host "Appling Virtual Services for routing." -ForegroundColor Green
  93. kubectl apply -f ./istio/virtualservices.yml
  94. Remove-Item istio-$ISTIO_VERSION -Recurse -ErrorAction Ignore
  95. Remove-Item istio-$ISTIO_VERSION.zip -Recurse -ErrorAction Ignore