Skip to content

Instantly share code, notes, and snippets.

@mohatb
Created May 30, 2023 10:43
Show Gist options
  • Select an option

  • Save mohatb/136519e470937baa544b014cf07e760e to your computer and use it in GitHub Desktop.

Select an option

Save mohatb/136519e470937baa544b014cf07e760e to your computer and use it in GitHub Desktop.
download kube-proxy from all aks nodes
#!/bin/bash
# Start kubectl proxy in the background
kubectl proxy &
# Save the process ID of kubectl proxy
kubectl_proxy_pid=$!
# Base URL to the logs directory on the node
base_url="http://localhost:8001/api/v1/nodes"
# Get the list of nodes
node_names=$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}')
# Iterate over each node
for node_name in $node_names; do
# Use curl to get the list of pod directories and extract directory names
dir_names=$(curl -s "$base_url/$node_name/proxy/logs/pods/" | grep -oP '(?<=href=")[^"]*')
# Iterate over each directory name
for dir_name in $dir_names; do
# Construct the full URL to the kube-proxy log file
log_url="${base_url}/${node_name}/proxy/logs/pods/${dir_name}kube-proxy/0.log"
# Construct the log file name with the node name
log_file_name="${node_name}_kube-proxy_0.log"
# Use wget or curl to download the log file
wget -O "$log_file_name" "$log_url"
done
done
# Stop kubectl proxy
kill $kubectl_proxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment