kubectl apply -f https://gist.githubusercontent.com/tg123/16e2fcc4e97222c95c8143858c8a5faf/raw/8e01fb743d4f6563303b9fb163fcf9b63a6aa825/podping.yaml
kubectl get -n podping po
# check if any pod failure
Last active
May 16, 2023 14:13
-
-
Save tg123/16e2fcc4e97222c95c8143858c8a5faf to your computer and use it in GitHub Desktop.
test all pod to pod tcp conn on all nodes
This file contains 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
apiVersion: v1 | |
kind: Namespace | |
metadata: | |
name: podping | |
namespace: podping | |
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: podping | |
namespace: podping | |
data: | |
ping.sh: | | |
#!/bin/sh | |
set -e | |
while true; do | |
echo "My public ip is:" | |
curl -sS @ifconfig.me | |
echo "" | |
echo "" | |
rm -f .good | |
kubectl get pods -l app=podping -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.podIP}{"\n"}{end}' | while read -r line; do | |
ip=$(echo $line | cut -d' ' -f2) | |
name=$(echo $line | cut -d' ' -f1) | |
echo "Processing $name ($ip)..." | |
set +e | |
nc -vz -w 1 $ip 80 | |
if [ ! $? -eq 0 ]; then | |
exit 1 | |
fi | |
set -e | |
echo "" | |
touch .good | |
done | |
if [ ! -f .good ]; then | |
echo "no pods found" | |
exit 1 | |
fi | |
sleep 30 | |
done | |
--- | |
apiVersion: apps/v1 | |
kind: DaemonSet | |
metadata: | |
name: podping | |
namespace: podping | |
labels: | |
app: podping | |
spec: | |
selector: | |
matchLabels: | |
app: podping | |
template: | |
metadata: | |
labels: | |
app: podping | |
spec: | |
# add cluster admin role to podping service account | |
serviceAccountName: podping | |
containers: | |
- name: nginx | |
image: nginx | |
ports: | |
- containerPort: 80 | |
- name: test | |
image: portainer/kubectl-shell | |
command: ["/bin/sh", "/ping.sh"] | |
volumeMounts: | |
- name: ping | |
mountPath: /ping.sh | |
subPath: ping.sh | |
readOnly: true | |
volumes: | |
- name: ping | |
configMap: | |
name: podping | |
items: | |
- key: ping.sh | |
path: ping.sh | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRoleBinding | |
metadata: | |
name: podping-cluster-admin | |
subjects: | |
- kind: ServiceAccount | |
name: podping | |
namespace: podping | |
roleRef: | |
kind: ClusterRole | |
name: cluster-admin | |
apiGroup: rbac.authorization.k8s.io | |
--- | |
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: podping | |
namespace: podping |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment