Monday, November 14, 2022

Adding nerdctl to an OpenShift 4 Windows Node

# Getting a Windows Node on OpenShift
... Not what this post is about, follow the Red Hat and Microsoft documentation and then consult with your certified Red Hat Solutions Architect or Consultant. 

# Now that I have a windows node
*  Administering a windows node is highly discouraged and will probably result in an unsupported configuration.
In order to install nerdctl, log into the necessary Windows Node and switch to PowerShell.
```
ssh win2022

Microsoft Windows [Version 10.0.20348.1070]
(c) Microsoft Corporation. All rights reserved.

administrator@WIN2022 C:\Users\Administrator> powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\Users\Administrator>
```

# Append to System PATH - Permanently
Borrowing commands from a friendly blogger we need to append a new entry to the system PATH.  
[Permanently Modify System Path](https://codingbee.net/powershell/powershell-make-a-permanent-change-to-the-path-environment-variable)
Run these:
```
rem Show Current Path
PS C:\Users\Administrator> $ENV:PATH
rem Save Current Path to a variable
PS C:\Users\Administrator> $oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path

rem Add a new folder for our binary
PS C:\Users\Administrator> mkdir C:\bin
rem Change directory to the new folder
PS C:\Users\Administrator> cd C:\bin
PS C:\bin> $newpath = "$oldpath;C:\bin"

rem Update System Path
PS C:\bin> Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath

rem Verify the Path
PS C:\bin> (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path

rem Reboot node - or close out of your shells and relogin
Restart-Computer -Force
```

# Download and install nerdctl.exe
With all that yak shaving out of the way we can get to it.
Find the latest windows release (nerdctl-x.y.z-windows-amd64.tar.gz)
[nerdctl-1.0.0-windows-amd64.tar.gz](https://github.com/containerd/nerdctl/releases/download/v1.0.0/nerdctl-1.0.0-windows-amd64.tar.gz)
[nerdctl releases](https://github.com/containerd/nerdctl/releases)
```
rem start Powershell and change to the bin folder
rem Download the release file.
PS C:\bin> curl https://github.com/containerd/nerdctl/releases/download/v1.0.0/nerdctl-1.0.0-windows-amd64.tar.gz -o nerdctl-1.0.0-windows-amd64.tar.gz

rem Extract nerdctl.exe from the compressed file
PS C:\bin> tar -xzvf nerdctl-1.0.0-windows-amd64.tar.gz
x nerdctl.exe

rem Delete the compressed file
PS C:\bin> rm nerdctl-1.0.0-windows-amd64.tar.gz

rem Test a nerdctl.exe command
PS C:\bin> nerdctl.exe ps
CONTAINER ID    IMAGE    COMMAND    CREATED    STATUS    PORTS    NAMES

```


# Celebrate
You can now interact with your containers on the windows node.

Clearing Windows proxy from PowerShell

# The Problem
The Windows Server 2022 Core VM we were working with had a http proxy set but the OpenShift cluster was in an environment that did not need a proxy.  Using the top google hits we were unable to clear the "advproxy" settings.

```
C:\> netsh winhttp show proxy
Current WinHTTP proxy settings:

    Direct access (no proxy server).

C:\> netsh winhttp show advproxy
{
        "Proxy":        "localhost:8080",
        "ProxyBypass":  "*"
}
```

Using `netsh winhttp reset proxy` only cleared the proxy settings.  It did NOT clear the advproxy settings.


# The solution
Create a JSON file with the settings required for `netsh winhttp set advproxy` command.  
```
PS C:\Users\Administrator> New-Item proxy.json
    Directory: C:\Users\Administrator

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        11/14/2022   4:05 PM              0 proxy.json

PS C:\Users\Administrator> Set-Content .\proxy.json '{"Proxy": "", "ProxyBypass": "", "AutoconfigUrl": "", "AutoDetect": false}'
PS C:\Users\Administrator> Get-Content proxy.json
{"Proxy": ""}

```

Then execute the netsh command below:
```
netsh winhttp set advproxy setting-scope=machine settings-file=proxy.json

Current WinHTTP advanced proxy settings:

{
}

```

# Thank You
I do not know the difference between the two settings, just know they both influence the system.

Adding nerdctl to an OpenShift 4 Windows Node

# Getting a Windows Node on OpenShift ... Not what this post is about, follow the Red Hat and Microsoft documentation and then consult with...