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

5 years ago
5 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.0.6"
  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. if($installIstioOnSystem -eq $true) {
  29. New-Item -ItemType Directory -Force -Path "C:\Program Files\Istio"
  30. mv ./istio-$ISTIO_VERSION/bin/istioctl.exe "C:\Program Files/Istio/"
  31. $PATH = [environment]::GetEnvironmentVariable("PATH", "User")
  32. [environment]::SetEnvironmentVariable("PATH", $PATH + "; C:\Program Files\Istio", "User")
  33. }
  34. # Primero Desinstalamos cualquier cosa que haya en el cluster
  35. if ($clean -eq $true) {
  36. Write-Host "Cleaning previous helm releases..." -ForegroundColor Green
  37. helm delete --purge $(helm ls -q)
  38. kubectl delete -f istio-$ISTIO_VERSION/install/kubernetes/helm/istio/templates/crds.yaml -n istio-system
  39. Write-Host "Previous releases deleted" -ForegroundColor Green
  40. }
  41. Write-Host "Generating Kiali Credentials" -ForegroundColor Green
  42. #generamos la credenciales para que kiali arranque sin problemas
  43. kubectl -n istio-system create secret generic kiali --from-literal=username=$kialiuser --from-literal=passphrase=$kialipasswrd
  44. Write-Host "Deploying Istio in the cluster" -ForegroundColor Green
  45. helm install istio-$ISTIO_VERSION/install/kubernetes/helm/istio --wait --name istio --namespace istio-system --set global.controlPlaneSecurityEnabled=true --set grafana.enabled=true --set tracing.enabled=true --set kiali.enabled=true
  46. Write-Host "Setting Up Gateway"
  47. kubectl delete gateway istio-autogenerated-k8s-ingress -n istio-system
  48. kubectl apply -f ./istio/gateway.yml
  49. if ($useLocalk8s -eq $true) {
  50. $dns="localhost"
  51. $externalDns="localhost"
  52. }
  53. else {
  54. Write-Host "Resolving DNS to Gateway public IP" -ForegroundColor Green
  55. $ipaddress = $(kubectl get service istio-ingressgateway -n istio-system)[1] | %{ $_.Split(' ')[9];}
  56. $query = "[?ipAddress!=null]|[?contains([ipAddress], '$ipaddress')].[id]"
  57. $resid = az network public-ip list --query $query --output tsv
  58. $jsonresponse = az network public-ip update --ids $resid --dns-name $dnsname
  59. $externalDns = ($jsonresponse | ConvertFrom-Json).dnsSettings.fqdn
  60. Write-Host "$externalDns is pointing to Cluster public ip $ipaddress"
  61. }
  62. $useCustomRegistry=$false
  63. if (-not [string]::IsNullOrEmpty($registry)) {
  64. $useCustomRegistry=$true
  65. if ([string]::IsNullOrEmpty($dockerUser) -or [string]::IsNullOrEmpty($dockerPassword)) {
  66. Write-Host "Error: Must use -dockerUser AND -dockerPassword if specifying custom registry" -ForegroundColor Red
  67. exit 1
  68. }
  69. }
  70. Write-Host "Begin eShopOnContainers installation using Helm" -ForegroundColor Green
  71. $infras = ("sql-data", "nosql-data", "rabbitmq", "keystore-data", "basket-data")
  72. $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")
  73. if ($deployInfrastructure) {
  74. foreach ($infra in $infras) {
  75. Write-Host "Installing infrastructure: $infra" -ForegroundColor Green
  76. helm install --values app.yaml --values inf.yaml --set app.name=$appName --set inf.k8s.dns=$externalDns --name="$appName-$infra" $infra
  77. }
  78. }
  79. foreach ($chart in $charts) {
  80. Write-Host "Installing: $chart" -ForegroundColor Green
  81. if ($useCustomRegistry) {
  82. 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
  83. }
  84. else {
  85. if ($chart -ne "eshop-common") { # eshop-common is ignored when no secret must be deployed
  86. 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
  87. }
  88. }
  89. }
  90. Write-Host "helm charts installed." -ForegroundColor Green
  91. Write-Host "Appling Virtual Services for routing." -ForegroundColor Green
  92. kubectl apply -f ./istio/virtualservices.yml
  93. Remove-Item istio-$ISTIO_VERSION -Recurse -ErrorAction Ignore
  94. Remove-Item istio-$ISTIO_VERSION.zip -Recurse -ErrorAction Ignore