Skip to content

Instantly share code, notes, and snippets.

@PatrickLang
Last active March 16, 2022 13:06
Show Gist options
  • Save PatrickLang/10dbe208b1eac4e354acbfe165e9fcca to your computer and use it in GitHub Desktop.
Save PatrickLang/10dbe208b1eac4e354acbfe165e9fcca to your computer and use it in GitHub Desktop.
Experiments with namespaces on Windows Pods
  1. kubectl create -f iis-multi.yml

  2. Log into the node

I can see the three containers running - pause, iis and windowswebserver. If I do a docker exec ... tasklist on each one, the processes listed are separate.

docker ps |select-string p7rm7

6a70b90f2fdf        17b224ab9b3a        "powershell.exe -com…"    About a minute ago   Up About a minute
          k8s_windowswebserver_iis-2019-5d465d7bb9-p7rm7_default_ecf61b0b-2360-11e9-ab5f-000d3afd3b6d_0
ba7d754faf61        9235cfdefbee        "C:\\ServiceMonitor.e…"   About a minute ago   Up About a minute
          k8s_iis_iis-2019-5d465d7bb9-p7rm7_default_ecf61b0b-2360-11e9-ab5f-000d3afd3b6d_0
d25a15c3018d        kubletwin/pause     "cmd /S /C 'cmd /c p…"    About a minute ago   Up About a minute
          k8s_POD_iis-2019-5d465d7bb9-p7rm7_default_ecf61b0b-2360-11e9-ab5f-000d3afd3b6d_0


PS C:\Users\azureuser> docker exec 6a70b90f2fdf  tasklist

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
System Idle Process              0                            0          8 K
System                           4                            0        160 K
smss.exe                     20468                            0      1,224 K
csrss.exe                    27236 Services                   7      4,860 K
wininit.exe                  11804 Services                   7      6,980 K
services.exe                 33244 Services                   7      6,380 K
lsass.exe                    33856 Services                   7     12,592 K
svchost.exe                  32520 Services                   7     10,040 K
fontdrvhost.exe              15700 Services                   7      3,268 K
svchost.exe                  37880 Services                   7      8,120 K
svchost.exe                  12988 Services                   7     24,088 K
svchost.exe                  28804 Services                   7      9,052 K
CExecSvc.exe                 22912 Services                   7      4,712 K
svchost.exe                  35112 Services                   7     14,204 K
powershell.exe               18072 Services                   7     73,640 K
svchost.exe                  18820 Services                   7     19,564 K
svchost.exe                  35284 Services                   7      5,656 K
svchost.exe                  21264 Services                   7     21,464 K
svchost.exe                  24260 Services                   7      6,340 K
tasklist.exe                 32200 Services                   7      7,536 K
WmiPrvSE.exe                 29940 Services                   7      8,320 K
PS C:\Users\azureuser> docker exec  ba7d754faf61 tasklist

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
System Idle Process              0                            0          8 K
System                           4                            0        160 K
smss.exe                     31828                            0      1,224 K
csrss.exe                    28132 Services                   6      4,884 K
wininit.exe                  14976 Services                   6      7,136 K
services.exe                 29432 Services                   6      6,268 K
lsass.exe                    16284 Services                   6     12,924 K
svchost.exe                  31192 Services                   6      8,232 K
fontdrvhost.exe              32168 Services                   6      3,228 K
svchost.exe                  33284 Services                   6     10,072 K
svchost.exe                  29476 Services                   6     24,212 K
svchost.exe                  32708 Services                   6      8,996 K
CExecSvc.exe                 22636 Services                   6      4,828 K
svchost.exe                  31988 Services                   6     13,904 K
ServiceMonitor.exe           32140 Services                   6      4,036 K
svchost.exe                  24040 Services                   6     19,124 K
svchost.exe                  27972 Services                   6     10,780 K
svchost.exe                  27924 Services                   6      5,680 K
svchost.exe                  28016 Services                   6     20,360 K
svchost.exe                  33820 Services                   6     11,640 K
WmiPrvSE.exe                  6896 Services                   6      8,708 K
tasklist.exe                 25040 Services                   6      7,544 K

Looking at the network - they share the same vNIC and hostname:

docker exec  ba7d754faf61 hostname
iis-2019-5d465d7bb9-p7rm7
PS C:\Users\azureuser> docker exec 6a70b90f2fdf hostname
iis-2019-5d465d7bb9-p7rm7
PS C:\Users\azureuser> docker exec 6a70b90f2fdf ipconfig

Windows IP Configuration


Ethernet adapter vEthernet (d25a15c3-eth0):

   Connection-specific DNS Suffix  . : default.svc.cluster.local
   Link-local IPv6 Address . . . . . : fe80::fc4f:87c3:b5dc:8b49%28
   IPv4 Address. . . . . . . . . . . : 10.240.0.47
   Subnet Mask . . . . . . . . . . . : 255.240.0.0
   Default Gateway . . . . . . . . . : 10.240.0.1
PS C:\Users\azureuser> docker exec  ba7d754faf61 ipconfig

Windows IP Configuration


Ethernet adapter vEthernet (d25a15c3-eth0):

   Connection-specific DNS Suffix  . : default.svc.cluster.local
   Link-local IPv6 Address . . . . . : fe80::fc4f:87c3:b5dc:8b49%28
   IPv4 Address. . . . . . . . . . . : 10.240.0.47
   Subnet Mask . . . . . . . . . . . : 255.240.0.0
   Default Gateway . . . . . . . . . : 10.240.0.1

The root filesystem of each is different because they're started from different images

docker exec  ba7d754faf61 cmd /c dir c:\
 Volume in drive C has no label.
 Volume Serial Number is 58A5-6DF3

 Directory of c:\

01/09/2019  01:29 AM    <DIR>          inetpub
09/15/2018  09:42 AM             5,510 License.txt
01/02/2019  10:33 PM    <DIR>          Program Files
01/02/2019  10:32 PM    <DIR>          Program Files (x86)
01/09/2019  01:30 AM           172,328 ServiceMonitor.exe
01/02/2019  10:34 PM    <DIR>          Users
01/29/2019  12:58 AM    <DIR>          var
01/09/2019  01:29 AM    <DIR>          Windows
               2 File(s)        177,838 bytes
               6 Dir(s)  21,173,903,360 bytes free
PS C:\Users\azureuser> docker exec 6a70b90f2fdf cmd /c dir c:\
 Volume in drive C has no label.
 Volume Serial Number is 58A5-6DF3

 Directory of c:\

09/15/2018  09:42 AM             5,510 License.txt
01/02/2019  10:33 PM    <DIR>          Program Files
01/02/2019  10:32 PM    <DIR>          Program Files (x86)
01/02/2019  10:34 PM    <DIR>          Users
01/29/2019  12:58 AM    <DIR>          var
01/29/2019  01:01 AM    <DIR>          Windows
               1 File(s)          5,510 bytes
               5 Dir(s)  21,174,878,208 bytes free
apiVersion: apps/v1
kind: Deployment
metadata:
name: iis-2019
labels:
app: iis-2019
spec:
replicas: 1
template:
metadata:
name: iis-2019
labels:
app: iis-2019
spec:
containers:
- name: iis
image: mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019
resources:
limits:
cpu: 1
memory: 800m
requests:
cpu: .1
memory: 300m
ports:
- containerPort: 80
- name: windowswebserver
image: mcr.microsoft.com/windows/servercore:1809
command:
- powershell.exe
- -command
- "<#code used from https://gist.github.com/wagnerandrade/5424431#> ; $$listener = New-Object System.Net.HttpListener ; $$listener.Prefixes.Add('http://*:81/') ; $$listener.Start() ; $$callerCounts = @{} ; Write-Host('Listening at http://*:81/') ; 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:
"beta.kubernetes.io/os": windows
selector:
matchLabels:
app: iis-2019
---
apiVersion: v1
kind: Service
metadata:
name: iis
spec:
type: LoadBalancer
ports:
- protocol: TCP
port: 80
selector:
app: iis-2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment