A collection of shell functions for retrieving and analyzing Kubernetes pod information along with their associated node labels and metadata. Available for both Bash and Fish shells.
These functions help you quickly analyze the relationship between your Kubernetes pods and the nodes they're running on, including:
- Node labels and metadata
- Availability zone distribution
- Instance types
- Karpenter node pool assignments
- Pod distribution statistics
Before using these functions, ensure you have:
kubectlinstalled and configured with access to your Kubernetes clusterjq(JSON processor) installed for data manipulation- Bash 4.0+ or Fish shell 3.0+
# Source the functions in your current session
source bash/pod_node_labels.bash
# Or add to your ~/.bashrc for permanent access
echo "source $(pwd)/bash/pod_node_labels.bash" >> ~/.bashrc# Source the functions in your current session
source fish/pod_node_labels.fish
# Or add to your Fish config
echo "source "(pwd)"/fish/pod_node_labels.fish" >> ~/.config/fish/config.fish# Enable completion in your current session
source bash/pod_node_labels_completion.bash
# Or add to your ~/.bashrc for automatic loading
echo "source $(pwd)/bash/pod_node_labels_completion.bash" >> ~/.bashrcRetrieves pods along with their associated node information and all node labels.
Example:
pod_node_labels --namespace production
pod_node_labels -l app=nginxCreates a mapping of pod names to a specific node label value.
Parameters:
NODE_LABEL: The node label key to extract (required)
Example:
podname_to_node_label "node.kubernetes.io/instance-type" -n default
podname_to_node_label "topology.kubernetes.io/zone" --all-namespacesMaps pod names to their availability zones using the standard topology.kubernetes.io/zone label.
Example:
podname_to_az -n production
podname_to_az -l tier=frontendMaps pod names to their node's EC2 instance types using the node.kubernetes.io/instance-type label.
Example:
pod_to_instance_type --all-namespaces
pod_to_instance_type -n kube-systemMaps pod names to their Karpenter node pool names. Only considers nodes initialized by Karpenter.
Example:
pod_to_karpenter_nodepool -n production
pod_to_karpenter_nodepool -l app=web-serverCounts the number of pods running in each availability zone.
Example:
pod_per_az --all-namespaces
pod_per_az -n production# Get pod count per AZ for a specific application
pod_per_az -l app=my-application
# Check AZ distribution for all pods in production namespace
pod_per_az -n production# Map all pods to their instance types
pod_to_instance_type --all-namespaces
# Check instance types for a specific deployment
pod_to_instance_type -l app=web-server# See which Karpenter node pools your pods are using
pod_to_karpenter_nodepool -n production
# Check node pool distribution for a specific application
pod_to_karpenter_nodepool -l app=data-processor# Map pods to custom node labels
podname_to_node_label "node.example.com/workload-type" -n production
podname_to_node_label "kubernetes.io/arch" --all-namespacesAll functions return JSON output that can be further processed with jq or other tools:
[
{
"podName": "nginx-deployment-abc123",
"podIP": "10.244.1.5",
"nodeName": "node-1",
"topology.kubernetes.io/zone": "us-west-2a",
"node.kubernetes.io/instance-type": "m5.large"
}
]These functions accept standard kubectl options:
--namespaceor-n: Specify namespace--all-namespacesor-A: Include all namespaces--selectoror-l: Filter by labels--field-selector: Filter by field selectors
Make sure you've sourced the appropriate file for your shell:
# For Bash
source bash/pod_node_labels.bash
# For Fish
source fish/pod_node_labels.fishInstall jq using your system's package manager:
# macOS
brew install jq
# Ubuntu/Debian
sudo apt-get install jq
# RHEL/CentOS
sudo yum install jqEnsure your kubectl is configured and you have appropriate permissions:
kubectl auth can-i get pods
kubectl auth can-i get nodesFeel free to submit issues or pull requests to improve these functions or add support for additional shells.
This project is open source and available under the MIT License.