Make Windows multi-cluster

Make Windows a multi-cluster example. Allow test to use fleet binaries
from any path.
This commit is contained in:
Nick Gerace
2021-02-18 16:04:21 -05:00
parent 2ec09778b8
commit 3162ee1212
10 changed files with 99 additions and 53 deletions

View File

@@ -0,0 +1,5 @@
apiVersion: v2
name: windows-app
description: Sample Windows application
version: 0.0.0
appVersion: 0.0.0

View File

@@ -0,0 +1,47 @@
# Windows Helm Example
This example will deploy the [Windows application example](https://kubernetes.io/docs/setup/production-environment/windows/user-guide-windows-containers/) packaged as a Helm chart.
This must be deployed in a multi-cluster configuration.
## Preparing Your Downstream Cluster(s)
Clusters (`clusters.fleet.cattle.io`) must have the `windows.version` label in order for the example to be deployed.
You can determine the value for the `windows.version` label key based on the release version of your Windows node(s).
Description | Example
--- | ---
For Windows Server SAC nodes, the value will be the SAC release number prepended with "win". | 2004 SAC would result in `windows.version: win2004`
For Windows Server LTSC nodes, the value will be the SAC release number that the LTSC is based on. | 2019 LTSC would result in `windows.version: win1809`
## Creating the GitRepo
Create the following `GitRepo` in your local cluster to get started.
```yaml
kind: GitRepo
apiVersion: fleet.cattle.io/v1alpha1
metadata:
name: helm
namespace: fleet-default
spec:
repo: https://github.com/rancher/fleet-examples
paths:
- multi-cluster/windows-helm
targets:
- name: win2004
clusterSelector:
matchLabels:
windows.version: win2004
- name: win1909
clusterSelector:
matchLabels:
windows.version: win1909
- name: win1903
clusterSelector:
matchLabels:
windows.version: win1903
- name: win1809
clusterSelector:
matchLabels:
windows.version: win1809
```

View File

@@ -0,0 +1,34 @@
namespace: fleet-helm-windows-example
targetCustomizations:
- name: win2004
helm:
values:
image:
tag: 2004
clusterSelector:
matchLabels:
windows.version: win2004
- name: win1909
helm:
values:
image:
tag: 1909
clusterSelector:
matchLabels:
windows.version: win1909
- name: win1903
helm:
values:
image:
tag: 1903
clusterSelector:
matchLabels:
windows.version: win1903
- name: win1809
helm:
values:
image:
tag: 1809
clusterSelector:
matchLabels:
windows.version: win1809

View File

@@ -0,0 +1,47 @@
# Source: https://kubernetes.io/docs/setup/production-environment/windows/user-guide-windows-containers/
apiVersion: v1
kind: Service
metadata:
name: win-webserver
labels:
app: win-webserver
spec:
ports:
# the port that this service should serve on
- port: 80
targetPort: 80
selector:
app: win-webserver
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: win-webserver
name: win-webserver
spec:
replicas: 2
selector:
matchLabels:
app: win-webserver
template:
metadata:
labels:
app: win-webserver
name: win-webserver
spec:
containers:
- name: windowswebserver
image: "mcr.microsoft.com/windows/servercore:{{ .Values.image.tag }}"
command:
- powershell.exe
- -command
- "<#code used from https://gist.github.com/19WAS85/5424431#> ; $$listener = New-Object System.Net.HttpListener ; $$listener.Prefixes.Add('http://*:80/') ; $$listener.Start() ; $$callerCounts = @{} ; Write-Host('Listening at http://*:80/') ; while ($$listener.IsListening) { ;$$context = $$listener.GetContext() ;$$requestUrl = $$context.Request.Url ;$$clientIP = $$context.Request.RemoteEndPoint.Address ;$$response = $$context.Response ;Write-Host '' ;Write-Host('> {0}' -f $$requestUrl) ; ;$$count = 1 ;$$k=$$callerCounts.Get_Item($$clientIP) ;if ($$k -ne $$null) { $$count += $$k } ;$$callerCounts.Set_Item($$clientIP, $$count) ;$$ip=(Get-NetAdapter | Get-NetIpAddress); $$header='<html><body><H1>Windows Container Web Server</H1>' ;$$callerCountsString='' ;$$callerCounts.Keys | % { $$callerCountsString+='<p>IP {0} callerCount {1} ' -f $$ip[1].IPAddress,$$callerCounts.Item($$_) } ;$$footer='</body></html>' ;$$content='{0}{1}{2}' -f $$header,$$callerCountsString,$$footer ;Write-Output $$content ;$$buffer = [System.Text.Encoding]::UTF8.GetBytes($$content) ;$$response.ContentLength64 = $$buffer.Length ;$$response.OutputStream.Write($$buffer, 0, $$buffer.Length) ;$$response.Close() ;$$responseStatus = $$response.StatusCode ;Write-Host('< {0}' -f $$responseStatus) } ; "
nodeSelector:
kubernetes.io/os: windows
tolerations:
- key: cattle.io/os
operator: "Equal"
value: "windows"
effect: NoSchedule

View File

@@ -0,0 +1,2 @@
image:
tag: 2004