|
| 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 | + |
| 19 | +$dns = $externalDns |
| 20 | + |
| 21 | +# Instalamos Istio |
| 22 | +# Specify the Istio version that will be leveraged throughout these instructions |
| 23 | +$ISTIO_VERSION="1.0.6" |
| 24 | + |
| 25 | +# Windows |
| 26 | +$ProgressPreference = 'SilentlyContinue'; |
| 27 | +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 |
| 28 | +Invoke-WebRequest -URI "https://github.com/istio/istio/releases/download/$ISTIO_VERSION/istio-$ISTIO_VERSION-win.zip" -OutFile "istio-$ISTIO_VERSION.zip" |
| 29 | +Remove-Item istio-$ISTIO_VERSION -Recurse -ErrorAction Ignore |
| 30 | +Expand-Archive -Path "istio-$ISTIO_VERSION.zip" -DestinationPath . |
| 31 | + |
| 32 | +if($installIstioOnSystem -eq $true) { |
| 33 | + New-Item -ItemType Directory -Force -Path "C:\Program Files\Istio" |
| 34 | + mv ./istio-$ISTIO_VERSION/bin/istioctl.exe "C:\Program Files/Istio/" |
| 35 | + $PATH = [environment]::GetEnvironmentVariable("PATH", "User") |
| 36 | + [environment]::SetEnvironmentVariable("PATH", $PATH + "; C:\Program Files\Istio", "User") |
| 37 | +} |
| 38 | +# Primero Desinstalamos cualquier cosa que haya en el cluster |
| 39 | +if ($clean -eq $true) { |
| 40 | + Write-Host "Cleaning previous helm releases..." -ForegroundColor Green |
| 41 | + helm delete --purge $(helm ls -q) |
| 42 | + kubectl delete -f istio-$ISTIO_VERSION/install/kubernetes/helm/istio/templates/crds.yaml -n istio-system |
| 43 | + Write-Host "Previous releases deleted" -ForegroundColor Green |
| 44 | +} |
| 45 | + |
| 46 | +Write-Host "Generating Kiali Credentials" -ForegroundColor Green |
| 47 | +#generamos la credenciales para que kiali arranque sin problemas |
| 48 | +kubectl -n istio-system create secret generic kiali --from-literal=username=$kialiuser --from-literal=passphrase=$kialipasswrd |
| 49 | + |
| 50 | + |
| 51 | +Write-Host "Deploying Istio in the cluster" -ForegroundColor Green |
| 52 | +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 |
| 53 | + |
| 54 | +Write-Host "Setting Up Gateway" |
| 55 | +kubectl delete gateway istio-autogenerated-k8s-ingress -n istio-system |
| 56 | +kubectl apply -f ./istio/gateway.yml |
| 57 | + |
| 58 | +if ($useLocalk8s -eq $true) { |
| 59 | + $dns="localhost" |
| 60 | +} |
| 61 | +else { |
| 62 | + Write-Host "Resolving DNS to Gateway public IP" -ForegroundColor Green |
| 63 | + $ipaddress = $(kubectl get service istio-ingressgateway -n istio-system)[1] | %{ $_.Split(' ')[9];} |
| 64 | + $query = "[?ipAddress!=null]|[?contains([ipAddress], '$ipaddress')].[id]" |
| 65 | + $resid = az network public-ip list --query $query --output tsv |
| 66 | + $jsonresponse = az network public-ip update --ids $resid --dns-name $dnsname |
| 67 | + $externalDns = ($jsonresponse | ConvertFrom-Json).dnsSettings.fqdn |
| 68 | + Write-Host "$externalDns is pointing to Cluster public ip $ipaddress" |
| 69 | +} |
| 70 | + |
| 71 | +$useCustomRegistry=$false |
| 72 | +if (-not [string]::IsNullOrEmpty($registry)) { |
| 73 | + $useCustomRegistry=$true |
| 74 | + if ([string]::IsNullOrEmpty($dockerUser) -or [string]::IsNullOrEmpty($dockerPassword)) { |
| 75 | + Write-Host "Error: Must use -dockerUser AND -dockerPassword if specifying custom registry" -ForegroundColor Red |
| 76 | + exit 1 |
| 77 | + } |
| 78 | +} |
| 79 | +Write-Host "Begin eShopOnContainers installation using Helm" -ForegroundColor Green |
| 80 | + |
| 81 | +$infras = ("sql-data", "nosql-data", "rabbitmq", "keystore-data", "basket-data") |
| 82 | +$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") |
| 83 | + |
| 84 | +if ($deployInfrastructure) { |
| 85 | + foreach ($infra in $infras) { |
| 86 | + Write-Host "Installing infrastructure: $infra" -ForegroundColor Green |
| 87 | + helm install --values app.yaml --values inf.yaml --set app.name=$appName --set inf.k8s.dns=$externalDns --name="$appName-$infra" $infra |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +foreach ($chart in $charts) { |
| 92 | + Write-Host "Installing: $chart" -ForegroundColor Green |
| 93 | + if ($useCustomRegistry) { |
| 94 | + 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 |
| 95 | + } |
| 96 | + else { |
| 97 | + if ($chart -ne "eshop-common") { # eshop-common is ignored when no secret must be deployed |
| 98 | + 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 |
| 99 | + } |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +Write-Host "helm charts installed." -ForegroundColor Green |
| 104 | +Write-Host "Appling Virtual Services for routing." -ForegroundColor Green |
| 105 | +kubectl apply -f ./istio/virtualservices.yml |
| 106 | + |
| 107 | +Remove-Item istio-$ISTIO_VERSION -Recurse -ErrorAction Ignore |
| 108 | +Remove-Item istio-$ISTIO_VERSION.zip -Recurse -ErrorAction Ignore |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
0 commit comments