Updated k8s deploy script
This commit is contained in:
parent
867afa3df4
commit
81b8950ced
@ -3,16 +3,24 @@ Param(
|
|||||||
[parameter(Mandatory=$false)][string]$dockerUser,
|
[parameter(Mandatory=$false)][string]$dockerUser,
|
||||||
[parameter(Mandatory=$false)][string]$dockerPassword,
|
[parameter(Mandatory=$false)][string]$dockerPassword,
|
||||||
[parameter(Mandatory=$false)][bool]$deployCI,
|
[parameter(Mandatory=$false)][bool]$deployCI,
|
||||||
[parameter(Mandatory=$false)][string]$execPath
|
[parameter(Mandatory=$false)][bool]$useDockerHub,
|
||||||
|
[parameter(Mandatory=$false)][string]$execPath,
|
||||||
|
[parameter(Mandatory=$false)][string]$kubeconfigPath
|
||||||
)
|
)
|
||||||
|
|
||||||
$kubectl_exec = 'kubectl';
|
function ExecKube($cmd) {
|
||||||
|
if($deployCI) {
|
||||||
if(-not [string]::IsNullOrEmpty($execPath)) {
|
$kubeconfig = $kubeconfigPath + 'config';
|
||||||
$kubectl_exec = $execPath + '/' + 'kubectl';
|
$exp = $execPath + 'kubectl ' + $cmd + ' --kubeconfig=' + $kubeconfig
|
||||||
|
Invoke-Expression $exp
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$exp = $execPath + 'kubectl ' + $cmd
|
||||||
|
Invoke-Expression $exp
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Not using ACR when deploying through CI VSTS
|
# Check command paths only for manual deployment
|
||||||
if(-not $deployCI) {
|
if(-not $deployCI) {
|
||||||
$requiredCommands = ("docker", "docker-compose", "kubectl")
|
$requiredCommands = ("docker", "docker-compose", "kubectl")
|
||||||
foreach ($command in $requiredCommands) {
|
foreach ($command in $requiredCommands) {
|
||||||
@ -21,7 +29,10 @@ if(-not $deployCI) {
|
|||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Use ACR instead of DockerHub as image repository
|
||||||
|
if(-not $useDockerHub) {
|
||||||
Write-Host "Logging in to $registry" -ForegroundColor Yellow
|
Write-Host "Logging in to $registry" -ForegroundColor Yellow
|
||||||
docker login -u $dockerUser -p $dockerPassword $registry
|
docker login -u $dockerUser -p $dockerPassword $registry
|
||||||
if (-not $LastExitCode -eq 0) {
|
if (-not $LastExitCode -eq 0) {
|
||||||
@ -30,17 +41,17 @@ if(-not $deployCI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# create registry key secret
|
# create registry key secret
|
||||||
& $kubectl_exec create secret docker-registry registry-key `
|
ExecKube -cmd 'create secret docker-registry registry-key `
|
||||||
--docker-server=$registry `
|
--docker-server=$registry `
|
||||||
--docker-username=$dockerUser `
|
--docker-username=$dockerUser `
|
||||||
--docker-password=$dockerPassword `
|
--docker-password=$dockerPassword `
|
||||||
--docker-email=not@used.com
|
--docker-email=not@used.com'
|
||||||
}
|
}
|
||||||
|
|
||||||
# start sql, rabbitmq, frontend deployments
|
# start sql, rabbitmq, frontend deployments
|
||||||
& $kubectl_exec create configmap config-files --from-file=nginx-conf=nginx.conf
|
ExecKube -cmd 'create configmap config-files --from-file=nginx-conf=nginx.conf'
|
||||||
& $kubectl_exec label configmap config-files app=eshop
|
ExecKube -cmd 'label configmap config-files app=eshop'
|
||||||
& $kubectl_exec create -f sql-data.yaml -f rabbitmq.yaml -f services.yaml -f frontend.yaml
|
ExecKube -cmd 'create -f sql-data.yaml -f rabbitmq.yaml -f services.yaml -f frontend.yaml'
|
||||||
|
|
||||||
# building and publishing docker images not necessary when deploying through CI VSTS
|
# building and publishing docker images not necessary when deploying through CI VSTS
|
||||||
if(-not $deployCI) {
|
if(-not $deployCI) {
|
||||||
@ -61,38 +72,39 @@ if(-not $deployCI) {
|
|||||||
|
|
||||||
Write-Host "Waiting for frontend's external ip..." -ForegroundColor Yellow
|
Write-Host "Waiting for frontend's external ip..." -ForegroundColor Yellow
|
||||||
while ($true) {
|
while ($true) {
|
||||||
$frontendUrl = & $kubectl_exec get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"
|
$frontendUrl = & ExecKube -cmd 'get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"'
|
||||||
if ([bool]($frontendUrl -as [ipaddress])) {
|
if ([bool]($frontendUrl -as [ipaddress])) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
Start-Sleep -s 15
|
Start-Sleep -s 15
|
||||||
}
|
}
|
||||||
|
|
||||||
& $kubectl_exec create configmap urls `
|
ExecKube -cmd 'create configmap urls `
|
||||||
--from-literal=BasketUrl=http://$($frontendUrl)/basket-api `
|
--from-literal=BasketUrl=http://$($frontendUrl)/basket-api `
|
||||||
--from-literal=CatalogUrl=http://$($frontendUrl)/catalog-api `
|
--from-literal=CatalogUrl=http://$($frontendUrl)/catalog-api `
|
||||||
--from-literal=IdentityUrl=http://$($frontendUrl)/identity `
|
--from-literal=IdentityUrl=http://$($frontendUrl)/identity `
|
||||||
--from-literal=OrderingUrl=http://$($frontendUrl)/ordering-api `
|
--from-literal=OrderingUrl=http://$($frontendUrl)/ordering-api `
|
||||||
--from-literal=MvcClient=http://$($frontendUrl)/webmvc `
|
--from-literal=MvcClient=http://$($frontendUrl)/webmvc `
|
||||||
--from-literal=SpaClient=http://$($frontendUrl)
|
--from-literal=SpaClient=http://$($frontendUrl)'
|
||||||
& $kubectl_exec label configmap urls app=eshop
|
|
||||||
|
ExecKube -cmd 'label configmap urls app=eshop'
|
||||||
|
|
||||||
Write-Host "Creating deployments..."
|
Write-Host "Creating deployments..."
|
||||||
& $kubectl_exec apply -f deployments.yaml
|
ExecKube -cmd 'apply -f deployments.yaml'
|
||||||
|
|
||||||
# not using ACR for pulling images when deploying through CI VSTS
|
# use ACR registry for pulling images if docker hub is not specified
|
||||||
if(-not $deployCI) {
|
if(-not $useDockerHub) {
|
||||||
# update deployments with the private registry before k8s tries to pull images
|
# update deployments with the private registry before k8s tries to pull images
|
||||||
# (deployment templating, or Helm, would obviate this)
|
# (deployment templating, or Helm, would obviate this)
|
||||||
& $kubectl_exec set image -f deployments.yaml `
|
ExecKube -cmd 'set image -f deployments.yaml `
|
||||||
basket=$registry/eshop/basket.api `
|
basket=$registry/eshop/basket.api `
|
||||||
catalog=$registry/eshop/catalog.api `
|
catalog=$registry/eshop/catalog.api `
|
||||||
identity=$registry/eshop/identity.api `
|
identity=$registry/eshop/identity.api `
|
||||||
ordering=$registry/eshop/ordering.api `
|
ordering=$registry/eshop/ordering.api `
|
||||||
webmvc=$registry/eshop/webmvc `
|
webmvc=$registry/eshop/webmvc `
|
||||||
webspa=$registry/eshop/webspa
|
webspa=$registry/eshop/webspa'
|
||||||
}
|
}
|
||||||
|
|
||||||
& $kubectl_exec rollout resume -f deployments.yaml
|
ExecKube -cmd 'rollout resume -f deployments.yaml'
|
||||||
|
|
||||||
Write-Host "WebSPA is exposed at http://$frontendUrl, WebMVC at http://$frontendUrl/webmvc" -ForegroundColor Yellow
|
Write-Host "WebSPA is exposed at http://$frontendUrl, WebMVC at http://$frontendUrl/webmvc" -ForegroundColor Yellow
|
||||||
|
Loading…
x
Reference in New Issue
Block a user