Last active
March 9, 2023 21:27
-
-
Save danielscholl/7f3841f951e7877bf6eebb37765d250d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create an AKS cluster | |
AKS_RG="aks-rg" | |
AKS_NAME="aks-cluster" | |
az group create -n $AKS_RG -l eastus | |
az aks create -g $AKS_RG -n $AKS_NAME --network-plugin azure --generate-ssh-keys --node-count 2 | |
az k8s-extension create -g $AKS_RG -c $AKS_NAME -n flux --extension-type microsoft.flux -t managedClusters --auto-upgrade-minor-version true | |
az aks get-credentials -n $AKS_NAME -g $AKS_RG --overwrite-existing | |
# verify connection to the cluster | |
kubectl get nodes | |
# install Nginx ingress controller | |
NAMESPACE_INGRESS="ingress-nginx" | |
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx | |
helm repo update | |
helm install ingress-nginx ingress-nginx/ingress-nginx \ | |
--create-namespace \ | |
--namespace $NAMESPACE_INGRESS \ | |
--set controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-health-probe-request-path"=/healthz | |
INGRESS_PUBLIC_IP=$(kubectl get services ingress-nginx-controller -n $NAMESPACE_INGRESS -o jsonpath='{.status.loadBalancer.ingress[0].ip}') | |
echo $INGRESS_PUPLIC_IP | |
# install Application | |
NAMESPACE_APP_01="app-01" | |
kubectl create namespace $NAMESPACE_APP_01 | |
cat <<EOF | kubectl create -f - | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: aks-helloworld-one | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: aks-helloworld-one | |
template: | |
metadata: | |
labels: | |
app: aks-helloworld-one | |
spec: | |
containers: | |
- name: aks-helloworld-one | |
image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 | |
ports: | |
- containerPort: 80 | |
env: | |
- name: TITLE | |
value: "Welcome to Azure Kubernetes Service (AKS)" | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: aks-helloworld-one | |
spec: | |
type: ClusterIP | |
ports: | |
- port: 80 | |
selector: | |
app: aks-helloworld-one | |
EOF | |
cat <<EOF | kubectl create -f - | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: aks-helloworld-two | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: aks-helloworld-two | |
template: | |
metadata: | |
labels: | |
app: aks-helloworld-two | |
spec: | |
containers: | |
- name: aks-helloworld-two | |
image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 | |
ports: | |
- containerPort: 80 | |
env: | |
- name: TITLE | |
value: "AKS Ingress Demo" | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: aks-helloworld-two | |
spec: | |
type: ClusterIP | |
ports: | |
- port: 80 | |
selector: | |
app: aks-helloworld-two | |
EOF | |
cat <<EOF | kubectl create -f - | |
apiVersion: networking.k8s.io/v1 | |
kind: Ingress | |
metadata: | |
name: hello-world-ingress | |
annotations: | |
nginx.ingress.kubernetes.io/ssl-redirect: "false" | |
nginx.ingress.kubernetes.io/use-regex: "true" | |
nginx.ingress.kubernetes.io/rewrite-taAKS_RGet: /\$2 | |
spec: | |
ingressClassName: nginx | |
rules: | |
- http: | |
paths: | |
- path: /hello-world-one(/|$)(.*) | |
pathType: Prefix | |
backend: | |
service: | |
name: aks-helloworld-one | |
port: | |
number: 80 | |
- path: /hello-world-two(/|$)(.*) | |
pathType: Prefix | |
backend: | |
service: | |
name: aks-helloworld-two | |
port: | |
number: 80 | |
- path: /(.*) | |
pathType: Prefix | |
backend: | |
service: | |
name: aks-helloworld-one | |
port: | |
number: 80 | |
--- | |
apiVersion: networking.k8s.io/v1 | |
kind: Ingress | |
metadata: | |
name: hello-world-ingress-static | |
annotations: | |
nginx.ingress.kubernetes.io/ssl-redirect: "false" | |
nginx.ingress.kubernetes.io/rewrite-taAKS_RGet: /static/\$2 | |
spec: | |
ingressClassName: nginx | |
rules: | |
- http: | |
paths: | |
- path: /static(/|$)(.*) | |
pathType: Prefix | |
backend: | |
service: | |
name: aks-helloworld-one | |
port: | |
number: 80 | |
EOF | |
curl http://$INGRESS_PUPLIC_IP | |
curl http://$INGRESS_PUPLIC_IP/aks-helloworld-one | |
curl http://$INGRESS_PUPLIC_IP/aks-helloworld-two | |
AZURE_PUBLIC_IP_ID=$(az network public-ip list --query "[?ipAddress!=null]|[?contains(ipAddress, '$INGRESS_PUPLIC_IP')].[id]" -o tsv) | |
echo $AZURE_PUBLIC_IP_ID | |
# Update public IP address with DNS name | |
az network public-ip update --ids $AZURE_PUBLIC_IP_ID --dns-name $DNS_NAME | |
DOMAIN_NAME_FQDN=$(az network public-ip show --ids $AZURE_PUBLIC_IP_ID --query='dnsSettings.fqdn' -o tsv) | |
# DOMAIN_NAME_FQDN=$(az network public-ip show -g MC_AKS_RG-aks-we_aks-cluster_westeurope -n kubernetes-af54fcf50c6b24d7fbb9ed6aa62bdc77 --query='dnsSettings.fqdn') | |
echo $DOMAIN_NAME_FQDN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment