Skip to content

Instantly share code, notes, and snippets.

@jonaskello
Last active April 7, 2026 12:33
Show Gist options
  • Select an option

  • Save jonaskello/138d0b00aec844b045ab8f413fcd3a6e to your computer and use it in GitHub Desktop.

Select an option

Save jonaskello/138d0b00aec844b045ab8f413fcd3a6e to your computer and use it in GitHub Desktop.

Revisions

  1. jonaskello revised this gist Jul 2, 2022. No changes.
  2. jonaskello revised this gist Jul 2, 2022. 1 changed file with 31 additions and 0 deletions.
    31 changes: 31 additions & 0 deletions upgrade-win-node.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    # https://v1-20.docs.kubernetes.io/docs/tasks/administer-cluster/kubeadm/upgrading-windows-nodes/

    ### *** NOTE: ***
    ### Before running this script you should drain the node:
    ###
    ### kubectl drain myworkernode --ignore-daemonsets --delete-emptydir-data
    ###
    ### And after this script you should uncordon it:
    ###
    ### kubectl uncordon myworkernode
    ###

    # POWERSHELL

    $env:VERSION = '1.24.1'

    # Upgrade kubeadm
    curl.exe -Lo C:\k\kubeadm.exe https://dl.k8s.io/v$env:VERSION/bin/windows/amd64/kubeadm.exe

    # Upgrade the kubelet configuration
    kubeadm upgrade node

    # Upgrade kubelet
    stop-service kubelet
    curl.exe -Lo C:\k\kubelet.exe https://dl.k8s.io/v$env:VERSION/bin/windows/amd64/kubelet.exe
    restart-service kubelet

    # Upgrade kube-proxy
    # This is only needed once for all windows worker nodes
    # From a LINUX machine with access to the Kubernetes API, run the following, again replacing v1.20.13 with your desired version:
    VERSION=1.24.1 && curl -L https://github.com/kubernetes-sigs/sig-windows-tools/releases/latest/download/kube-proxy.yml | sed "s/VERSION/v$VERSION/g" | kubectl apply -f -
  3. jonaskello revised this gist Jul 1, 2022. 1 changed file with 60 additions and 0 deletions.
    60 changes: 60 additions & 0 deletions upgrade-flannel.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    # flannel upgrade

    Instructions on how to upgrade:

    https://github.com/flannel-io/flannel/blob/master/Documentation/upgrade.md

    > To follow that approach one just needs to have a definition of the current version of flannel and the new one. kubectl delete -f .yaml and kubectl create -f .yaml will do the thing
    The instructions on how to install flannel always installs the latest version of the manifests so we need to backtrack and find what we have actuall installed.

    # Getting new files

    We need new versions of

    - `kube-flannel.yml` (this is the linux flannel)
    - `flannel-overlay.yml` (this is the windows flannel)

    Linux: Use history to find the latest version of this file that has the version of flannel you are installing: https://github.com/flannel-io/flannel/blob/master/Documentation/kube-flannel.yml. For example for 0.14.0 it is this version: https://github.com/flannel-io/flannel/blob/584c19aebe302db6318e2063e1359a78a63a4ecf/Documentation/kube-flannel.yml

    Windows: Make sure flannel-overlay.yml is using hostprocess and not the old wins with script version. At the time of writing this was located here: https://github.com/kubernetes-sigs/sig-windows-tools/blob/master/hostprocess/flannel/flanneld/flannel-overlay.yml

    > IMPORTANT: After we get the new files we need to patch them
    ## Patch linux file

    According to instructions here the linux file must be patched:

    https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/adding-windows-nodes/#configuring-flannel

    Need to change this in kube-flannel.yml (linux):

    ```
    net-conf.json: |
    {
    "Network": "10.244.0.0/16",
    "Backend": {
    "Type": "vxlan",
    "VNI": 4096,
    "Port": 4789
    }
    }
    ```

    ## Patch windows file

    No patch is needed for hostprocess.

    # Upgrading

    So we need the original files that were installed, and the new files with patches from above, and then run this:

    ```bash
    kubectl delete -f original/flannel-overlay.yml
    kubectl delete -f original/kube-flannel.yml
    # wait a bit
    kubectl apply -f new/kube-flannel.yml
    kubectl delete -f new/flannel-overlay.yml
    ```
  4. jonaskello created this gist Jul 1, 2022.
    12 changes: 12 additions & 0 deletions prep-windows-node-step1.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # Make sure you have enabled "Expose hardware assisted virtualization to the guest OS" for the VMWare CPU

    Write-Host "##############################`nInstalling features: Containers, Hyper-V, Hyper-V-PowerShell`n##############################`n"
    Install-WindowsFeature Containers
    Install-WindowsFeature Hyper-V
    Install-WindowsFeature Hyper-V-PowerShell

    Write-Host "##############################`nDisabling firewall`n##############################`n"
    Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False

    Write-Host "##############################`nRestarting...`n##############################`n"
    Restart-Computer -force
    62 changes: 62 additions & 0 deletions prep-windows-node-step2.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@

    Write-Host "##############################`nInstalling ContainerD`n##############################`n"

    # Download and extract desired containerd Windows binaries
    $ContainerDVersion="1.6.4"
    curl.exe -L https://github.com/containerd/containerd/releases/download/v$ContainerDVersion/containerd-$ContainerDVersion-windows-amd64.tar.gz -o containerd-windows-amd64.tar.gz
    tar.exe xvf .\containerd-windows-amd64.tar.gz

    # Add containerd to path
    $global:ContainerDPath = "$env:ProgramFiles\containerd"
    $env:Path += ";$global:ContainerDPath"
    [Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)

    # Copy and configure
    Copy-Item -Path ".\bin\" -Destination "$global:ContainerDPath" -Recurse -Force
    containerd.exe config default | Out-File "$global:ContainerDPath\config.toml" -Encoding ascii

    # Review the configuration. Depending on setup you may want to adjust:
    # - the sandbox_image (Kubernetes pause image)
    # - cni bin_dir and conf_dir locations
    Get-Content "$global:ContainerDPath\config.toml"

    #config file fixups
    $config = Get-Content "$global:ContainerDPath\config.toml"
    $config = $config -replace "bin_dir = (.)*$", "bin_dir = `"c:/opt/cni/bin`""
    $config = $config -replace "conf_dir = (.)*$", "conf_dir = `"c:/etc/cni/net.d`""
    $config | Set-Content "$global:ContainerDPath\config.toml" -Force

    # Create dirs for cni
    mkdir -Force c:\opt\cni\bin | Out-Null
    mkdir -Force c:\etc\cni\net.d | Out-Null

    # Register and start service
    containerd.exe --register-service
    Start-Service containerd

    Write-Host "##############################`nInstalling crictl`n##############################`n"

    $crictl_version="1.24.1"

    # Install crictl from the cri-tools project which is required so that kubeadm can talk to the CRI endpoint.
    curl.exe -LO https://github.com/kubernetes-sigs/cri-tools/releases/download/v$crictl_version/crictl-v$crictl_version-windows-amd64.tar.gz
    tar xvf crictl-v$crictl_version-windows-amd64.tar.gz
    mv crictl.exe "$global:ContainerDPath"

    # Configure crictl
    mkdir -Force "$home\.crictl"
    @"
    runtime-endpoint: npipe://./pipe/containerd-containerd
    image-endpoint: npipe://./pipe/containerd-containerd
    timeout: 10
    #debug: true
    "@ | Set-Content "$home\.crictl\crictl.yaml" -Force
    crictl.exe info

    Write-Host "##############################`nInstalling wins, kubelet, and kubeadm`n##############################`n"

    $k8s_version="1.23.6"

    # Install wins, kubelet, and kubeadm
    curl.exe -LO https://raw.githubusercontent.com/kubernetes-sigs/sig-windows-tools/master/kubeadm/scripts/PrepareNode.ps1
    .\PrepareNode.ps1 -KubernetesVersion v$k8s_version -ContainerRuntime containerD
    8 changes: 8 additions & 0 deletions prep-windows-node-step3.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@

    # Done - please remember to add '--cri-socket "npipe:////./pipe/containerd-containerd"' to your kubeadm join command

    # Join the node (run this on the windows worker node)
    kubeadm join mymaster:6443 --token xxxxx --discovery-token-ca-cert-hash sha256:xxxxxx --cri-socket "npipe:////./pipe/containerd-containerd"

    #Add a taint to the windows worker so linux daemonsets are not scheduled on it (do it on a linux node)
    kubectl taint nodes mynode os=Win1809:NoSchedule