Last active
July 3, 2024 21:51
-
-
Save cgustav/0a3a1207cb5bbe03b05c457af562dc45 to your computer and use it in GitHub Desktop.
Run an ephemera pod in a specified Kubernetes namespace. It comes with tons of ready to use networking tools.
This file contains hidden or 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
#!/bin/bash | |
function kubenet { | |
# Description: Run an ephemeral Swiss Army Knife pod in a specified namespace. | |
# You already have tons of networking test tools ready to be used inside a kubernetes infrastructure. | |
# Based on Sören Metje's article | |
# https://dev.to/soerenmetje/debug-kubernetes-applications-a-swiss-army-knife-container-56id | |
# Usage: | |
# kubenet {YOUR_NAMESPACE} | |
namespace="$1" | |
if [ -z "$namespace" ]; then | |
namespace="default" | |
else | |
# Check if the namespace exists | |
if ! kubectl get namespace "$namespace" &>/dev/null; then | |
echo "Namespace '$namespace' does not exist. Using 'default' namespace." | |
namespace="default" | |
fi | |
fi | |
echo "Running Swiss Army Knife pod in namespace: $namespace" | |
kubectl run swiss-army-knife --namespace="$namespace" \ | |
--image=leodotcloud/swiss-army-knife:latest \ | |
--labels="app=test,environment=debug" \ | |
--rm -it --restart=Never --command -- /bin/bash | |
} | |
# Call the function with the provided argument | |
kubenet "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment