Deploy to hybrid Linux/Windows Kubernetes clusters

How to run Dapr apps on Kubernetes clusters with Windows nodes

Dapr supports running your microservices on Kubernetes clusters on:

  • Windows
  • Linux
  • A combination of both

This is especially helpful during a piecemeal migration of a legacy application into a Dapr Kubernetes cluster.

Kubernetes uses a concept called node affinity to denote whether you want your application to be launched on a Linux node or a Windows node. When deploying to a cluster which has both Windows and Linux nodes, you must provide affinity rules for your applications, otherwise the Kubernetes scheduler might launch your application on the wrong type of node.

前期准备

Before you begin, set up a Kubernetes cluster with Windows nodes. Many Kubernetes providers support the automatic provisioning of Windows enabled Kubernetes clusters.

  1. Follow your preferred provider’s instructions for setting up a cluster with Windows enabled.

  2. Once you have set up the cluster, verify that both Windows and Linux nodes are available.

    1. kubectl get nodes -o wide
    2. NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
    3. aks-nodepool1-11819434-vmss000000 Ready agent 6d v1.17.9 10.240.0.4 <none> Ubuntu 16.04.6 LTS 4.15.0-1092-azure docker://3.0.10+azure
    4. aks-nodepool1-11819434-vmss000001 Ready agent 6d v1.17.9 10.240.0.35 <none> Ubuntu 16.04.6 LTS 4.15.0-1092-azure docker://3.0.10+azure
    5. aks-nodepool1-11819434-vmss000002 Ready agent 5d10h v1.17.9 10.240.0.129 <none> Ubuntu 16.04.6 LTS 4.15.0-1092-azure docker://3.0.10+azure
    6. akswin000000 Ready agent 6d v1.17.9 10.240.0.66 <none> Windows Server 2019 Datacenter 10.0.17763.1339 docker://19.3.5
    7. akswin000001 Ready agent 6d v1.17.9 10.240.0.97 <none> Windows Server 2019 Datacenter 10.0.17763.1339 docker://19.3.5

Install the Dapr control plane

If you are installing using the Dapr CLI or via a Helm chart, simply follow the normal deployment procedures: Installing Dapr on a Kubernetes cluster

Affinity will be automatically set for kubernetes.io/os=linux. This will be sufficient for most users, as Kubernetes requires at least one Linux node pool.

Note

Dapr control plane containers are built and tested for both Windows and Linux. However, it’s recommended to use the Linux control plane containers, which tend to be smaller and have a much larger user base.

If you understand the above, but want to deploy the Dapr control plane to Windows, you can do so by setting:

  1. helm install dapr dapr/dapr --set global.daprControlPlaneOs=windows

Install Dapr applications

Windows applications

  1. Follow the Microsoft documentation to create a Docker Windows container with your application installed.

  2. Once you’ve created a Docker container with your application, create a deployment YAML file with the node affinity set to kubernetes.io/os: windows. In the example deploy_windows.yaml deployment file below:

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: yourwinapp
    5. labels:
    6. app: applabel
    7. spec:
    8. replicas: 1
    9. selector:
    10. matchLabels:
    11. app: applablel
    12. template:
    13. metadata:
    14. labels:
    15. app: applabel
    16. annotations:
    17. dapr.io/enabled: "true"
    18. dapr.io/id: "addapp"
    19. dapr.io/port: "6000"
    20. dapr.io/config: "appconfig"
    21. spec:
    22. containers:
    23. - name: add
    24. image: yourreponsitory/your-windows-dapr-container:your-tag
    25. ports:
    26. - containerPort: 6000
    27. imagePullPolicy: Always
    28. affinity:
    29. nodeAffinity:
    30. requiredDuringSchedulingIgnoredDuringExecution:
    31. nodeSelectorTerms:
    32. - matchExpressions:
    33. - key: kubernetes.io/os
    34. operator: In
    35. values:
    36. - windows
  3. Deploy the YAML file to your Kubernetes cluster.

    1. kubectl apply -f deploy_windows.yaml

Linux applications

If you already have a Dapr application that runs on Linux, you still need to add affinity rules.

  1. Create a deployment YAML file with the node affinity set to kubernetes.io/os: linux. In the example deploy_linux.yaml deployment file below:

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: yourlinuxapp
    5. labels:
    6. app: yourlabel
    7. spec:
    8. replicas: 1
    9. selector:
    10. matchLabels:
    11. app: yourlabel
    12. template:
    13. metadata:
    14. labels:
    15. app: yourlabel
    16. annotations:
    17. dapr.io/enabled: "true"
    18. dapr.io/id: "addapp"
    19. dapr.io/port: "6000"
    20. dapr.io/config: "appconfig"
    21. spec:
    22. containers:
    23. - name: add
    24. image: yourreponsitory/your-application:your-tag
    25. ports:
    26. - containerPort: 6000
    27. imagePullPolicy: Always
    28. affinity:
    29. nodeAffinity:
    30. requiredDuringSchedulingIgnoredDuringExecution:
    31. nodeSelectorTerms:
    32. - matchExpressions:
    33. - key: kubernetes.io/os
    34. operator: In
    35. values:
    36. - linux
  2. Deploy the YAML to your Kubernetes cluster.

    1. kubectl apply -f deploy_linux.yaml

That’s it!

Clean up

To remove the deployments from this guide, run the following commands:

  1. kubectl delete -f deploy_linux.yaml
  2. kubectl delete -f deploy_windows.yaml
  3. helm uninstall dapr