Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 93c86fc

Browse files
committed
Default namespace, fixed AKS DNS and Ingress
Several fixes in this commit: * Added 'namespace' argument, default to 'eshop'. * Every Helm command (`helm install` and `helm ls` used with `helm delete`) will honor the namespace parameter. This way this script is no longer destructive with the Kubernetes cluster. Usage() has been updated accordingly. * Custom registry image push didn't honor `--docker-username` and `--docker-password`. A `docker login` has been added to fix the situation. * AKS DNS discovery was not working properly due to case sensitivity with the JMESPath to the HTTPApplicationRouteZoneName. A small two-entries array with iterative loop has been added ton ensure either way the AKS http routing DNS retrieval is successful. * Helm charts were enabled to use Kubernetes Ingress, but the `Ingress.spec.rules.host[]` was not honored with the `$dns` variable. This has been fixed in the `helm install` commands and now the script deploys the Ingress as expected.
1 parent d026eb4 commit 93c86fc

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

k8s/helm/deploy-all.sh

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@ Parameters:
4242
The Docker username used to logon to the custom registry, supplied using the -r parameter.
4343
--use-local-k8s
4444
Deploy to a locally installed Kubernetes (default: false).
45+
--namespace <namespace name>
46+
Specifies the namespace name to deploy the app. If it doesn't exists it will be created (default: eshop).
4547
4648
It is assumed that the Kubernetes cluster has been granted access to the container registry.
4749
If using AKS and ACR see link for more info:
4850
https://docs.microsoft.com/en-us/azure/container-registry/container-registry-auth-aks
4951
5052
WARNING! THE SCRIPT WILL COMPLETELY DESTROY ALL DEPLOYMENTS AND SERVICES VISIBLE
51-
FROM THE CURRENT CONFIGURATION CONTEXT.
52-
It is recommended that you create a separate namespace and confguration context
53-
for the $app_name application, to isolate it from other applications on the cluster.
53+
FROM THE CURRENT CONFIGURATION CONTEXT AND NAMESPACE.
54+
It is recommended that you check your selected namespace, 'eshop' by default, is already in use.
55+
Every deployment and service done in the namespace will be deleted.
5456
For more information see https://kubernetes.io/docs/tasks/administer-cluster/namespaces/
55-
You can use namespace.yaml file (in the same directory) to create the namespace.
5657
5758
END
5859
}
@@ -71,6 +72,7 @@ image_tag=$(date '+%Y%m%d%H%M')
7172
push_images='yes'
7273
skip_infrastructure=''
7374
use_local_k8s=''
75+
namespace='eshop'
7476

7577
while [[ $# -gt 0 ]]; do
7678
case "$1" in
@@ -104,6 +106,8 @@ while [[ $# -gt 0 ]]; do
104106
docker_username="$2"; shift 2;;
105107
--use-local-k8s )
106108
use_local_k8s='yes'; shift ;;
109+
--namespace )
110+
namespace="$2"; shift 2;;
107111
*)
108112
echo "Unknown option $1"
109113
usage; exit 2 ;;
@@ -169,13 +173,19 @@ if [[ $dns == "aks" ]]; then
169173
exit 1
170174
fi
171175

172-
echo "Getting DNS of AKS of AKS $aks_name (in resource group $aks_rg)"
173-
dns="$(az aks show -n $aks_name -g $aks_rg --query addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName)"
174-
if [[ -z dns ]]; then
176+
echo "Getting AKS cluster $aks_name AKS (in resource group $aks_rg)"
177+
# JMESPath queries are case sensitive and httpapplicationrouting can be lowercase sometimes
178+
jmespath_dnsqueries=(addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName \
179+
addonProfiles.httpapplicationrouting.config.HTTPApplicationRoutingZoneName)
180+
for q in "${jmespath_dnsqueries[@]}"
181+
do
182+
dns="$(az aks show -n $aks_name -g $aks_rg --query $q -o tsv)"
183+
if [[ -n $dns ]]; then break; fi
184+
done
185+
if [[ -z $dns ]]; then
175186
echo "Error: when getting DNS of AKS $aks_name (in resource group $aks_rg). Please ensure AKS has httpRouting enabled AND Azure CLI is logged in and is of version 2.0.37 or higher."
176187
exit 1
177188
fi
178-
$dns=${dns//[\"]/""}
179189
echo "DNS base found is $dns. Will use $aks_name.$dns for the app!"
180190
fi
181191

@@ -186,8 +196,12 @@ fi
186196

187197
if [[ $clean ]]; then
188198
echo "Cleaning previous helm releases..."
189-
helm delete --purge $(helm ls -q)
190-
echo "Previous releases deleted"
199+
if [[ -z $(helm ls -q --namespace $namespace) ]]; then
200+
echo "No previous releases found"
201+
else
202+
helm delete --purge $(helm ls -q --namespace $namespace)
203+
echo "Previous releases deleted"
204+
fi
191205
fi
192206

193207
echo "#################### Begin $app_name installation using Helm ####################"
@@ -198,17 +212,17 @@ if [[ !$skip_infrastructure ]]; then
198212
for infra in "${infras[@]}"
199213
do
200214
echo "Installing infrastructure: $infra"
201-
helm install --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --name="$app_name-$infra" $infra
215+
helm install --namespace $namespace --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --name="$app_name-$infra" $infra
202216
done
203217
fi
204218

205219
for chart in "${charts[@]}"
206220
do
207221
echo "Installing: $chart"
208222
if [[ $use_custom_registry ]]; then
209-
helm install --set inf.registry.server=$container_registry --set inf.registry.login=$docker_username --set inf.registry.pwd=$docker_password --set inf.registry.secretName=eshop-docker-scret --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --set image.tag=$image_tag --set image.pullPolicy=Always --name="$app_name-$chart" $chart
223+
helm install --namespace $namespace --set ingress.hosts[0]=$dns --set inf.registry.server=$container_registry --set inf.registry.login=$docker_username --set inf.registry.pwd=$docker_password --set inf.registry.secretName=eshop-docker-scret --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --set image.tag=$image_tag --set image.pullPolicy=Always --name="$app_name-$chart" $chart
210224
elif [[ $chart != "eshop-common" ]]; then # eshop-common is ignored when no secret must be deployed
211-
helm install --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --set image.tag=$image_tag --set image.pullPolicy=Always --name="$app_name-$chart" $chart
225+
helm install --namespace $namespace --set ingress.hosts[0]=$dns --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --set image.tag=$image_tag --set image.pullPolicy=Always --name="$app_name-$chart" $chart
212226
fi
213227
done
214228

0 commit comments

Comments
 (0)