顯示頁面舊版反向連結Fold/unfold all回到頁頂 本頁是唯讀的,您可以看到原始碼,但不能更動它。您如果覺得它不應被鎖上,請詢問管理員。 ====== K8s 內的網路檢測 ====== <note> - 在 K8s 內起一個有 curl 的 busybox POD <cli> kubectl run --rm -it busybox --image yauritux/busybox-curl:latest --restart=Never </cli> - 直接下 ping / nslookup / curl 等等命令進行網路檢測++看結果|<cli> rkeuser@iso:~$ kubectl run --rm -it busybox --image yauritux/busybox-curl:latest --restart=Never If you don't see a command prompt, try pressing enter. /home # ping www.ichiayi.com PING www.ichiayi.com (220.135.35.198): 56 data bytes 64 bytes from 220.135.35.198: seq=0 ttl=242 time=4.992 ms 64 bytes from 220.135.35.198: seq=1 ttl=242 time=6.761 ms ^C --- www.ichiayi.com ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 4.992/5.876/6.761 ms /home # nslookup www.ichiayi.com Server: 10.43.0.10 Address 1: 10.43.0.10 kube-dns.kube-system.svc.cluster.local Name: www.ichiayi.com Address 1: 220.135.35.198 220-135-35-198.HINET-IP.hinet.net /home # curl http://10.20.0.77:32080 <html><body>You are being <a href="http://10.20.0.77:32080/users/sign_in">redirected</a>.</body></html>/home # /home # </cli>++ - 輸入 exit 離開++看結果|<cli> /home # exit pod "busybox" deleted </cli>++ </note> 因為在 Hyper-V 內建立一個 Ubuntu 20.04 VM 然後起一個 K8s Cluster 卻發現在 K8s 內的服務連不上 VM 內的服務, 以下是將檢測 K8s 網路的相關語法紀錄下來. ===== 在 K8s 內起一個檢測的 pod ===== * 定義 pod 內容 k8s-chk.yml <file> apiVersion: apps/v1 kind: Deployment metadata: name: busybox namespace: default spec: replicas: 1 selector: matchLabels: app: busybox template: metadata: labels: app: busybox spec: containers: - name: busybox image: yauritux/busybox-curl:latest command: - sleep - "3600" imagePullPolicy: IfNotPresent </file> * 啟動檢測 pod <cli>kubectl apply -f k8s-chk.yml</cli><cli> localadmin@iiidevops1:~/test$ kubectl apply -f k8s-chk.yml deployment.apps/busybox created </cli> * 取得 pod name <cli>kubectl get pod | grep busybox</cli><cli> localadmin@iiidevops1:~/test$ kubectl get pod | grep busybox busybox-5d5bd64f66-zlvls 1/1 Running 0 2m29s </cli> ===== 使用 pod 安裝相關工具與檢測 ===== * 安裝 curl <cli> kubectl exec busybox-5d5bd64f66-zlvls -- opkg-install curl </cli> * 進行目標網址檢測 <cli> kubectl exec busybox-5d5bd64f66-zlvls -- ping -c 5 172.16.0.171 kubectl exec busybox-5d5bd64f66-zlvls -- traceroute 172.16.0.171 kubectl exec busybox-5d5bd64f66-zlvls -- curl -k https://172.16.0.171:5443/ </cli> ===== 關閉檢測的 pod ===== <cli>kubectl delete deploy busybox</cli><cli> localadmin@devops1:~/test$ kubectl delete deploy busybox deployment.apps "busybox" deleted </cli> ===== 檢測跨 namespace 的 service ===== * 預設完整服務網址是 {SERVICE_NAME}.{NAMESPACE_NAME}.svc.cluster.local * Exp. 一個簡易網頁服務 * SERVICE_NAME : test-20230110-37-master-serv-svc * NAMESPACE_NAME : test-20230110-37 * **test-20230110-37-master-serv-svc.test-20230110-37.svc.cluster.local** * Exp. 在 namespace : test-20230110-37 內的 POD 內可直接使用 service name : test-20230110-37-master-serv-svc 當網址 ++看結果|<cli> /var/www/html # curl http://test-20230110-37-master-serv-svc <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>III DevOps Sample</title> <style> h3{text-align: center;} </style> </head> <body> <h3>Hello World!</h3> </body> </cli>++ * Exp. 在 namespace : test-20230110-37 外的 POD 內需要使用完整的服務網址 : test-20230110-37-master-serv-svc.test-20230110-37.svc.cluster.local ++看結果|<cli> /var/www/html # curl http://test-20230110-37-master-serv-svc.test-20230110-37.svc.cluster.local <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>III DevOps Sample</title> <style> h3{text-align: center;} </style> </head> <body> <h3>Hello World!</h3> </body> </cli>++ ===== 參考網址 ===== * https://stackoverflow.com/questions/62847331/is-there-possible-to-install-curl-into-busybox-in-kubernetes-pod {{tag>K8s busybox}} tech/k8s-netchk.txt 上一次變更: 2023/04/07 12:43由 jonathan