使用 Telepresence 在本地环境直接访问 Kubernetes 内部服务地址

Telepresence Kubernetes About 2,584 words

查看服务

kubectl get pod,svc -o wide

输出:可以看到有Servicemydeploynginx和默认的kubernetes,已经服务对应的Pod

PS C:\> kubectl get pod,svc -o wide
NAME                            READY   STATUS    RESTARTS   AGE     IP           NODE       NOMINATED NODE   READINESS GATES
pod/mydeploy-7cfc9db8bd-f2tgl   2/2     Running   0          6h27m   172.17.0.5   minikube   <none>           <none>
pod/nginx                       1/1     Running   0          6h7m    172.17.0.4   minikube   <none>           <none>

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)     AGE     SELECTOR
service/kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP     6h37m   <none>
service/mydeploy     ClusterIP   10.99.243.67     <none>        8080/TCP    6h27m   app=mydeploy
service/nginx        ClusterIP   10.110.107.238   <none>        18080/TCP   6h7m    run=nginx

开启转发服务

telepresence connect

直接访问

谷歌浏览器三种方式都可以访问

Windows系统只能使用CMD下的curlPowerShell下的curl都会报错)

curl nginx:18080
curl nginx.default:18080
curl nginx.default.svc.cluster.local:18080

Windows子系统curl只能通过service-name.namespace-name和全限定名可以访问

curl nginx.default:18080
curl nginx.default.svc.cluster.local:18080

本地机器解析服务域名

nslookup

本地机器nslookup默认服务器是本地IP,显示查找不到。

PS C:\Users\thunk> nslookup.exe nginx
服务器:  UnKnown
Address:  192.168.100.1

*** UnKnown 找不到 nginx: Non-existent domain

指定Kubernetescoredns地址,

PS C:\Users\thunk> nslookup.exe nginx 10.96.0.10
服务器:  UnKnown
Address:  10.96.0.10

名称:    nginx.default.svc.cluster.local
Address:  10.110.107.238

ping

ping服务名nginxping会解析为对应服务的全限定名(容器禁止了ping,所以会请求超时)。

PS C:\> ping nginx

正在 Ping nginx.default.svc.cluster.local [10.110.107.238] 具有 32 字节的数据:
请求超时。

dig

本地机器是Windowsdig命令是通过Windows子系统WSL才有的命令。

使用dig命令查询服务全限定名,可以查看对应Kubernetes内部CLUSTER-IP

root@local:~# dig nginx.default.svc.cluster.local

; <<>> DiG 9.11.3-1ubuntu1.7-Ubuntu <<>> nginx.default.svc.cluster.local
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12884
;; flags: qr rd ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;nginx.default.svc.cluster.local. IN    A

;; ANSWER SECTION:
nginx.default.svc.cluster.local. 0 IN   A       10.110.107.238

;; Query time: 13 msec
;; SERVER: 172.21.144.1#53(172.21.144.1)
;; WHEN: Sun Jun 12 17:46:44 CST 2022
;; MSG SIZE  rcvd: 96
Views: 1,574 · Posted: 2022-08-16

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh