Browse Source

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.
pull/1092/head
Carlos Milán Figueredo 5 years ago
parent
commit
93c86fc33e
1 changed files with 27 additions and 13 deletions
  1. +27
    -13
      k8s/helm/deploy-all.sh

+ 27
- 13
k8s/helm/deploy-all.sh View File

@ -42,17 +42,18 @@ Parameters:
The Docker username used to logon to the custom registry, supplied using the -r parameter. The Docker username used to logon to the custom registry, supplied using the -r parameter.
--use-local-k8s --use-local-k8s
Deploy to a locally installed Kubernetes (default: false). Deploy to a locally installed Kubernetes (default: false).
--namespace <namespace name>
Specifies the namespace name to deploy the app. If it doesn't exists it will be created (default: eshop).
It is assumed that the Kubernetes cluster has been granted access to the container registry. It is assumed that the Kubernetes cluster has been granted access to the container registry.
If using AKS and ACR see link for more info: If using AKS and ACR see link for more info:
https://docs.microsoft.com/en-us/azure/container-registry/container-registry-auth-aks https://docs.microsoft.com/en-us/azure/container-registry/container-registry-auth-aks
WARNING! THE SCRIPT WILL COMPLETELY DESTROY ALL DEPLOYMENTS AND SERVICES VISIBLE WARNING! THE SCRIPT WILL COMPLETELY DESTROY ALL DEPLOYMENTS AND SERVICES VISIBLE
FROM THE CURRENT CONFIGURATION CONTEXT.
It is recommended that you create a separate namespace and confguration context
for the $app_name application, to isolate it from other applications on the cluster.
FROM THE CURRENT CONFIGURATION CONTEXT AND NAMESPACE.
It is recommended that you check your selected namespace, 'eshop' by default, is already in use.
Every deployment and service done in the namespace will be deleted.
For more information see https://kubernetes.io/docs/tasks/administer-cluster/namespaces/ For more information see https://kubernetes.io/docs/tasks/administer-cluster/namespaces/
You can use namespace.yaml file (in the same directory) to create the namespace.
END END
} }
@ -71,6 +72,7 @@ image_tag=$(date '+%Y%m%d%H%M')
push_images='yes' push_images='yes'
skip_infrastructure='' skip_infrastructure=''
use_local_k8s='' use_local_k8s=''
namespace='eshop'
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
@ -104,6 +106,8 @@ while [[ $# -gt 0 ]]; do
docker_username="$2"; shift 2;; docker_username="$2"; shift 2;;
--use-local-k8s ) --use-local-k8s )
use_local_k8s='yes'; shift ;; use_local_k8s='yes'; shift ;;
--namespace )
namespace="$2"; shift 2;;
*) *)
echo "Unknown option $1" echo "Unknown option $1"
usage; exit 2 ;; usage; exit 2 ;;
@ -169,13 +173,19 @@ if [[ $dns == "aks" ]]; then
exit 1 exit 1
fi fi
echo "Getting DNS of AKS of AKS $aks_name (in resource group $aks_rg)"
dns="$(az aks show -n $aks_name -g $aks_rg --query addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName)"
if [[ -z dns ]]; then
echo "Getting AKS cluster $aks_name AKS (in resource group $aks_rg)"
# JMESPath queries are case sensitive and httpapplicationrouting can be lowercase sometimes
jmespath_dnsqueries=(addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName \
addonProfiles.httpapplicationrouting.config.HTTPApplicationRoutingZoneName)
for q in "${jmespath_dnsqueries[@]}"
do
dns="$(az aks show -n $aks_name -g $aks_rg --query $q -o tsv)"
if [[ -n $dns ]]; then break; fi
done
if [[ -z $dns ]]; then
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." 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."
exit 1 exit 1
fi fi
$dns=${dns//[\"]/""}
echo "DNS base found is $dns. Will use $aks_name.$dns for the app!" echo "DNS base found is $dns. Will use $aks_name.$dns for the app!"
fi fi
@ -186,8 +196,12 @@ fi
if [[ $clean ]]; then if [[ $clean ]]; then
echo "Cleaning previous helm releases..." echo "Cleaning previous helm releases..."
helm delete --purge $(helm ls -q)
echo "Previous releases deleted"
if [[ -z $(helm ls -q --namespace $namespace) ]]; then
echo "No previous releases found"
else
helm delete --purge $(helm ls -q --namespace $namespace)
echo "Previous releases deleted"
fi
fi fi
echo "#################### Begin $app_name installation using Helm ####################" echo "#################### Begin $app_name installation using Helm ####################"
@ -198,7 +212,7 @@ if [[ !$skip_infrastructure ]]; then
for infra in "${infras[@]}" for infra in "${infras[@]}"
do do
echo "Installing infrastructure: $infra" echo "Installing infrastructure: $infra"
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
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
done done
fi fi
@ -206,9 +220,9 @@ for chart in "${charts[@]}"
do do
echo "Installing: $chart" echo "Installing: $chart"
if [[ $use_custom_registry ]]; then if [[ $use_custom_registry ]]; then
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
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
elif [[ $chart != "eshop-common" ]]; then # eshop-common is ignored when no secret must be deployed elif [[ $chart != "eshop-common" ]]; then # eshop-common is ignored when no secret must be deployed
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
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
fi fi
done done


Loading…
Cancel
Save