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.

193 lines
9.2 KiB

3 years ago
  1. # 20.63.171.125
  2. PUBLIC_IP_ID=$(az network public-ip list --query "[?ipAddress=='20.63.171.125'].id" -o tsv)
  3. az network dns zone create --resource-group k8sstudy --name anniedesign.xyz
  4. az network dns record-set a add-record --resource-group k8sstudy --record-set-name eshop --zone-name anniedesign.xyz --ipv4-address 1.1.1.1
  5. az network dns record-set a update --name eshop --resource-group k8sstudy --zone-name anniedesign.xyz --target-resource /subscriptions/e25379c9-941e-4fe6-81ff-f0e62becf996/resourceGroups/mc_k8sstudy_eshop_japaneast/providers/Microsoft.Network/publicIPAddresses/kubernetes-ae87c596c80514b95839a76c3ed683df
  6. az network dns zone show --resource-group k8sstudy --name anniedesign.xyz --query nameServers
  7. # ns1-03.azure-dns.com.
  8. # ns2-03.azure-dns.net.
  9. # ns3-03.azure-dns.org.
  10. # ns4-03.azure-dns.info.
  11. # ---------------------------
  12. REGISTRY_NAME=heigoo
  13. CONTROLLER_REGISTRY=k8s.gcr.io
  14. CONTROLLER_IMAGE=ingress-nginx/controller
  15. CONTROLLER_TAG=v0.48.1
  16. PATCH_REGISTRY=docker.io
  17. PATCH_IMAGE=jettech/kube-webhook-certgen
  18. PATCH_TAG=v1.5.1
  19. DEFAULTBACKEND_REGISTRY=k8s.gcr.io
  20. DEFAULTBACKEND_IMAGE=defaultbackend-amd64
  21. DEFAULTBACKEND_TAG=1.5
  22. CERT_MANAGER_REGISTRY=quay.io
  23. CERT_MANAGER_TAG=v1.3.1
  24. CERT_MANAGER_IMAGE_CONTROLLER=jetstack/cert-manager-controller
  25. CERT_MANAGER_IMAGE_WEBHOOK=jetstack/cert-manager-webhook
  26. CERT_MANAGER_IMAGE_CAINJECTOR=jetstack/cert-manager-cainjector
  27. az acr import --name $REGISTRY_NAME --source $CONTROLLER_REGISTRY/$CONTROLLER_IMAGE:$CONTROLLER_TAG --image $CONTROLLER_IMAGE:$CONTROLLER_TAG
  28. az acr import --name $REGISTRY_NAME --source $PATCH_REGISTRY/$PATCH_IMAGE:$PATCH_TAG --image $PATCH_IMAGE:$PATCH_TAG
  29. az acr import --name $REGISTRY_NAME --source $DEFAULTBACKEND_REGISTRY/$DEFAULTBACKEND_IMAGE:$DEFAULTBACKEND_TAG --image $DEFAULTBACKEND_IMAGE:$DEFAULTBACKEND_TAG
  30. az acr import --name $REGISTRY_NAME --source $CERT_MANAGER_REGISTRY/$CERT_MANAGER_IMAGE_CONTROLLER:$CERT_MANAGER_TAG --image $CERT_MANAGER_IMAGE_CONTROLLER:$CERT_MANAGER_TAG
  31. az acr import --name $REGISTRY_NAME --source $CERT_MANAGER_REGISTRY/$CERT_MANAGER_IMAGE_WEBHOOK:$CERT_MANAGER_TAG --image $CERT_MANAGER_IMAGE_WEBHOOK:$CERT_MANAGER_TAG
  32. az acr import --name $REGISTRY_NAME --source $CERT_MANAGER_REGISTRY/$CERT_MANAGER_IMAGE_CAINJECTOR:$CERT_MANAGER_TAG --image $CERT_MANAGER_IMAGE_CAINJECTOR:$CERT_MANAGER_TAG
  33. az aks show --resource-group k8sstudy --name eshop --query nodeResourceGroup -o tsv --MC_k8sstudy_eShop_japaneast
  34. az network public-ip create --resource-group MC_k8sstudy_eShop_japaneast --name myAKSPublicIP --sku Standard --allocation-method static --query publicIp.ipAddress -o tsv --20.194.219.173
  35. -----
  36. # Create a namespace for your ingress resources
  37. kubectl create namespace ingress-basic
  38. # Add the ingress-nginx repository
  39. helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
  40. # Set variable for ACR location to use for pulling images
  41. ACR_URL=heigoo.azurecr.io
  42. STATIC_IP=20.194.219.173
  43. DNS_LABEL=eshop
  44. # Use Helm to deploy an NGINX ingress controller
  45. kubectl --namespace ingress-basic get services -o wide -w nginx-ingress-ingress-nginx-controller
  46. az network public-ip list --resource-group MC_myResourceGroup_myAKSCluster_eastus --query "[?name=='myAKSPublicIP'].[dnsSettings.fqdn]" -o tsv
  47. # ===============
  48. az network public-ip create \
  49. --resource-group k8sstudy \
  50. --name myAKSPublicIP \
  51. --sku Standard \
  52. --allocation-method static
  53. az network public-ip list
  54. az network public-ip show --resource-group k8sstudy --name myAKSPublicIP --query ipAddress --output tsv
  55. az role assignment create \
  56. --assignee eShop \
  57. --role "Network Contributor" \
  58. --scope /subscriptions/e25379c9-941e-4fe6-81ff-f0e62becf996/resourceGroups/k8sstudy
  59. # ==================
  60. az aks create --name myAKSCluster --resource-group myResourceGroup
  61. service principle
  62. az ad sp create-for-rbac --skip-assignment --name myAKSClusterServicePrincipal
  63. Specify a service principal for an AKS cluster
  64. az aks create \
  65. --resource-group myResourceGroup \
  66. --name myAKSCluster \
  67. --service-principal <appId> \
  68. --client-secret <password>
  69. # Delegate access to other Azure resources
  70. az role assignment create --assignee <appId> --scope <resourceScope> --role Contributor
  71. # ===========================================
  72. # Create a new AKS cluster with ACR integration
  73. # set this to the name of your Azure Container Registry. It must be globally unique
  74. MYACR=myContainerRegistry
  75. # Run the following line to create an Azure Container Registry if you do not already have one
  76. az acr create -n $MYACR -g myContainerRegistryResourceGroup --sku basic
  77. # Create an AKS cluster with ACR integration
  78. az aks create -n myAKSCluster -g myResourceGroup --generate-ssh-keys --attach-acr $MYACR
  79. az aks create -n myAKSCluster -g myResourceGroup --generate-ssh-keys --attach-acr /subscriptions/<subscription-id>/resourceGroups/myContainerRegistryResourceGroup/providers/Microsoft.ContainerRegistry/registries/myContainerRegistry
  80. # Configure ACR integration for existing AKS clusters
  81. # =====
  82. # =================managed identity==========================
  83. az account show --query id -o tsv
  84. az aks show -g k8sstudy -n eShop --query "servicePrincipalProfile"
  85. # After verifying the cluster is using managed identities, you can find the control plane system-assigned identity's object ID with the following command:
  86. az aks show -g k8sstudy -n eShop --query "identity"
  87. az identity list --query "[].{Name:name, Id:id, Location:location}" -o table
  88. # ==================inital aks==========
  89. az group delete --name myResourceGroup --yes --no-wait
  90. # ======= acr azure registry============
  91. az aks check-acr --name MyManagedCluster --resource-group MyResourceGroup --acr myacr.azurecr.io
  92. # set this to the name of your Azure Container Registry. It must be globally unique
  93. MYACR=myContainerRegistry
  94. # Run the following line to create an Azure Container Registry if you do not already have one
  95. az acr create -n $MYACR -g myContainerRegistryResourceGroup --sku basic
  96. # Create an AKS cluster with ACR integration
  97. az aks create -n myAKSCluster -g myResourceGroup --generate-ssh-keys --attach-acr $MYACR
  98. # -----------------
  99. az aks update -n myAKSCluster -g myResourceGroup --attach-acr heigoo
  100. # If you are using an ACR that is located in a different subscription from your AKS cluster, use the ACR resource ID when attaching or detaching from an AKS cluster.
  101. az aks create -n myAKSCluster -g myResourceGroup --generate-ssh-keys --attach-acr /subscriptions/<subscription-id>/resourceGroups/myContainerRegistryResourceGroup/providers/Microsoft.ContainerRegistry/registries/myContainerRegistry
  102. # -----
  103. helm upgrade -i nginx-ingress ingress-nginx/ingress-nginx \
  104. --version 3.36.0 \
  105. --namespace ingress-basic \
  106. --set controller.replicaCount=2 \
  107. --set controller.nodeSelector."kubernetes\.io/os"=linux \
  108. --set controller.image.registry=$ACR_URL \
  109. --set controller.image.image=$CONTROLLER_IMAGE \
  110. --set controller.image.tag=$CONTROLLER_TAG \
  111. --set controller.image.digest="" \
  112. --set controller.admissionWebhooks.patch.nodeSelector."kubernetes\.io/os"=linux \
  113. --set controller.admissionWebhooks.patch.image.registry=$ACR_URL \
  114. --set controller.admissionWebhooks.patch.image.image=$PATCH_IMAGE \
  115. --set controller.admissionWebhooks.patch.image.tag=$PATCH_TAG \
  116. --set defaultBackend.nodeSelector."kubernetes\.io/os"=linux \
  117. --set defaultBackend.image.registry=$ACR_URL \
  118. --set defaultBackend.image.image=$DEFAULTBACKEND_IMAGE \
  119. --set defaultBackend.image.tag=$DEFAULTBACKEND_TAG
  120. helm upgrade -i nginx-ingress ingress-nginx/ingress-nginx \
  121. --version 3.36.0 \
  122. --namespace ingress-basic \
  123. --set controller.replicaCount=2 \
  124. --set controller.nodeSelector."kubernetes\.io/os"=linux \
  125. --set controller.image.registry=$ACR_URL \
  126. --set controller.image.image=$CONTROLLER_IMAGE \
  127. --set controller.image.tag=$CONTROLLER_TAG \
  128. --set controller.image.digest="" \
  129. --set controller.admissionWebhooks.patch.nodeSelector."kubernetes\.io/os"=linux \
  130. --set controller.admissionWebhooks.patch.image.registry=$ACR_URL \
  131. --set controller.admissionWebhooks.patch.image.image=$PATCH_IMAGE \
  132. --set controller.admissionWebhooks.patch.image.tag=$PATCH_TAG \
  133. --set defaultBackend.nodeSelector."kubernetes\.io/os"=linux \
  134. --set defaultBackend.image.registry=$ACR_URL \
  135. --set defaultBackend.image.image=$DEFAULTBACKEND_IMAGE \
  136. --set defaultBackend.image.tag=$DEFAULTBACKEND_TAG \
  137. --set controller.service.loadBalancerIP=$STATIC_IP \
  138. --set controller.service.annotations."service\.beta\.kubernetes\.io/azure-dns-label-name"=$DNS_LABEL
  139. az network dns record-set a add-record \
  140. --resource-group myResourceGroup \
  141. --zone-name anniedesign.xyz \
  142. --record-set-name "*" \
  143. --ipv4-address 20.89.163.19
  144. # ============clear resources========================
  145. kubectl delete namespace ingress-basic
  146. kubectl delete -f certificates.yaml
  147. kubectl delete -f cluster-issuer.yaml
  148. helm list --all-namespaces
  149. helm uninstall nginx-ingress cert-manager -n ingress-basic
  150. kubectl delete -f aks-helloworld.yaml --namespace ingress-basic
  151. kubectl delete -f ingress-demo.yaml --namespace ingress-basic
  152. kubectl delete namespace ingress-basic
  153. az network public-ip delete --resource-group MC_myResourceGroup_myAKSCluster_japaneast --name myAKSPublicIP
  154. az group delete --name myResourceGroup --yes --no-wait