Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -v
- #------------------------------------------
- install_az=1 #0 true, 1 false
- #echo_or_execute=echo
- #echo_or_execute=''
- echo_or_execute_conn=''
- echo_or_execute_features=''
- echo_or_execute_ext=''
- echo_or_execute_customloc=''
- echo_or_execute_appsvc=''
- MySubscription=fc874319-2389-4xxxxxxxxxxxxxxxx
- #MySubscription=14349cf0-21fb-xxxxxxxxxxxxxx
- groupName="poc-eu-west"
- resourceGroupName=$groupName
- resourceLocation="westeurope" # "eastus" or "westeurope"
- clusterName=test-arc-cluster-node1
- extensionName="appservice-ext-node1-v1" # Name of the App Service extension
- namespace="appservice-ns-node1-v1" # Namespace in your cluster to install the extension and provision resources
- kubeEnvironmentName=$clusterName # Name of the App Service Kubernetes environment resource
- staticIp=20.67.115.34
- customLocationName="k8s-k3s-poc-node1" # Name of the custom location
- storage_account_name=pocuadama1234
- app_svc_plan_name=app-svc-client-plan-node1
- logicAppName=la-node1-poc
- #------------------------------------------
- az account set --subscription $MySubscription
- #az group create --name $groupName \
- # --subscription 14349cf0-2zzzzzzzzzzzzzzzzzzzzz \
- # --location westeurope
- #------------------------------------------
- #arc enabled k8s (external)
- #https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster?tabs=azure-cli
- if [ $install_az == 0 ]; then
- az provider register --namespace Microsoft.Kubernetes
- az provider register --namespace Microsoft.KubernetesConfiguration
- az provider register --namespace Microsoft.ExtendedLocation
- az provider show -n Microsoft.Kubernetes -o table
- az provider show -n Microsoft.KubernetesConfiguration -o table
- az provider show -n Microsoft.ExtendedLocation -o table
- fi
- #############################
- ## Create cluster connection
- #############################
- #TODO auto-download
- #here need .kube/config to allow access to cluster, take it eg from /etc/rancher/k3s/k3s.yaml
- #------------------------------------------
- ssh $staticIp -l ubuntu -i ~/.ssh/example_key 'sudo chmod o+r /etc/rancher/k3s/k3s.yaml'
- scp -i ~/.ssh/example_key ubuntu@$staticIp:/etc/rancher/k3s/k3s.yaml ~/.kube/config
- sed -i s,127.0.0.1,$staticIp,g ~/.kube/config
- #------------------------------------------
- $echo_or_execute_conn az connectedk8s connect --name $clusterName --resource-group $groupName
- az connectedk8s list --resource-group $groupName --output table
- #------------------------------------------
- #custom location enable
- #https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/custom-locations#create-custom-location<F12>
- if [ $install_az == 0 ]; then
- az extension add --name connectedk8s
- az extension add --name k8s-extension
- az extension add --name customlocation
- az provider register --namespace Microsoft.ExtendedLocation
- az provider show -n Microsoft.ExtendedLocation -o table
- fi
- #############################
- ## Cluster features
- #############################
- #$echo_or_execute_features az connectedk8s enable-features -n $clusterName -g $groupName --features cluster-connect custom-locations
- ##same command for SP
- objectId=$(az ad sp show --id 'bc313c14-388c-4e7d-a58e-70017303ee3b' --query objectId -o tsv)
- az connectedk8s enable-features -n $clusterName -g $groupName --custom-locations-oid $objectId --features cluster-connect custom-locations
- #------------------------------------------
- ##now create arc extention
- #https://docs.microsoft.com/en-us/azure/app-service/manage-create-arc-environment#install-the-app-service-extension
- if [ $install_az == 0 ]; then
- az extension add --upgrade --yes --name connectedk8s
- az extension add --upgrade --yes --name k8s-extension
- az extension add --upgrade --yes --name customlocation
- az provider register --namespace Microsoft.ExtendedLocation --wait
- az provider register --namespace Microsoft.Web --wait
- az provider register --namespace Microsoft.KubernetesConfiguration --wait
- az extension remove --name appservice-kube
- az extension add --yes --source "https://aka.ms/appsvc/appservice_kube-latest-py2.py3-none-any.whl"
- fi
- #############################
- ## k8s estension
- #############################
- $echo_or_execute_ext az k8s-extension create \
- --resource-group $groupName \
- --name $extensionName \
- --cluster-type connectedClusters \
- --cluster-name $clusterName \
- --extension-type 'Microsoft.Web.Appservice' \
- --release-train stable \
- --auto-upgrade-minor-version true \
- --scope cluster \
- --release-namespace $namespace \
- --configuration-settings "Microsoft.CustomLocation.ServiceAccount=default" \
- --configuration-settings "appsNamespace=${namespace}" \
- --configuration-settings "clusterName=${kubeEnvironmentName}" \
- --configuration-settings "loadBalancerIp=${staticIp}" \
- --configuration-settings "buildService.storageClassName=local-path" \
- --configuration-settings "buildService.storageAccessMode=ReadWriteOnce" \
- --configuration-settings "keda.enabled=true"
- ### --configuration-settings "keda.enabled=true" \
- ### --configuration-settings "buildService.storageClassName=default" \
- ### --configuration-settings "buildService.storageAccessMode=ReadWriteOnce" \
- ### --configuration-settings "customConfigMap=${namespace}/kube-environment-config" \
- ### --configuration-settings "envoy.annotations.service.beta.kubernetes.io/azure-load-balancer-resource-group=${aksClusterGroupName}" \
- ### --configuration-settings "logProcessor.appLogs.destination=log-analytics" \
- ### --configuration-protected-settings "logProcessor.appLogs.logAnalyticsConfig.customerId=${logAnalyticsWorkspaceIdEnc}" \
- ### --configuration-protected-settings "logProcessor.appLogs.logAnalyticsConfig.sharedKey=${logAnalyticsKeyEnc}"
- #
- #
- ##TODO
- ##appservice-ns svclb-appservice-ext-k8se-envoy-rmzm8
- ##1 node(s) didn't have free ports for the requested pod ports.
- #
- ##traefik LoadBalancer 10.43.29.229 <pending> web:81►30757 websecure:444►30674
- ##appservice-ext-k8se-envoy LoadBalancer 10.43.142.26 20.101.129.153 http:80►32547 https:443►32365 internal-http:8081►30661
- #
- extensionId=$(az k8s-extension show \
- --cluster-type connectedClusters \
- --cluster-name $clusterName \
- --resource-group $groupName \
- --name $extensionName \
- --query id \
- --output tsv)
- echo $extensionId
- az resource wait --ids $extensionId --custom "properties.installState!='Pending'" --api-version "2020-07-01-preview"
- #------------------------------------------
- ##custom location create
- #https://docs.microsoft.com/en-us/azure/app-service/manage-create-arc-environment#create-a-custom-location
- connectedClusterId=$(az connectedk8s show --resource-group $groupName --name $clusterName --query id --output tsv)
- #############################
- ## k8s extension
- #############################
- $echo_or_execute_customloc az customlocation create \
- --resource-group $groupName \
- --name $customLocationName \
- --host-resource-id $connectedClusterId \
- --namespace $namespace \
- --cluster-extension-ids $extensionId
- az customlocation show \
- --resource-group $groupName \
- --name $customLocationName
- customLocationId=$(az customlocation show \
- --resource-group $groupName \
- --name $customLocationName \
- --query id \
- --output tsv)
- #------------------------------------------
- #############################
- ## appservice
- #############################
- ###https://docs.microsoft.com/en-us/azure/app-service/manage-create-arc-environment#create-the-app-service-kubernetes-environment
- $echo_or_execute_appsvc az appservice kube create \
- --resource-group $groupName \
- --name $kubeEnvironmentName-app-svc \
- --custom-location $customLocationId \
- --static-ip $staticIp
- az appservice kube show \
- --resource-group $groupName \
- --name $kubeEnvironmentName-app-svc
- #------------------------------------------
- ##functions
- ##https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-arc-cli?tabs=csharp%2Cbrowser#create-storage-account
- #############################
- ## storage
- #############################
- az storage account create --name $storage_account_name --location westeurope --resource-group $groupName --sku Standard_LRS
- #------------------------------------------
- #############################
- ## functions
- #############################
- ##logicapp
- ##https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-arc-cli?tabs=csharp%2Cbrowser#create-storage-account
- if [ $install_az == 0 ]; then
- az extension add --yes --source "https://aka.ms/logicapp-latest-py2.py3-none-any.whl"
- fi
- #------------------------------------------
- echo az logicapp create --name $logicAppName \
- --resource-group $groupName --subscription $MySubscription \
- --storage-account $storage_account_name --custom-location $customLocationId
- az logicapp create --name $logicAppName \
- --resource-group $groupName --subscription $MySubscription \
- --storage-account $storage_account_name --custom-location $customLocationId
- #------------------------------------------
- az appservice plan create -g $groupName -n $app_svc_plan_name \
- --custom-location $customLocationId \
- --per-site-scaling --is-linux --sku K1
- az webapp create \
- --plan $app_svc_plan_name \
- --resource-group $groupName \
- --name appzip-node1 \
- --custom-location $customLocationId \
- --runtime "NODE|12-lts"
- git clone https://github.com/Azure-Samples/nodejs-docs-hello-world
- cd nodejs-docs-hello-world
- zip -r package.zip .
- az webapp deployment source config-zip --resource-group $groupName --name appzip-node1 --src package.zip
- cd -
- az webapp create \
- --plan $app_svc_plan_name \
- --resource-group $groupName \
- --name app-two-node1 \
- --custom-location $customLocationId \
- --deployment-container-image-name mcr.microsoft.com/appsvc/node:12-lts
- #--name test-app2 \ #TODO bug - no test in the app name or it would fail
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement