Author : HASSAN MD TAREQ | 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

AGIC Ingress With AKS Hello World

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

Serving Multiple APIs Under Same Domain

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

Simple Ingress For Testing ExternalDNS

foo-api-deployment.yaml


foo-api-ingress.yaml


bar-api-deployment.yaml


bar-api-ingress.yaml