You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
8.9 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. # login in Ubuntu
  2. az login az login --use-device-code /
  3. az login --tenant 429950a6-2916-4b6f-8bd1-09b5071951d4
  4. #Create a resource group
  5. resourceGroup=DL-LEARNING-RG
  6. az group create --name $resourceGroup --location southeastasia #/////canadacentral
  7. #delete resouce group
  8. az group delete --name $resourceGroup
  9. # Vnet
  10. #resourceGroup='DL-LEARNING-RG'
  11. subscription='909efc0a-aa87-4bd2-884c-c93b75692357'
  12. vnetName='aks-vnet-eshop'
  13. az network vnet create -g $resourceGroup --subscription $subscription -n $vnetName -l southeastasia --address-prefix 10.10.0.0/17 --subnet-name eshopsubnet --subnet-prefix 10.10.0.0/18
  14. subnetId=$(az network vnet subnet show --resource-group $resourceGroup --subscription $subscription --vnet-name $vnetName --name eshopsubnet --query id -o tsv)
  15. # Create a private container registry
  16. #######################################################################################
  17. # Create a resource group for acr
  18. acrrg=DL-PRIVATE-RG
  19. az group create --name $acrrg --location southeastasia ///eastus
  20. # Create a container registry
  21. az acr create --resource-group $acrrg \
  22. --name heigoo --sku Basic ###// Standard Premium
  23. #Log in to registry
  24. az acr login --name heigoo #geCqSifODg7Zs8KCni//P/f295oI8uUr
  25. #Push image to registry
  26. docker pull mcr.microsoft.com/hello-world
  27. docker tag mcr.microsoft.com/hello-world heigoo.azurecr.io/hello-world:v1
  28. docker push heigoo.azurecr.io/hello-world:v1
  29. docker rmi heigoo.azurecr.io/hello-world:v1
  30. #List container images
  31. az acr repository list --name heigoo --output table
  32. az acr repository show-tags --name heigoo --repository hello-world --output table
  33. #Run image from registry
  34. docker run heigoo.azurecr.io/hello-world:v1
  35. #Clean up resources
  36. az group delete --name DL-PRIVATE-RG
  37. # crete aks Cluster
  38. clusterName='eShop'
  39. acr=$(az acr show --name heigoo --resource-group $acrrg --query "id" --output tsv)
  40. az aks create -n $clusterName --resource-group $resourceGroup --subscription $subscription --kubernetes-version 1.21.1 --network-plugin azure --enable-managed-identity --generate-ssh-keys --attach-acr $acr --node-count 2 --vnet-subnet-id $subnetId
  41. ## if acr already created
  42. az aks update --name myAKSCluster --resource-group myResourceGroup --subscription mySubscription --attach-acr <acr-resource-id>
  43. az acr show --name acrName --resource-group myResourceGroup --subscription mySubscription --query "id"
  44. ## deploy
  45. az account set --subscription 909efc0a-aa87-4bd2-884c-c93b75692357
  46. az aks get-credentials --resource-group DL-LEARNING-RG --name eShop
  47. kubectl get all -n cert-manager -o wide
  48. # install ingress-nginx
  49. #cd D:\temp\microservice\eShopOnContainers\deploy\k8s\nginx-ingress
  50. kubectl apply -f mandatory.yaml
  51. kubectl apply -f local-cm.yaml #(add large-client-header-buffers: "4 16k")
  52. kubectl apply -f local-svc.yaml
  53. #cd D:\temp\microservice\eShopOnContainers\deploy\k8s\helm
  54. #.\deploy-all.ps1 -externalDns aks -aksName eShop -aksRg DL-LEARNING-RG -imageTag linux-latest -registry heigoo.azurecr.io -dockerUser heigoo -dockerPassword tuQbbDDaFxYPV6NMBpEylhw -useMesh $false
  55. .\deploy-all.ps1 -externalDns eshop.anniedesign.xyz -imageTag linux-latest -registry heigoo.azurecr.io -dockerUser heigoo -dockerPassword geCqSifODg7Zs8KCni//P/f295oI8uUr -useMesh $false -sslSupport staging
  56. .\deploy-all.ps1 -externalDns eshop.anniedesign.xyz -imageTag linux-latest -registry heigoo.azurecr.io -dockerUser heigoo -dockerPassword geCqSifODg7Zs8KCni//P/f295oI8uUr -useMesh $false -sslSupport prod
  57. #.\deploy-all.ps1 -externalDns eshop.anniedesign.xyz -aksName eShop -aksRg DL-LEARNING-RG -imageTag linux-dev -useMesh $false
  58. # enable tls-support
  59. # https://github.com/dotnet-architecture/eShopOnContainers/wiki/AKS-TLS
  60. # cd D:\temp\microservice\eShopOnContainers\deploy\k8s
  61. #run .\enable-tls.ps1
  62. # rename values-staging.yaml(values-prod.yaml) to values.yaml() and ingressClass to nginx
  63. # cd D:\temp\microservice\eShopOnContainers\deploy\k8s\helm
  64. #kubectl apply -f cert-manager.yaml(if no running .\enable-tls.ps1)
  65. helm install eshop-tls-support tls-support
  66. kubectl get issuer
  67. kubectl get cert -o wide
  68. helm uninstall eshop-tls-support #(change server and environment to pord server ) redeploy
  69. # check deploy status
  70. kubectl get deployment
  71. kubectl get ingress #check external IP to bind it on Godaddy (or other DNS provider) with the DNS name
  72. kubectl get cert # check certificate
  73. kubectl get certificaterequest
  74. kubectl get order
  75. kubectl get challenges
  76. kubectl get Issuers,ClusterIssuers,Certificates,CertificateRequests,Orders,Challenges --all-namespaces
  77. # CD D:\temp\microservice\eShopOnContainers\deploy\k8s\nodeports to change sql-service.yaml from NodePort to LoadBalancer
  78. kubectl apply -f sql-service1.yaml
  79. #get db external IP(lb) to connect to DB to change all http to https (eg. 20.44.192.98:1433 sa/Pass@word)
  80. # update clients set ClientUri= replace(clientUri,'http://eshop.','https://eshop.')
  81. # update ClientRedirectUris set RedirectUri = replace(RedirectUri,'http://eshop.','https://eshop.') where clientid <>3
  82. # update ClientPostLogoutRedirectUris set PostLogoutRedirectUri = replace(PostLogoutRedirectUri,'http://eshop.','https://eshop.') where clientid <>3
  83. # webmvc unauthorized client issue (change back RedirectUri to http for temporary usage)
  84. ##uninstall
  85. helm uninstall $(helm ls --filter eshop -q) --dry-run
  86. #azure devops pipeline
  87. # https://github.com/dotnet-architecture/eShopOnContainers/tree/main/build/azure-devops
  88. #############################################################################################
  89. ## This creates a working single node Azure Kubernetes Cluster
  90. ## and with an Azure Container Registry. Note, the ACR is in
  91. ## the same resource group as the AKS for demo purposes. For
  92. ## dev you should have ACR in separate resource group.
  93. echo "Beginning AKS Setup for Demo"
  94. date
  95. AKS_RESOURCE_GROUP=aks-rg1
  96. AKS_CLUSTER_NAME=aks-c1
  97. ACR_RESOURCE_GROUP=MC_aks-rg1_aks-c1_centralus
  98. ACR_NAME=aksacr122
  99. SERVICE_PRINCIPAL_NAME=aks-sp-user
  100. RG_LOCATION=CentralUS
  101. DOCKER_USERNAME=$ACR_NAME
  102. DOCKER_EMAIL={provide email address here} #does not have to be an account with docker hub
  103. #DOCKER_PASSWORD is applied a value later
  104. az group create --location $RG_LOCATION --name $AKS_RESOURCE_GROUP
  105. az aks create -g $AKS_RESOURCE_GROUP -n $AKS_CLUSTER_NAME --generate-ssh-keys --node-count 1 --node-vm-size Standard_F1s
  106. az acr create --resource-group $ACR_RESOURCE_GROUP --name $ACR_NAME --sku Basic --admin-enabled true
  107. CLIENT_ID=$(az aks show --resource-group $AKS_RESOURCE_GROUP --name $AKS_CLUSTER_NAME --query "servicePrincipalProfile.clientId" --output tsv)
  108. # Get the ACR registry resource id
  109. ACR_ID=$(az acr show --name $ACR_NAME --resource-group $ACR_RESOURCE_GROUP --query "id" --output tsv)
  110. # Create role assignment
  111. az role assignment create --assignee $CLIENT_ID --role Reader --scope $ACR_ID
  112. # Populate the ACR login server and resource id.
  113. ACR_LOGIN_SERVER=$(az acr show --name $ACR_NAME --query loginServer --output tsv)
  114. ACR_REGISTRY_ID=$(az acr show --name $ACR_NAME --query id --output tsv)
  115. # Create a contributor role assignment with a scope of the ACR resource.
  116. SP_PASSWD=$(az ad sp create-for-rbac --name $SERVICE_PRINCIPAL_NAME --role Reader --scopes $ACR_REGISTRY_ID --query password --output tsv)
  117. # Get the service principle client id.
  118. CLIENT_ID=$(az ad sp show --id http://$SERVICE_PRINCIPAL_NAME --query appId --output tsv)
  119. # Output used when creating Kubernetes secret.
  120. echo "Service principal ID: $CLIENT_ID"
  121. echo "Service principal password: $SP_PASSWD"
  122. #connect to the aks environment
  123. az aks get-credentials --resource-group $AKS_RESOURCE_GROUP --name $AKS_CLUSTER_NAME
  124. ACR_HTTPS_LOGIN_SERVER="https://$ACR_LOGIN_SERVER"
  125. ### get password from ACR
  126. DOCKER_PASSWORD=$(az acr credential show -n $ACR_NAME --query passwords[0].value -o tsv)
  127. kubectl create secret docker-registry acrconnection --docker-server=$ACR_HTTPS_LOGIN_SERVER --docker-username=$DOCKER_USERNAME --docker-password=$DOCKER_PASSWORD --docker-email=$DOCKER_EMAIL
  128. az acr login --name $ACR_NAME
  129. echo "Completed AKS Setup"
  130. date
  131. #######################
  132. # Post the following JSON payload to the endpoint, sending a valid Basic Access Token
  133. # https://dev.azure.com/{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=5.1-preview.2
  134. {
  135. "authorization": {
  136. "scheme": "ServicePrincipal",
  137. "parameters": {
  138. "loginServer": "<ACRSERVER>.azurecr.io",
  139. "servicePrincipalId": "<APPLICATIONid OF SPN>",
  140. "tenantId": "<TENANTID>",
  141. "serviceprincipalkey": "<SPN kEY>"
  142. }
  143. },
  144. "description": "",
  145. "name": "Name of Connection",
  146. "type": "dockerregistry",
  147. "url": "https://<ACRSERVER>.azurecr.io",
  148. "isShared": false,
  149. "owner": "library",
  150. "data": {
  151. "registryId": "/subscriptions/<SUBSCRIPTIONID>/resourceGroups/<RESOURCEGROUP>/providers/Microsoft.ContainerRegistry/registries/<ACRSERVER>",
  152. "registrytype": "ACR",
  153. "spnObjectId": "",
  154. "subscriptionId": "<SUBSCRIPTIONID>",
  155. "subscriptionName": "<SUBSCRIPTIONNAME>"
  156. }
  157. }