@@ -270,11 +270,13 @@ function Disable-WindowsDefender {
270
270
# Creates directories where other functions in this module will read and write
271
271
# data.
272
272
# Note: C:\tmp is required for running certain kubernetes tests.
273
+ # C:\var\log is used by kubelet to stored container logs and also
274
+ # hard-coded in the fluentd/stackdriver config for log collection.
273
275
function Create-Directories {
274
276
Log- Output " Creating ${env: K8S_DIR} and its subdirectories."
275
277
ForEach ($dir in (" ${env: K8S_DIR} " , " ${env: NODE_DIR} " , " ${env: LOGS_DIR} " ,
276
278
" ${env: CNI_DIR} " , " ${env: CNI_CONFIG_DIR} " , " ${env: MANIFESTS_DIR} " ,
277
- " ${env: PKI_DIR} " ), " C:\tmp" ) {
279
+ " ${env: PKI_DIR} " ), " C:\tmp" , " C:\var\log " ) {
278
280
mkdir - Force $dir
279
281
}
280
282
}
@@ -1059,7 +1061,7 @@ function Create-DockerRegistryKey {
1059
1061
# TODO(pjh): move the Stackdriver logging agent code below into a separate
1060
1062
# module; it was put here temporarily to avoid disrupting the file layout in
1061
1063
# the K8s release machinery.
1062
- $STACKDRIVER_VERSION = ' v1-8 '
1064
+ $STACKDRIVER_VERSION = ' v1-9 '
1063
1065
$STACKDRIVER_ROOT = ' C:\Program Files (x86)\Stackdriver'
1064
1066
1065
1067
# Install and start the Stackdriver logging agent according to
@@ -1123,9 +1125,6 @@ function InstallAndStart-LoggingAgent {
1123
1125
Remove-Item - Force - Recurse $tmp_dir
1124
1126
}
1125
1127
1126
- # TODO(yujuhong):
1127
- # - Collect kubelet/kube-proxy logs.
1128
- # - Add tag for kubernetes node name.
1129
1128
$FLUENTD_CONFIG = @'
1130
1129
# This configuration file for Fluentd is used to watch changes to kubernetes
1131
1130
# container logs in the directory /var/lib/docker/containers/ and submit the
@@ -1184,6 +1183,34 @@ $FLUENTD_CONFIG = @'
1184
1183
read_from_head true
1185
1184
</source>
1186
1185
1186
+ # Example:
1187
+ # I0204 07:32:30.020537 3368 server.go:1048] POST /stats/container/: (13.972191ms) 200 [[Go-http-client/1.1] 10.244.1.3:40537]
1188
+ <source>
1189
+ @type tail
1190
+ format multiline
1191
+ multiline_flush_interval 5s
1192
+ format_firstline /^\w\d{4}/
1193
+ format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
1194
+ time_format %m%d %H:%M:%S.%N
1195
+ path /etc/kubernetes/logs/kubelet.log
1196
+ pos_file /etc/kubernetes/logs/gcp-kubelet.log.pos
1197
+ tag kubelet
1198
+ </source>
1199
+
1200
+ # Example:
1201
+ # I1118 21:26:53.975789 6 proxier.go:1096] Port "nodePort for kube-system/default-http-backend:http" (:31429/tcp) was open before and is still needed
1202
+ <source>
1203
+ @type tail
1204
+ format multiline
1205
+ multiline_flush_interval 5s
1206
+ format_firstline /^\w\d{4}/
1207
+ format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
1208
+ time_format %m%d %H:%M:%S.%N
1209
+ path /etc/kubernetes/logs/kube-proxy.log
1210
+ pos_file /etc/kubernetes/logs/gcp-kube-proxy.log.pos
1211
+ tag kube-proxy
1212
+ </source>
1213
+
1187
1214
<match reform.**>
1188
1215
@type record_reformer
1189
1216
enable_ruby true
@@ -1203,7 +1230,17 @@ $FLUENTD_CONFIG = @'
1203
1230
tag ${if record['stream'] == 'stderr' then 'raw.stderr' else 'raw.stdout' end}
1204
1231
remove_keys stream,log
1205
1232
</match>
1206
- '@
1233
+
1234
+ # Attach local_resource_id for 'k8s_node' monitored resource.
1235
+ <filter **>
1236
+ @type record_transformer
1237
+ enable_ruby true
1238
+ <record>
1239
+ "logging.googleapis.com/local_resource_id" ${"k8s_node.NODE_NAME"}
1240
+ </record>
1241
+ </filter>
1242
+ '@ .replace(' NODE_NAME' , (hostname))
1243
+
1207
1244
1208
1245
# Export all public functions:
1209
1246
Export-ModuleMember - Function *-*
0 commit comments