Created
April 28, 2020 14:17
-
-
Save ry4nz/47dc9c3b18a7af8463af7fa12ebce3dc to your computer and use it in GitHub Desktop.
wargame yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# win-webserver.yaml | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: win-webserver | |
namespace: demo | |
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 | |
namespace: demo | |
name: win-webserver | |
namespace: demo | |
spec: | |
replicas: 2 | |
selector: | |
matchLabels: | |
app: win-webserver | |
template: | |
metadata: | |
labels: | |
app: win-webserver | |
name: win-webserver | |
spec: | |
affinity: | |
podAntiAffinity: | |
requiredDuringSchedulingIgnoredDuringExecution: | |
- labelSelector: | |
matchExpressions: | |
- key: app | |
operator: In | |
values: | |
- win-webserver | |
topologyKey: "kubernetes.io/hostname" | |
containers: | |
- name: windowswebserver | |
image: mcr.microsoft.com/windows/servercore:ltsc2019 | |
command: | |
- powershell.exe | |
- -command | |
- "<#code used from https://gist.github.com/wagnerandrade/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) } ; " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment