-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowClusterMesh.sh
143 lines (104 loc) · 4.19 KB
/
showClusterMesh.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
<<EOF
# https://docs.cilium.io/en/latest/operations/troubleshooting/#cluster-mesh-troubleshooting
注意:
(1) 不同集群的 clustermesh 的 nodePort 不能使用相同端口
apiserver:
service:
type: NodePort
# WARNING: make sure to configure a different NodePort in each cluster if
# kube-proxy replacement is enabled, as Cilium is currently affected by a known bug (#24692) when NodePorts are handled by the KPR implementation
nodePort: ${CLUSTERMESH_APISERVER_NODEPORT}
EOF
CILIUM_NS=${CILIUM_NS:-"kube-system"}
CONFIG_DIR=${CONFIG_DIR:-"/root/clustermesh"}
export KUBECONFIG="${CONFIG_DIR}/config"
[ -f "${CONFIG_DIR}/config" ] || { echo "kubeconfig ${KUBECONFIG} is not found"; exit 1; }
# Get all available clusters from the kubeconfig
CLUSTERS=($(kubectl --kubeconfig=${KUBECONFIG} config get-contexts -o name))
if [ ${#CLUSTERS[@]} -eq 0 ]; then
echo "No clusters found in kubeconfig ${KUBECONFIG}"
exit 1
fi
echo "Found ${#CLUSTERS[@]} clusters in kubeconfig: ${CLUSTERS[*]}"
echo ""
echo "===================================== hubble Status ==================================="
if ! hubble status &>/dev/null ; then
cilium hubble port-forward &
sleep 3
fi
echo ""
echo "hubble status"
hubble status
echo ""
echo "hubble list nodes"
hubble list nodes
# Show clustermesh status for each cluster
echo ""
echo "===================================== ClusterMesh Status Per Cluster ==================================="
for CLUSTER in "${CLUSTERS[@]}"; do
echo ""
echo "--------- check clusterMesh status in ${CLUSTER} "
cilium clustermesh status --context ${CLUSTER} || true
echo ""
done
echo ""
echo "===================================== clusterMesh export address ==================================="
echo ""
echo "注意!每个集群的 nodePort 号不能相同,否则会冲突,多集群连接会失败"
echo ""
# Show clustermesh export addresses for each cluster
for CLUSTER in "${CLUSTERS[@]}"; do
echo ""
echo "${CLUSTER} export address:"
kubectl get service --context ${CLUSTER} -n ${CILIUM_NS} clustermesh-apiserver
echo ""
done
echo ""
echo "===================================== show status of each agent in all clusters ==================================="
echo ""
# Show status of each agent in each cluster
for CLUSTER in "${CLUSTERS[@]}"; do
echo ""
echo "------------------- Agents in ${CLUSTER} -------------------"
echo ""
kubectl config use-context ${CLUSTER}
AGENT_PODS=$( kubectl get pods -n ${CILIUM_NS} -l app.kubernetes.io/name=cilium-agent | sed '1d' | awk '{ print $1}' )
if [ -z "$AGENT_PODS" ]; then
echo "No Cilium agent pods found in ${CLUSTER}"
continue
fi
for POD in ${AGENT_PODS} ; do
echo ""
if kubectl get pod -n ${CILIUM_NS} ${POD} | grep Running &>/dev/null ; then
echo "-------------- agent pod ${POD} in ${CLUSTER}: Running "
kubectl exec -it -n ${CILIUM_NS} ${POD} -c cilium-agent -- cilium-dbg troubleshoot clustermesh
else
echo "-------------- agent pod ${POD} in ${CLUSTER}: Not Running "
fi
echo ""
done
done
echo ""
echo "===================================== show status of clustermesh in all clusters ==================================="
echo ""
# Show status of clustermesh in each cluster
for CLUSTER in "${CLUSTERS[@]}"; do
echo ""
kubectl config use-context ${CLUSTER}
CLUSTERMESH_PODS=$( kubectl get -n ${CILIUM_NS} pod -l app.kubernetes.io/name=clustermesh-apiserver | sed '1d' | awk '{ print $1}' )
if [ -z "$CLUSTERMESH_PODS" ]; then
echo "No ClusterMesh API server pods found in ${CLUSTER}"
continue
fi
for POD in ${CLUSTERMESH_PODS} ; do
echo ""
if kubectl get pod -n ${CILIUM_NS} ${POD} | grep Running &>/dev/null ; then
echo "-------------- clustermesh pod ${POD} in ${CLUSTER}: Running "
kubectl exec -it -n ${CILIUM_NS} ${POD} -c kvstoremesh -- /usr/bin/clustermesh-apiserver kvstoremesh-dbg troubleshoot
else
echo "-------------- clustermesh pod ${POD} in ${CLUSTER}: Not Running "
fi
echo ""
done
done