Última atividade 1 week ago

此腳本用於顯示 Kubernetes 環境中 Pod、Service、NodePort、Ingress 的狀態與連線資訊,並列出 PVC,方便快速掌握服務部署與存取方式。特別適用於 k3s + Traefik 環境。

timmy revisou este gist 1 week ago. Ir para a revisão

1 file changed, 0 insertions, 0 deletions

check_k8s_endpoints.sh renomeado para k8s_status_access.sh

Arquivo renomeado sem alterações

timmy revisou este gist 2 weeks ago. Ir para a revisão

1 file changed, 62 insertions

check_k8s_endpoints.sh(arquivo criado)

@@ -0,0 +1,62 @@
1 + #!/usr/bin/env bash
2 + # 用途:查看 Kubernetes 服務狀態與實際連線方式
3 + # 包含:Pod、Service(NodePort)、Ingress(HTTP/HTTPS)、PVC
4 + # 適用:k3s + Traefik
5 +
6 + set -euo pipefail
7 +
8 + echo
9 + echo "=== Pods ==="
10 + kubectl get pods -o wide
11 +
12 + echo
13 + echo "=== Services ==="
14 + kubectl get svc
15 +
16 + echo
17 + echo "=== Node IPs ==="
18 + kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{range .status.addresses[?(@.type=="InternalIP")]}{.address}{" "}{end}{"\n"}{end}'
19 +
20 + echo
21 + echo "=== NodePort Access ==="
22 + NODE_IPS=$(kubectl get nodes -o jsonpath='{range .items[*]}{.status.addresses[?(@.type=="InternalIP")].address}{"\n"}{end}')
23 + NODEPORT_SVCS=$(kubectl get svc -o jsonpath='{range .items[?(@.spec.type=="NodePort")]}{.metadata.name}{"\t"}{.spec.ports[0].nodePort}{"\n"}{end}')
24 +
25 + if [ -z "$NODEPORT_SVCS" ]; then
26 + echo "(無 NodePort 服務)"
27 + else
28 + for ip in $NODE_IPS; do
29 + while IFS=$'\t' read -r svc port; do
30 + echo "- $ip:$port ($svc)"
31 + done <<< "$NODEPORT_SVCS"
32 + done
33 + fi
34 +
35 + echo
36 + echo "=== Ingress (Access URLs) ==="
37 + INGRESS_LIST=$(kubectl get ingress -o name 2>/dev/null || true)
38 +
39 + if [ -z "$INGRESS_LIST" ]; then
40 + echo "(無 Ingress)"
41 + else
42 + for ing in $INGRESS_LIST; do
43 + NAME=$(kubectl get "$ing" -o jsonpath='{.metadata.name}')
44 + HOSTS=$(kubectl get "$ing" -o jsonpath='{range .spec.rules[*]}{.host}{"\n"}{end}')
45 + TLS=$(kubectl get "$ing" -o jsonpath='{.spec.tls}')
46 +
47 + echo "- $NAME"
48 + while read -r host; do
49 + [ -z "$host" ] && continue
50 + if [ -n "$TLS" ]; then
51 + echo " https://$host"
52 + else
53 + echo " http://$host"
54 + fi
55 + done <<< "$HOSTS"
56 + done
57 + fi
58 +
59 + echo
60 + echo "=== PVC ==="
61 + kubectl get pvc
62 +
Próximo Anterior