---
title: Provisioning a windows worker node
exercise: 3
date: '2024-05-26'
tags: ['openshift','windows','kubernetes','containers']
draft: false
authors: ['default']
summary: "Auto scaling nodes with machine sets!"
---


Now that our cluster is ready to support Windows nodes lets provision one through the Machine API.

The Machine API is a combination of primary resources that are based on the upstream [Cluster API](https://github.com/kubernetes-sigs/cluster-api) project and custom OpenShift Container Platform resources.

The two primary resources are:

**1. Machines**

> A fundamental unit that describes the host for a Node. A machine has a providerSpec, which describes the types of compute nodes that are offered for different cloud platforms. For example, a machine type for a worker node on Amazon Web Services (AWS) might define a specific machine type and required metadata.

**2. MachineSets**

> Groups of machines. MachineSets are to machines as ReplicaSets are to Pods. If you need more machines or must scale them down, you change the **replicas** field on the MachineSet to meet your compute need.


## 3.1 Create a single replica machineset

In this excersie we will create a `MachineSet`. Once created this will automatically begin provisoning a Windows machine and adding it to our cluster as a worker node.

Below is a yaml snippet we will use as base to create our `MachineSet`:

```yaml
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
  name: windows
  namespace: openshift-machine-api
spec:
  replicas: 1
  selector:
    matchLabels:
      machine.openshift.io/cluster-api-cluster: demo
      machine.openshift.io/cluster-api-machineset: windows
  template:
    metadata:
      labels:
        machine.openshift.io/cluster-api-cluster: demo
        machine.openshift.io/cluster-api-machine-role: worker
        machine.openshift.io/cluster-api-machine-type: worker
        machine.openshift.io/cluster-api-machineset: windows
        machine.openshift.io/os-id: Windows
    spec:
      lifecycleHooks: {}
      metadata:
        labels:
          node-role.kubernetes.io/worker: ''
      providerSpec:
        value:
          userDataSecret:
            name: windows-user-data
          placement:
            availabilityZone: ap-southeast-1c
            region: ap-southeast-1
          credentialsSecret:
            name: aws-cloud-credentials
          instanceType: m5a.4xlarge
          metadata:
            creationTimestamp: null
          blockDevices:
            - ebs:
                iops: 0
                kmsKey: {}
                volumeSize: 120
                volumeType: gp2
          securityGroups:
            - filters:
                - name: 'tag:Name'
                  values:
                    - cluster-<id>-worker-sg
          kind: AWSMachineProviderConfig
          metadataServiceOptions: {}
          tags:
            - name: kubernetes.io/cluster/cluster-<id>
              value: owned
          deviceIndex: 0
          ami:
            id: ami-0e76083a67107f741
          subnet:
            filters:
              - name: 'tag:Name'
                values:
                  - cluster-<id>-private-ap-southeast-1c
          apiVersion: awsproviderconfig.openshift.io/v1beta1
          iamInstanceProfile:
            id: cluster-<id>-worker-profile

```

There are four references to `<id>` in the sample that we need to replace with the actual cluster id for the cluster we have been allocated for the workshop.

Run the following command in your bastion host to find your cluster id:

```bash
name=$(oc get machineset -n openshift-machine-api cluster-nkpgx-zf758-worker-ap-southeast-1c -o jsonpath={.metadata.name})

echo ${name:8:11}
```

After retrieving your cluster id which will look something like example `nkpgx-zf758` update the sample `MachineSet` using your preferred text editor, then select and copy all of the text to clipboard.

Within OpenShift you can then click the ➕ button in the top right hand corner, paste in your yaml and click **Create**. 

