差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

兩邊的前次修訂版 前次修改
下次修改
前次修改
tech:k8s-netchk [2021/01/23 09:24] jonathantech:k8s-netchk [2023/04/07 12:43] (目前版本) – [檢測跨 namespace 的 service] jonathan
行 1: 行 1:
 ====== K8s 內的網路檢測 ====== ====== 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 網路的相關語法紀錄下來. 因為在 Hyper-V 內建立一個 Ubuntu 20.04 VM 然後起一個 K8s Cluster 卻發現在 K8s 內的服務連不上 VM 內的服務, 以下是將檢測 K8s 網路的相關語法紀錄下來.
  
行 21: 行 52:
       containers:       containers:
       - name: busybox       - name: busybox
-        image: progrium/busybox+        image: yauritux/busybox-curl:latest
         command:         command:
           - sleep           - sleep
行 38: 行 69:
 ===== 使用 pod 安裝相關工具與檢測 ===== ===== 使用 pod 安裝相關工具與檢測 =====
   * 安裝 curl <cli>   * 安裝 curl <cli>
-kubectl exec -it busybox-5d5bd64f66-zlvls -- opkg-install curl+kubectl exec busybox-5d5bd64f66-zlvls -- opkg-install curl
 </cli> </cli>
   * 進行目標網址檢測 <cli>   * 進行目標網址檢測 <cli>
-kubectl exec -it busybox-5d5bd64f66-zlvls -- ping -c 5 172.16.0.171 +kubectl exec busybox-5d5bd64f66-zlvls -- ping -c 5 172.16.0.171 
-kubectl exec -it busybox-5d5bd64f66-zlvls -- traceroute 172.16.0.171 +kubectl exec busybox-5d5bd64f66-zlvls -- traceroute 172.16.0.171 
-kubectl exec -it busybox-5d5bd64f66-zlvls -- curl -k https://172.16.0.171:5443/+kubectl exec busybox-5d5bd64f66-zlvls -- curl -k https://172.16.0.171:5443/
 </cli> </cli>
  
行 52: 行 83:
 </cli> </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   * https://stackoverflow.com/questions/62847331/is-there-possible-to-install-curl-into-busybox-in-kubernetes-pod
  
 {{tag>K8s busybox}} {{tag>K8s busybox}}
  • tech/k8s-netchk.1611365085.txt.gz
  • 上一次變更: 2021/01/23 09:24
  • jonathan