-
Notifications
You must be signed in to change notification settings - Fork 173
320 lines (278 loc) · 11 KB
/
AksTroubleshooting.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# Demonstrates various troubleshooting steps to check the AKS deployment
# Handy when there's strange errors to chase
name: AKS Troubleshooting Deployment
on:
workflow_call:
inputs:
Environment:
required: true
type: string
description: 'GitHub Environment'
RG:
required: true
type: string
description: 'Resource Group Name'
AKSNAME:
required: true
type: string
description: AKS Resource Name'
AGNAME:
default: ""
required: true
type: string
description: 'Application Gateway Resource Name'
LANAME:
default: ""
required: true
type: string
description: 'Log Analytics Resource Name'
LAWGUID:
default: ""
required: true
type: string
description: 'Log Analytics Workspace GUID'
USERUNCMD:
default: false
required: false
type: boolean
description: 'Run kubectl commands through RunCmd'
secrets:
AZURE_CREDENTIALS:
required: true
env:
AKSNAME: "${{ inputs.AKSNAME}}"
RG: "${{ inputs.RG }}"
jobs:
Log:
runs-on: ubuntu-latest
environment: ${{ inputs.Environment }}
steps:
- name: Parameter log
run: |
echo "Capturing environment parameters"
echo "--------------------------------"
echo "Environment is ${{ inputs.Environment }}"
echo "Use Run Cmd is ${{ inputs.USERUNCMD }}"
echo "RG is $RG"
echo "AKS name is $AKSNAME"
echo "AGW name is ${{ inputs.AGNAME }}"
echo "LA name is ${{ inputs.LANAME }}"
echo "LA workspace guid is ${{ inputs.LAWGUID }}"
VerifyMonitoring:
runs-on: ubuntu-latest
environment: ${{ inputs.Environment }}
if: always() && inputs.LANAME != '' && inputs.LAWGUID != ''
env:
LANAME: "${{ inputs.LANAME}}"
LAWGUID: "${{ inputs.LAWGUID}}"
steps:
- name: Param check
run: |
echo "Environment is ${{ inputs.Environment }}"
echo "RG is $RG"
echo "AKS name is $AKSNAME"
echo "LA name is $LANAME"
echo "LA workspace guid is $LAWGUID"
- name: Allow Monitoring extension
shell: pwsh
run: az extension add -n log-analytics -y
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
environment: azurecloud
allow-no-subscriptions: false
- name: Log Analytics log table verification
shell: pwsh
run: |
Write-Output "Check for Logs in the Log Analytics ($env:LANAME) Workspace ($env:LAWGUID)"
$KubeNode = az monitor log-analytics query -w $env:LAWGUID --analytics-query "KubeNodeInventory | count" -o json | ConvertFrom-Json
Write-Output $KubeNode
Write-Output $KubeNode[0].Count
if ($KubeNode[0].Count -eq 0) {
throw "Log Analytics Workspace table: KubeNodeInventory does not have any data. Check network traffic is not being supressed by firewall egress rules"
}
$containers = az monitor log-analytics query -w $env:LAWGUID --analytics-query "ContainerLog | join(KubePodInventory| where TimeGenerated > startofday(ago(1h))) on ContainerID |where TimeGenerated > startofday(ago(10m)) | project TimeGenerated ,Namespace , LogEntrySource , LogEntry | summarize count() by Namespace, LogEntrySource"
Write-Output $containers
- name: Flow Logs Deny checks
shell: pwsh
continue-on-error: true #The query will fail if NSG flow logs are not being captured
run: |
Write-Output "Check for Logs in the Log Analytics ($env:LANAME) Workspace ($env:LAWGUID)"
$query="AzureNetworkAnalytics_CL |where DeniedInFlows_d > 0 or DeniedOutFlows_d > 0 |project FlowStartTime_t, NSGRule_s, SourceSystem, FlowType_s, DestIP_s, DestPort_d, Subnet_s"
Write-Output "Sending Query $query"
$DenyLogs = az monitor log-analytics query -w $env:LAWGUID --analytics-query $query -o json | ConvertFrom-Json
Write-Output $DenyLogs
- name: Flow Logs IP Details Check
shell: pwsh
continue-on-error: true #The query will fail if NSG flow logs are not being captured
run: |
Write-Output "Check for Logs in the Log Analytics ($env:LANAME) Workspace ($env:LAWGUID)"
$query="AzureNetworkAnalyticsIPDetails_CL"
Write-Output "Sending Query $query"
$Logs = az monitor log-analytics query -w $env:LAWGUID --analytics-query $query -o json | ConvertFrom-Json
Write-Output $Logs
CaptureAgicLogs:
runs-on: ubuntu-latest
environment: ${{ inputs.Environment }}
if: always() && inputs.AGNAME != ''
steps:
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
environment: azurecloud
allow-no-subscriptions: false
- name: AKS Connect
if: inputs.USERUNCMD == false
run: az aks get-credentials -n $AKSNAME -g $RG --overwrite-existing
- name: Kubelogin
if: inputs.USERUNCMD == false
timeout-minutes: 2
env:
kubeloginversion: 'v0.0.28'
run: |
wget https://github.com/Azure/kubelogin/releases/download/${{ env.kubeloginversion }}/kubelogin-linux-amd64.zip
unzip kubelogin-linux-amd64.zip
sudo mv bin/linux_amd64/kubelogin /usr/bin
kubelogin convert-kubeconfig -l azurecli
kubectl get nodes
- name: Get Agic pod name
id: agicpodname
timeout-minutes: 1
env:
NAMESP: "kube-system"
AGICLABEL: "app=ingress-appgw"
USERUNCMD: ${{ inputs.USERUNCMD }}
run: |
NAMESPACEPODS="kubectl get pods -n $NAMESP -l $AGICLABEL -o json"
echo $NAMESPACEPODS
if [ "$USERUNCMD" == "true" ];
then
echo "Sending command $NAMESPACEPODS to $AKSNAME in $RG";
cmdOut=$(az aks command invoke -g $RG -n $AKSNAME -o json --command "${NAMESPACEPODS}");
echo $cmdOut > debug-agic-cmdout.json
PODS=$(echo $cmdOut | jq -r '.logs')
echo $PODS > debug-getagicpod-logs.json
else
PODS=$($NAMESPACEPODS)
fi
APPGWPOD=$(echo $PODS | jq -r '.items[] | select(.metadata.name | test("appgw-")).metadata.name')
echo "Found AGIC pod name: $APPGWPOD"
echo "APPGWPOD=$APPGWPOD" >> $GITHUB_OUTPUT
- name: Describe AGIC Pod
env:
NAMESP: "kube-system"
APPGWPODNAME: ${{ steps.agicpodname.outputs.APPGWPOD}}
USERUNCMD: ${{ inputs.USERUNCMD }}
run: |
DESCRIBEPODCMD="kubectl describe po -n $NAMESP $APPGWPODNAME"
if [ "$USERUNCMD" == "true" ];
then
echo "Sending command $DESCRIBEPODCMD to $AKSNAME in $RG";
cmdOut=$(az aks command invoke -g $RG -n $AKSNAME -o json --command "${DESCRIBEPODCMD}");
echo $cmdOut > debug-describe-agic.json
else
$DESCRIBEPODCMD > debug-describe-agic.json
fi
echo "Grabbing AGIC image version"
cat debug-describe-agic.json | grep Image:
- name: Grab full AGIC pod logs
continue-on-error: true
env:
NAMESP: "kube-system"
APPGWPODNAME: ${{ steps.agicpodname.outputs.APPGWPOD}}
USERUNCMD: ${{ inputs.USERUNCMD }}
run: |
PODLOGSCMD="kubectl logs -n $NAMESP $APPGWPODNAME"
if [ "$USERUNCMD" == "true" ];
then
echo "Sending command $PODLOGSCMD to $AKSNAME in $RG";
cmdOut=$(az aks command invoke -g $RG -n $AKSNAME -o json --command "${PODLOGSCMD}");
echo $cmdOut > debug-agic-podlogs.json
PODLOGS=$(echo $cmdOut | jq -r '.logs')
echo $PODLOGS > debug-agic-podlogs.txt
else
$PODLOGSCMD > debug-agic-podlogs.txt
fi
cat debug-agic-podlogs.txt | grep invalid > debug-agic-podlogs-invalid.txt
- name: Store any generated debug json files as artifacts
if: always()
uses: actions/[email protected]
with:
name: Troubleshooting-AGIC
path: debug*.*
CaptureAKSLogs:
runs-on: ubuntu-latest
environment: ${{ inputs.Environment }}
if: always() && inputs.AKSNAME != ''
steps:
- name: Param check
run: |
echo "Environment is ${{ inputs.Environment }}"
echo "RG is $RG"
echo "AKS name is $AKSNAME"
echo "LA name is ${{ inputs.LANAME }}"
echo "LA workspace guid is ${{ inputs.LAWGUID }}"
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
environment: azurecloud
allow-no-subscriptions: false
- name: AKS Connect
if: inputs.USERUNCMD == false
run: az aks get-credentials -n $AKSNAME -g $RG --overwrite-existing
- name: Kubelogin
if: inputs.USERUNCMD == false
env:
kubeloginversion: 'v0.0.28'
run: |
wget https://github.com/Azure/kubelogin/releases/download/${{ env.kubeloginversion }}/kubelogin-linux-amd64.zip
unzip kubelogin-linux-amd64.zip
sudo mv bin/linux_amd64/kubelogin /usr/bin
kubelogin convert-kubeconfig -l azurecli
- name: Check Run Command
if: inputs.USERUNCMD == true
uses: Azure/cli@v2
env:
AZCLIVERSION: latest
with:
azcliversion: ${{ env.AZCLIVERSION }}
inlineScript: |
command="kubectl get nodes"
echo "Sending command $command to AKS"
cmdOut=$(az aks command invoke -g $RG -n $AKSNAME -o json --command "${command}")
echo $cmdOut
- name: Kubectl get event Warnings
env:
USERUNCMD: inputs.USERUNCMD
run: |
geteventcmd="kubectl get events --sort-by='.metadata.creationTimestamp' -A | grep Warning"
if [ "$USERUNCMD" != "true" ];
then
echo "Grep command not in RunCmd Container. Setting unfiltered command."
geteventcmd="kubectl get events --sort-by='.metadata.creationTimestamp' -A"
echo "Sending command $geteventcmd to $AKSNAME in $RG";
cmdOut=$(az aks command invoke -g $RG -n $AKSNAME -o json --command "${geteventcmd}");
echo $cmdOut;
else
$geteventcmd
fi
- name: Check Events for default namespace
env:
NAMESP: "default"
USERUNCMD: inputs.USERUNCMD
run: |
geteventcmd="kubectl get events -n $NAMESP"
if [ "$USERUNCMD" != "true" ];
then
echo "Sending command $geteventcmd to $AKSNAME in $RG";
cmdOut=$(az aks command invoke -g $RG -n $AKSNAME -o json --command "${geteventcmd}");
echo $cmdOut;
else
$geteventcmd
fi