Advertisement
Guest User

Untitled

a guest
Jul 26th, 2021
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.16 KB | None | 0 0
  1. #!/bin/bash
  2. set -v
  3.  
  4. #------------------------------------------
  5.  
  6. install_az=1 #0 true, 1 false
  7. #echo_or_execute=echo
  8. #echo_or_execute=''
  9. echo_or_execute_conn=''
  10. echo_or_execute_features=''
  11. echo_or_execute_ext=''
  12. echo_or_execute_customloc=''
  13. echo_or_execute_appsvc=''
  14.  
  15. MySubscription=fc874319-2389-4xxxxxxxxxxxxxxxx
  16. #MySubscription=14349cf0-21fb-xxxxxxxxxxxxxx
  17.  
  18.  
  19. groupName="poc-eu-west"
  20. resourceGroupName=$groupName
  21. resourceLocation="westeurope" # "eastus" or "westeurope"
  22. clusterName=test-arc-cluster-node1
  23.  
  24. extensionName="appservice-ext-node1-v1" # Name of the App Service extension
  25. namespace="appservice-ns-node1-v1" # Namespace in your cluster to install the extension and provision resources
  26. kubeEnvironmentName=$clusterName # Name of the App Service Kubernetes environment resource
  27. staticIp=20.67.115.34
  28.  
  29. customLocationName="k8s-k3s-poc-node1" # Name of the custom location
  30.  
  31. storage_account_name=pocuadama1234
  32. app_svc_plan_name=app-svc-client-plan-node1
  33. logicAppName=la-node1-poc
  34.  
  35. #------------------------------------------
  36.  
  37.  
  38. az account set --subscription $MySubscription
  39.  
  40. #az group create --name $groupName \
  41. # --subscription 14349cf0-2zzzzzzzzzzzzzzzzzzzzz \
  42. # --location westeurope
  43.  
  44. #------------------------------------------
  45.  
  46. #arc enabled k8s (external)
  47. #https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster?tabs=azure-cli
  48.  
  49. if [ $install_az == 0 ]; then
  50. az provider register --namespace Microsoft.Kubernetes
  51. az provider register --namespace Microsoft.KubernetesConfiguration
  52. az provider register --namespace Microsoft.ExtendedLocation
  53. az provider show -n Microsoft.Kubernetes -o table
  54. az provider show -n Microsoft.KubernetesConfiguration -o table
  55. az provider show -n Microsoft.ExtendedLocation -o table
  56. fi
  57.  
  58. #############################
  59. ## Create cluster connection
  60. #############################
  61. #TODO auto-download
  62. #here need .kube/config to allow access to cluster, take it eg from /etc/rancher/k3s/k3s.yaml
  63. #------------------------------------------
  64. ssh $staticIp -l ubuntu -i ~/.ssh/example_key 'sudo chmod o+r /etc/rancher/k3s/k3s.yaml'
  65. scp -i ~/.ssh/example_key ubuntu@$staticIp:/etc/rancher/k3s/k3s.yaml ~/.kube/config
  66. sed -i s,127.0.0.1,$staticIp,g ~/.kube/config
  67. #------------------------------------------
  68.  
  69. $echo_or_execute_conn az connectedk8s connect --name $clusterName --resource-group $groupName
  70. az connectedk8s list --resource-group $groupName --output table
  71.  
  72. #------------------------------------------
  73.  
  74. #custom location enable
  75. #https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/custom-locations#create-custom-location<F12>
  76. if [ $install_az == 0 ]; then
  77. az extension add --name connectedk8s
  78. az extension add --name k8s-extension
  79. az extension add --name customlocation
  80. az provider register --namespace Microsoft.ExtendedLocation
  81. az provider show -n Microsoft.ExtendedLocation -o table
  82. fi
  83.  
  84. #############################
  85. ## Cluster features
  86. #############################
  87. #$echo_or_execute_features az connectedk8s enable-features -n $clusterName -g $groupName --features cluster-connect custom-locations
  88.  
  89. ##same command for SP
  90. objectId=$(az ad sp show --id 'bc313c14-388c-4e7d-a58e-70017303ee3b' --query objectId -o tsv)
  91. az connectedk8s enable-features -n $clusterName -g $groupName --custom-locations-oid $objectId --features cluster-connect custom-locations
  92.  
  93.  
  94. #------------------------------------------
  95. ##now create arc extention
  96. #https://docs.microsoft.com/en-us/azure/app-service/manage-create-arc-environment#install-the-app-service-extension
  97.  
  98. if [ $install_az == 0 ]; then
  99. az extension add --upgrade --yes --name connectedk8s
  100. az extension add --upgrade --yes --name k8s-extension
  101. az extension add --upgrade --yes --name customlocation
  102. az provider register --namespace Microsoft.ExtendedLocation --wait
  103. az provider register --namespace Microsoft.Web --wait
  104. az provider register --namespace Microsoft.KubernetesConfiguration --wait
  105. az extension remove --name appservice-kube
  106. az extension add --yes --source "https://aka.ms/appsvc/appservice_kube-latest-py2.py3-none-any.whl"
  107. fi
  108.  
  109.  
  110. #############################
  111. ## k8s estension
  112. #############################
  113. $echo_or_execute_ext az k8s-extension create \
  114. --resource-group $groupName \
  115. --name $extensionName \
  116. --cluster-type connectedClusters \
  117. --cluster-name $clusterName \
  118. --extension-type 'Microsoft.Web.Appservice' \
  119. --release-train stable \
  120. --auto-upgrade-minor-version true \
  121. --scope cluster \
  122. --release-namespace $namespace \
  123. --configuration-settings "Microsoft.CustomLocation.ServiceAccount=default" \
  124. --configuration-settings "appsNamespace=${namespace}" \
  125. --configuration-settings "clusterName=${kubeEnvironmentName}" \
  126. --configuration-settings "loadBalancerIp=${staticIp}" \
  127. --configuration-settings "buildService.storageClassName=local-path" \
  128. --configuration-settings "buildService.storageAccessMode=ReadWriteOnce" \
  129. --configuration-settings "keda.enabled=true"
  130. ### --configuration-settings "keda.enabled=true" \
  131. ### --configuration-settings "buildService.storageClassName=default" \
  132. ### --configuration-settings "buildService.storageAccessMode=ReadWriteOnce" \
  133. ### --configuration-settings "customConfigMap=${namespace}/kube-environment-config" \
  134. ### --configuration-settings "envoy.annotations.service.beta.kubernetes.io/azure-load-balancer-resource-group=${aksClusterGroupName}" \
  135. ### --configuration-settings "logProcessor.appLogs.destination=log-analytics" \
  136. ### --configuration-protected-settings "logProcessor.appLogs.logAnalyticsConfig.customerId=${logAnalyticsWorkspaceIdEnc}" \
  137. ### --configuration-protected-settings "logProcessor.appLogs.logAnalyticsConfig.sharedKey=${logAnalyticsKeyEnc}"
  138. #
  139. #
  140. ##TODO
  141. ##appservice-ns svclb-appservice-ext-k8se-envoy-rmzm8
  142. ##1 node(s) didn't have free ports for the requested pod ports.
  143. #
  144. ##traefik LoadBalancer 10.43.29.229 <pending> web:81►30757 websecure:444►30674
  145. ##appservice-ext-k8se-envoy LoadBalancer 10.43.142.26 20.101.129.153 http:80►32547 https:443►32365 internal-http:8081►30661
  146. #
  147. extensionId=$(az k8s-extension show \
  148. --cluster-type connectedClusters \
  149. --cluster-name $clusterName \
  150. --resource-group $groupName \
  151. --name $extensionName \
  152. --query id \
  153. --output tsv)
  154.  
  155. echo $extensionId
  156.  
  157. az resource wait --ids $extensionId --custom "properties.installState!='Pending'" --api-version "2020-07-01-preview"
  158.  
  159. #------------------------------------------
  160.  
  161.  
  162. ##custom location create
  163. #https://docs.microsoft.com/en-us/azure/app-service/manage-create-arc-environment#create-a-custom-location
  164. connectedClusterId=$(az connectedk8s show --resource-group $groupName --name $clusterName --query id --output tsv)
  165.  
  166. #############################
  167. ## k8s extension
  168. #############################
  169. $echo_or_execute_customloc az customlocation create \
  170. --resource-group $groupName \
  171. --name $customLocationName \
  172. --host-resource-id $connectedClusterId \
  173. --namespace $namespace \
  174. --cluster-extension-ids $extensionId
  175.  
  176. az customlocation show \
  177. --resource-group $groupName \
  178. --name $customLocationName
  179.  
  180. customLocationId=$(az customlocation show \
  181. --resource-group $groupName \
  182. --name $customLocationName \
  183. --query id \
  184. --output tsv)
  185.  
  186. #------------------------------------------
  187. #############################
  188. ## appservice
  189. #############################
  190. ###https://docs.microsoft.com/en-us/azure/app-service/manage-create-arc-environment#create-the-app-service-kubernetes-environment
  191. $echo_or_execute_appsvc az appservice kube create \
  192. --resource-group $groupName \
  193. --name $kubeEnvironmentName-app-svc \
  194. --custom-location $customLocationId \
  195. --static-ip $staticIp
  196.  
  197. az appservice kube show \
  198. --resource-group $groupName \
  199. --name $kubeEnvironmentName-app-svc
  200.  
  201.  
  202. #------------------------------------------
  203.  
  204. ##functions
  205. ##https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-arc-cli?tabs=csharp%2Cbrowser#create-storage-account
  206. #############################
  207. ## storage
  208. #############################
  209. az storage account create --name $storage_account_name --location westeurope --resource-group $groupName --sku Standard_LRS
  210.  
  211. #------------------------------------------
  212. #############################
  213. ## functions
  214. #############################
  215. ##logicapp
  216. ##https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-arc-cli?tabs=csharp%2Cbrowser#create-storage-account
  217. if [ $install_az == 0 ]; then
  218. az extension add --yes --source "https://aka.ms/logicapp-latest-py2.py3-none-any.whl"
  219. fi
  220. #------------------------------------------
  221.  
  222. echo az logicapp create --name $logicAppName \
  223. --resource-group $groupName --subscription $MySubscription \
  224. --storage-account $storage_account_name --custom-location $customLocationId
  225.  
  226. az logicapp create --name $logicAppName \
  227. --resource-group $groupName --subscription $MySubscription \
  228. --storage-account $storage_account_name --custom-location $customLocationId
  229.  
  230. #------------------------------------------
  231.  
  232. az appservice plan create -g $groupName -n $app_svc_plan_name \
  233. --custom-location $customLocationId \
  234. --per-site-scaling --is-linux --sku K1
  235.  
  236. az webapp create \
  237. --plan $app_svc_plan_name \
  238. --resource-group $groupName \
  239. --name appzip-node1 \
  240. --custom-location $customLocationId \
  241. --runtime "NODE|12-lts"
  242.  
  243. git clone https://github.com/Azure-Samples/nodejs-docs-hello-world
  244. cd nodejs-docs-hello-world
  245. zip -r package.zip .
  246. az webapp deployment source config-zip --resource-group $groupName --name appzip-node1 --src package.zip
  247. cd -
  248.  
  249. az webapp create \
  250. --plan $app_svc_plan_name \
  251. --resource-group $groupName \
  252. --name app-two-node1 \
  253. --custom-location $customLocationId \
  254. --deployment-container-image-name mcr.microsoft.com/appsvc/node:12-lts
  255. #--name test-app2 \ #TODO bug - no test in the app name or it would fail
  256.  
  257.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement