如何從本機連線至 GKE Pod
Last updated
Last updated
# 首先建立應用服務 busybox
kubectl apply -f busybox.yaml
# 查看 busybox pod
kubectl get pod
NAME READY STATUS RESTARTS AGE
busybox 1/1 Running 0 108s
# 遠端連線至 busybox pod,執行應用程式指令 ping
kubectl exec -i --tty busybox -- sh
/ # ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=51 time=1.300 ms
64 bytes from 8.8.8.8: seq=1 ttl=51 time=0.353 ms# 建立 redis pod 應用程式
kubectl apply -f redis-master.yaml
# 查看 redis pod 應用程式(pod name = redis-master-ID)
kubectl get pod
NAME READY STATUS RESTARTS AGE
busybox 1/1 Running 0 24m
redis-master-57fc67768d-p7dg4 1/1 Running 0 38s
# 建立遠端 pod 網路層連線至本機上
kubectl port-forward redis-master-57fc67768d-p7dg4 6379:6379
# 測試連線
telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.