Janne Mattila

From programmer to programmer -- Programming just for the fun of it

AKS and Topology Aware Routing

Posted on: December 31, 2030

Sometimes modules encapsulate the functionality so well that you don’t really understand what’s happening under the hood anymore. And as you might know, I hate magic.

text

text

apiVersion: v1
kind: Service
metadata:
  name: network-app-svc
  namespace: network-app
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: 8080
  selector:
    app: network-app
apiVersion: apps/v1
kind: Deployment
metadata:
  name: network-app-deployment
  namespace: network-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: network-app
  template:
    metadata:
      labels:
        app: network-app
    spec:
      nodeSelector:
        kubernetes.io/os: linux
      topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: topology.kubernetes.io/zone
          whenUnsatisfiable: ScheduleAnyway
          labelSelector:
            matchLabels:
              app: network-app
      containers:
        - image: jannemattila/webapp-network-tester:1.0.75
          name: network-app
          resources:
            requests:
              cpu: 100m
              memory: 100Mi
            limits:
              cpu: 150m
              memory: 150Mi
          ports:
            - containerPort: 8080
              name: http
              protocol: TCP

Update the service:

apiVersion: v1
kind: Service
metadata:
  name: network-app-svc
  namespace: network-app
  annotations:
    service.kubernetes.io/topology-mode: Auto
spec:
  type: ClusterIP
  trafficDistribution: PreferClose
  internalTrafficPolicy: Local
  ports:
    - port: 80
      targetPort: 8080
  selector:
    app: network-app