@@ -6,13 +6,44 @@ param (
66 [Parameter ()]
77 [string ]$TAG = " latest" ,
88 [Parameter ()]
9- [string ]$HOSTURL = " pygoat-test.cad4devops.com"
9+ [string ]$dnsResourceGroupName = " rg-dns-prod" ,
10+ [Parameter ()]
11+ [string ]$dnsZoneName = " cad4devops.com" ,
12+ [Parameter ()]
13+ [ValidateSet (" " , " -dev" , " -test" )]
14+ [string ]$environmentSuffix = " -test" , # "-dev", "-test", ""
15+ [Parameter ()]
16+ [string ]$dnsRecordSetName = " pygoat${environmentSuffix} " ,
17+ [Parameter ()]
18+ [string ]$HOSTURL = " ${dnsRecordSetName} .${dnsZoneName} " ,
19+ [Parameter ()]
20+ [string ]$serviceName = " pygoat-svc" ,
21+ [Parameter ()]
22+ [string ]$namespace = " pygoat${environmentSuffix} " ,
23+ [Parameter ()]
24+ [string ]$subscriptionId = " Microsoft Azure Sponsorship"
1025)
1126# docker pull devopsshield/devsecops-pygoat:latest
1227
1328# echo parameters
1429Write-Host " manifestTemplateFolder: $manifestTemplateFolder "
30+ Write-Host " IMAGE: $IMAGE "
31+ Write-Host " TAG: $TAG "
32+ Write-Host " HOSTURL: $HOSTURL "
33+ Write-Host " serviceName: $serviceName "
34+ Write-Host " namespace: $namespace "
35+ Write-Host " dnsResourceGroupName: $dnsResourceGroupName "
36+ Write-Host " dnsZoneName: $dnsZoneName "
37+ Write-Host " dnsRecordSetName: $dnsRecordSetName "
38+ Write-Host " subscriptionId: $subscriptionId "
39+ Write-Host " environmentSuffix: $environmentSuffix "
40+
41+
42+ # create a namespace if it does not exist
43+ Write-Output " Creating namespace $namespace if it does not exist"
44+ kubectl create namespace $namespace -- dry- run= client - o yaml | kubectl apply -f -
1545
46+ # deploy k8s manifests
1647Write-Output " Deploying k8s manifests in folder $manifestTemplateFolder "
1748
1849# loop through each manifest file in the folder with extension template.yaml
@@ -31,5 +62,75 @@ foreach ($manifestFile in $manifestFiles) {
3162 Write-Output " Writing processed manifest file $newManifestFile "
3263 Set-Content - Path $newManifestFile - Value $manifestFileContent
3364 # apply the manifest file
34- kubectl apply -f $manifestFile.FullName
35- }
65+ Write-Output " Applying manifest file $newManifestFile "
66+ kubectl apply -f $manifestFile.FullName -- namespace $namespace
67+ }
68+
69+ Write-Output " Finished deploying k8s manifests"
70+
71+ # get the external IP address of the service
72+ $service = kubectl get service $serviceName -- namespace $namespace - o json | ConvertFrom-Json
73+ $externalIp = $service.status.loadBalancer.ingress [0 ].ip
74+ Write-Output " External IP address of the service $serviceName is $externalIp "
75+
76+ # get all pods in the namespace
77+ $pods = kubectl get pods -- namespace $namespace
78+ Write-Output " Pods in namespace ${namespace} :"
79+ Write-Output $pods
80+
81+ # now get all
82+ Write-Output " Getting all resources in namespace $namespace "
83+ kubectl get all -- namespace $namespace
84+
85+ # give instructions to access the service
86+ Write-Output " To access the service, open a web browser and go to http://$externalIp "
87+
88+ # open a web browser
89+ Write-Output " Opening a web browser to http://$externalIp "
90+ Start-Process " http://$externalIp "
91+
92+ # create a DNS record for the service in Azure DNS
93+ Write-Output " Creating a DNS record for the service in Azure DNS"
94+
95+ # login to Azure
96+ Write-Output " Logging in to Azure"
97+ az login
98+
99+ # set subscription
100+ Write-Output " Setting subscription to $subscriptionId "
101+ az account set -- subscription " $subscriptionId "
102+
103+ # show the current subscription
104+ Write-Output " Current subscription:"
105+ az account show
106+
107+ Write-Output " Creating DNS record set $dnsRecordSetName in zone $dnsZoneName in resource group $dnsResourceGroupName "
108+ # delete the existing DNS record set if it exists
109+ Write-Output " Deleting existing DNS record set $dnsRecordSetName in zone $dnsZoneName in resource group $dnsResourceGroupName "
110+ az network dns record- set a delete `
111+ -- resource- group $dnsResourceGroupName `
112+ -- zone- name $dnsZoneName `
113+ -- name $dnsRecordSetName `
114+ -- yes
115+ Write-Output " DNS record set $dnsRecordSetName deleted in zone $dnsZoneName in resource group $dnsResourceGroupName "
116+ az network dns record- set a create `
117+ -- resource- group $dnsResourceGroupName `
118+ -- name $dnsRecordSetName `
119+ -- zone- name $dnsZoneName
120+ Write-Output " DNS record set $dnsRecordSetName created in zone $dnsZoneName in resource group $dnsResourceGroupName "
121+ az network dns record- set a add-record `
122+ -- resource- group $dnsResourceGroupName `
123+ -- zone- name $dnsZoneName `
124+ -- record- set-name $dnsRecordSetName `
125+ -- ipv4- address $externalIp
126+
127+ Write-Output " DNS record set $dnsRecordSetName created in zone $dnsZoneName in resource group $dnsResourceGroupName "
128+
129+ Write-Output " Finished creating DNS record set"
130+
131+ # test the DNS record
132+ Write-Output " Testing the DNS record"
133+
134+ # open a web browser
135+ Write-Output " Opening a web browser to http://$HOSTURL "
136+ Start-Process " http://$HOSTURL "
0 commit comments