Author : MD TAREQ HASSAN | Updated : 2021/06/23

AKS Hello World Image

Image: mcr.microsoft.com/azuredocs/aks-helloworld:v1

Usage: aks-helloworld-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: aks-helloworld
spec:
  replicas: 1
  selector:
    matchLabels:
      app: aks-helloworld
  template:
    metadata:
      labels:
        app: aks-helloworld
    spec:
      containers:
      - name: aks-helloworld
        image: mcr.microsoft.com/azuredocs/aks-helloworld:v1
        ports:
        - containerPort: 80
        env:
        - name: TITLE
          value: "AKS Hello World Test"

Links

Simple Ingress with AGIC

Demo api

demo-api.yaml

apiVersion: v1
kind: Service
metadata:
  name: demo-api 
  namespace: default
spec:
  type: ClusterIP
  ports:
  - port: 80
  selector:
    app: demo-api
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-api
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: demo-api
  template:
    metadata:
      labels:
        app: demo-api
    spec:
      containers:
      - name: demo-api
        image: hovermind.azurecr.io/demoapi:latest
        ports:
        - containerPort: 80
---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: demo-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/backend-path-prefix: "/api/" # API has url prefix -> [Route("api")]
spec:
  rules:
  - host: agic-appgw-public-ip.japaneast.cloudapp.azure.com
    http:
      paths:
      - path: /api*
        pathType: Prefix
        backend:
          service:
            name: demo-api
            port:
              number: 80

Demo webapp: demo-webapp.yaml

apiVersion: v1
kind: Service
metadata:
  name: demo-webapp 
  namespace: default
spec:
  type: ClusterIP
  ports:
  - port: 80
  selector:
    app: demo-webapp
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-webapp
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: demo-webapp
  template:
    metadata:
      labels:
        app: demo-webapp
    spec:
      containers:
      - name: demo-webapp
        image: mcr.microsoft.com/azuredocs/aks-helloworld:v1
        ports:
        - containerPort: 80
        env:
        - name: TITLE
          value: "AKS Ingress Test"
---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: demo-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/backend-path-prefix: "/"
spec:
  rules:
  - host: agic-appgw-public-ip.japaneast.cloudapp.azure.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: demo-webapp
            port:
              number: 80

Serving Multiple APIs Under Same Domain

Project level setup: Ingress For Multiple APIs - API projects

foo-api.yaml (service, deployment and ingress)

apiVersion: v1
kind: Service
metadata:
  name: foo-api
  namespace: transient # I frequently delete and create poc namespace, that's why "transient"
spec:
  type: ClusterIP
  ports:
  - port: 80
  selector:
    app: foo-api
	
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: foo-api
  namespace: demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: foo-api
  template:
    metadata:
      labels:
        app: foo-api
    spec:
      containers:
      - name: foo-api
        image: myacr.azurecr.io/foo-api:202107
        ports:
        - containerPort: 80

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: foo-api
  namespace: demo
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/ssl-redirect: "false"
    appgw.ingress.kubernetes.io/backend-path-prefix: "/api/foo"
spec:
  rules:
  - host: demo.com
    http:
      paths:
      - path: /api/foo*
        pathType: Prefix
        backend:
          service:
            name: foo-api
            port:
              number: 80

bar-api.yaml (service, deployment and ingress)

apiVersion: v1
kind: Service
metadata:
  name: bar-api
  namespace: transient # I frequently delete and create poc namespace, that's why "transient"
spec:
  type: ClusterIP
  ports:
  - port: 80
  selector:
    app: bar-api
	
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: bar-api
  namespace: demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: bar-api
  template:
    metadata:
      labels:
        app: bar-api
    spec:
      containers:
      - name: bar-api
        image: myacr.azurecr.io/bar-api:202107
        ports:
        - containerPort: 80

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: bar-api
  namespace: demo
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/ssl-redirect: "false"
    appgw.ingress.kubernetes.io/backend-path-prefix: "/api/bar"
spec:
  rules:
  - host: demo.com
    http:
      paths:
      - path: /api/bar*
        pathType: Prefix
        backend:
          service:
            name: bar-api
            port:
              number: 80

Serving Multiple MVC Applications Under Same Domain

Make sure you followed the instructions described here: https://stackoverflow.com/a/57212033/4802664

mvc-ingress.yaml

apiVersion: v1
kind: Service
metadata:
  name: foo-mvc-webapp
  namespace: demo
spec:
  type: ClusterIP
  ports:
  - port: 80
  selector:
    app: foo-mvc-webapp
	
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: foo-mvc-webapp
  namespace: demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: foo-mvc-webapp
  template:
    metadata:
      labels:
        app: foo-mvc-webapp
    spec:
      containers:
      - name: foo-mvc-webapp
        image: myacr.azurecr.io/foo-mvc:202107
        ports:
        - containerPort: 80
        env:
          # define custom Path Base (it should be the same as 'path' in Ingress-service)
          - name: API_PATH_BASE
            value: "apistarter"

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: foo-mvc-webapp-ingress
  namespace: demo
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/ssl-redirect: "false"
    appgw.ingress.kubernetes.io/backend-path-prefix: "/webapp/foo/"
spec:
  rules:
  - host: demo.com
    http:
      paths:
      - path: /webapp/foo/*
        pathType: Prefix
        backend:
          service:
            name: foo-mvc-webapp
            port:
              number: 80

Custom Domain and TLS with AGIC Ingress

foo-api-deployment.yaml (custom domain i.e. demo.com and TLS)

apiVersion: v1
kind: Service
metadata:
  name: foo-app
  namespace: demo
spec:
  type: ClusterIP
  ports:
  - port: 80
  selector:
    app: foo-app
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: foo-app
  namespace: demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: foo-app
  template:
    metadata:
      labels:
        app: foo-app
    spec:
      containers:
      - name: foo-app
        image: mcr.microsoft.com/azuredocs/aks-helloworld:v1
        ports:
        - containerPort: 80
        env:
        - name: TITLE
          value: "AKS Hello World - Foo App" 

bar-app-deployment.yaml

apiVersion: v1
kind: Service
metadata:
  name: bar-app
  namespace: demo
spec:
  type: ClusterIP
  ports:
  - port: 80
  selector:
    app: bar-app
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: bar-app
  namespace: demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: bar-app
  template:
    metadata:
      labels:
        app: bar-app
    spec:
      containers:
      - name: bar-app
        image: mcr.microsoft.com/azuredocs/aks-helloworld:v1
        ports:
        - containerPort: 80
        env:
        - name: TITLE
          value: "AKS Hello World - Bar App" 

Ingress: foo-bar-ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: foo-bar-ingress
  namespace: demo
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/ssl-redirect: "false"
    appgw.ingress.kubernetes.io/backend-path-prefix: "/"
spec:
  tls:
  - hosts:
    - demo.com
    secretName: demo-tls-secret # SSL certificate for 'demo.com'
  rules:
  - host: demo.com
    http: 
      paths:
      - path: /foo/*
        pathType: Prefix
        backend:
          service:
            name: foo-app
            port:
              number: 80
      - path: /bar/*
        pathType: Prefix
        backend:
          service:
            name: bar-app
            port:
              number: 80

Now