functions/helm/InstallLoadBalancerHelmPackage.ps1

<#
  .SYNOPSIS
  InstallLoadBalancerHelmPackage
 
  .DESCRIPTION
  InstallLoadBalancerHelmPackage
 
  .INPUTS
  InstallLoadBalancerHelmPackage - The name of InstallLoadBalancerHelmPackage
 
  .OUTPUTS
  None
 
  .EXAMPLE
  InstallLoadBalancerHelmPackage
 
  .EXAMPLE
  InstallLoadBalancerHelmPackage
 
 
#>

function InstallLoadBalancerHelmPackage() {
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]
        $ExternalIP
        ,
        [Parameter(Mandatory = $true, HelpMessage="Set this if you want to put the external load balancer in a subnet")]
        [AllowEmptyString()]
        [string]
        $ExternalSubnet
        ,
        [Parameter(Mandatory = $true)]
        [AllowEmptyString()]
        [string]
        $InternalIP
        ,
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]
        $InternalSubnet
    )

    Write-Verbose 'InstallLoadBalancerHelmPackage: Starting'

    [string] $package = "nginx"
    [string] $packageInternal = "nginx-internal"
    [string] $ngniximageTag = "0.20.0"

    Write-Output "Removing old deployment"
    helm del --purge $package
    helm del --purge $packageInternal

    Start-Sleep -Seconds 5

    # nginx configuration: https://github.com/helm/charts/tree/master/stable/nginx-ingress#configuration

    Write-Verbose "Installing the public nginx load balancer"
    helm install stable/nginx-ingress `
        --namespace "kube-system" `
        --name "$package" `
        --set controller.stats.enabled=true `
        --set controller.extraArgs.enable-ssl-passthrough=""  `
        --set controller.image.tag="$ngniximageTag" `
        --set controller.service.loadBalancerIP="$ExternalIP" `
        --set-string controller.service.labels."$($globals.externalLoadBalancerLabel)"='"'$($globals.externalLoadBalancerLabelValue)'"'

    # setting values in helm: https://github.com/helm/helm/blob/master/docs/chart_best_practices/values.md
    # and https://github.com/helm/helm/blob/master/docs/using_helm.md
    # use "helm inspect values" to see values

    Write-Verbose "Installing the internal nginx load balancer"
    # NOTE: helm cannot handle spaces before or after "=" in --set command
    helm install stable/nginx-ingress `
        --namespace "kube-system" `
        --name "$packageInternal" `
        --set controller.image.tag="$ngniximageTag" `
        --set-string controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-internal"='"true"' `
        --set-string controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-internal-subnet"='"'$InternalSubnet'"' `
        --set controller.service.loadBalancerIP="$InternalIP" `
        --set-string controller.service.labels."$($globals.internalLoadBalancerLabel)"='"'$($globals.internalLoadBalancerLabelValue)'"'

    Write-Verbose 'InstallLoadBalancerHelmPackage: Done'
}

Export-ModuleMember -Function "InstallLoadBalancerHelmPackage"