-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Daemoset yaml to capture dns packets from specific compartment.
- Loading branch information
1 parent
f08b6f3
commit 7b9dbf1
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
Kubernetes/windows/debug/dnsmonitor/DnsPktMonitor2019.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
apiVersion: apps/v1 | ||
kind: DaemonSet | ||
metadata: | ||
name: dns-pkt-capture | ||
labels: | ||
app: dns-pkt-capture | ||
spec: | ||
selector: | ||
matchLabels: | ||
name: dns-pkt-capture | ||
template: | ||
metadata: | ||
labels: | ||
name: dns-pkt-capture | ||
spec: | ||
securityContext: | ||
windowsOptions: | ||
hostProcess: true | ||
runAsUserName: "NT AUTHORITY\\SYSTEM" | ||
hostNetwork: true | ||
containers: | ||
- name: dns-pkt-capture | ||
image: mcr.microsoft.com/windows/nanoserver:1809 | ||
command: | ||
- powershell.exe | ||
- -command | ||
- | | ||
$stopPktmon = $false | ||
$podPrefix = "tcp-server" | ||
$pktmonLogs = "C:\pktmonLogs" | ||
Write-Host "Stop pktmon if running..." | ||
pktmon stop | ||
if($stopPktmon) { | ||
Write-Host "Pktmon stopped. Logs will be available in : $pktmonLogs ..." | ||
While($true) { | ||
Start-Sleep -Seconds 60 | ||
} | ||
return | ||
} | ||
$pods = (crictl pods -o json | ConvertFrom-Json).items | ||
$podIPs = @() | ||
$macAddrs = @() | ||
foreach($pod in $pods) { | ||
if($pod.metadata.name -like "$podPrefix*") { | ||
$podInspect = (crictl inspectp $pod.id | ConvertFrom-Json) | ||
$podIP = $podInspect.status.network.ip | ||
$podIPs += $podIP | ||
$macAddrs += (Get-HnsEndpoint | where IPAddress -EQ $podIP).MacAddress | ||
} | ||
} | ||
Write-Host "POD IPS : $podIPs" | ||
Write-Host "MAC ADDRESSES : $macAddrs" | ||
$compIds = "" | ||
foreach($mac in $macAddrs) { | ||
$grepped = pktmon list | Select-String $mac | ||
$compId = $grepped.ToString().Split(" ")[3] | ||
if($compId -ne "") { | ||
if($compIds -eq "") { | ||
$compIds = $compId | ||
} else { | ||
$compIds += "," | ||
$compIds += $compId | ||
} | ||
} | ||
} | ||
Write-Host "COMPONENT IDS : $compIds" | ||
Write-Host "Removing all pktmon filters if anything existing..." | ||
pktmon filter remove | ||
Write-Host "Create DNS Port filter..." | ||
pktmon filter add DNSFilter -p 53 | ||
Write-Host "Create a directory for pktmon logs..." | ||
remove-item -Recurse -Force $pktmonLogs -ErrorAction Ignore | ||
mkdir $pktmonLogs | ||
Set-Location $pktmonLogs | ||
Write-Host "Start pktmon. Command : [pktmon start -c --comp $compIds -m multi-file] ..." | ||
pktmon start -c --comp $compIds -m multi-file | ||
Write-Host "Logs will be available in $pktmonLogs" | ||
While($true) { | ||
Start-Sleep -Seconds 60 | ||
} | ||
securityContext: | ||
privileged: true | ||
nodeSelector: | ||
kubernetes.azure.com/os-sku: Windows2019 |