MiniKubeExternalName访问问题

问题描述 投票:0回答:1

我使用了以下资源一周,但没有用:

  1. 所有 StackOverflowExternalName 访问问题
  2. Kubernetes 外部名称文档
  3. 许多关于ExternalName的YouTube视频
  4. 许多有关 Kubernetes 网络的 YouTube 视频
  5. 有关如何从 pod 访问外部数据库的中型文章

问题来了:

在我的本地计算机上,我有 docker 容器

nginx
在端口
8090
运行。它正在使用图像
nginx:stable-perl
。在 Chrome 中,当我运行
http://192.168.56.1:8090
时,显示欢迎使用 nginx!页面出现。请注意,
192.168.56.1
是我的本地机器IP。

在我的本地计算机上,我还有一个在 minikube 上运行的 pod,开始使用

minikube start --driver=hyperv
。 Pod 正在运行
helloworld
容器,使用镜像“bhargavshah86/kube-test:v0.1”。

这是吊舱:

PS C:\data\code\unleash> kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
helloworld-8654c996c4-thjrf   1/1     Running   0          9m48s

我运行了

port-forward
命令

kubectl --namespace default port-forward helloworld-8654c996c4-thjrf 8090:8090

这是我的

etc\hosts

192.168.56.1 my.web

这是

nslookup

/usr/share/nginx/html # nslookup 192.168.56.1 8090
Server:    0.0.31.154
Address 1: 0.0.31.154

Name:      192.168.56.1
Address 1: 192.168.56.1 my.web

现在,当我尝试从 pod 容器中

curl
主机
192.168.56.1:8090
时,它超时了。

/usr/share/nginx/html # curl 192.168.56.1 8090
curl: (7) Failed to connect to 192.168.56.1 port 80: Operation timed out

如果我

curl
externalName
my-web
,主机无法解析:

/usr/share/nginx/html # curl http://my-web:8090
curl: (6) Could not resolve host: my-web

使用服务名称 url,它不起作用:

/usr/share/nginx/html # curl my-web.default.svc.cluster.local:8090
curl: (6) Could not resolve host: my-web.default.svc.cluster.local

甚至

telnet
超时:

/usr/share/nginx/html # busybox-extras telnet 192.168.56.1 8090
telnet: can't connect to remote host (192.168.56.1): Operation timed out

我安装了

apk add postgresql-client
来访问本地计算机上的Postgres,在
192.168.56.1
端口'5432`上运行,但出现错误:

psql -h 192.168.56.1 -U postgres

curl
google.com
有效:

/usr/share/nginx/html # curl www.google.com
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-PK"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="1i3Z2zYvpmrTvPimeEfy8g">(function(){var _g={kEI:'CQ0pZpuiG8vk2roP3ZmLmAo',kEXPI:'0,18167,774941,577370,2329773,698,361,302200,146403,29615,4998,13744,39064,2711,2872,2891,8349,34679,46357,1014,1,16916,89311,6636,7596,1,42157,2,16734,23024,6700,41942,24676,33064,2,2,1,6959,19673,8155,8860,14491,22435,9779,5864,36595,20198,73179,2266,764,15816,1804,7734,6626,32722,1634,13493,29971,546,12350,5210437,1347,1190,5992132,2839368,3,1,1,1,1,1,14,23,91,27982631,16672,43887,3,318,4,1281,3,2121778,2585,24112,23010663,2739,4636,8409,3321,4706,8637,17451,8666,5,1905,36870,1922,7288,1301,2370,4832,1575,2863,1679,9303,12953,2210,7970,213,391,7526,2891,2437,4501,5,5102,4,105,8678,155,13518,2323,1794,1139,2042,33,1915,4,4952,6009,4981,360,234,1265,3,611,419,709,1794,1954,123,32,389,10,2085,207,8740,827,9,36,3685,2410,3753,892,680,9,5182,110,1299,1173,5,248,53,1060,969,538,2168,610,132,183,23,184,121,385,1050,4,1,6,762,1009,4,123,1949,932,272,433,1986,660,464,446,2,1,14,1,303,5,11,1157,538,853,2,4,922,673,1598,361,24,5,208,362,435,319,1076,38,1119,26,3,38,188,285,759,213,179,760,3,129,2,93,349,1091,135,665,347,387,139,300,218,246,1,161,483,1218,884,303,802,309,1,3,447,5,338,936,705,1,366,84,75,66,926,460,785,871,654,69,477,2,1345,8,1289,41,351,1898,74,733,39,17,548,925,595,111,563,123,48,43,50,49,511,466,3,313,104,20,145,881,651,249,537,1,1910,16,717,141,400,184,3,136,837,206,299,434,69,43,171,15,193,66,4,2,3,49,258,321,312,198,848,2097,2513,21262213,365638,3,3769,4505,21,2163,379,2613,614,105',kBL:'_YbZ',kOPI:89978449};(function(){var a;(null==(a=window.google)?0:a.stvsc)?google.kEI=_g.kEI:window.google=_g;}).call(this);})();(function(){google.sn='webhp';google.kHL='en-PK';})();(function(){

描述如下:

PS C:\data\code\unleash> kubectl describe svc/my-web
Name:              my-web
Namespace:         default
Labels:            <none>
Annotations:       <none>
Selector:          <none>
Type:              ExternalName
IP Families:       <none>
IP:
IPs:               <none>
External Name:     192.168.56.1
Port:              <unset>  8090/TCP
TargetPort:        8090/TCP
Endpoints:         <none>
Session Affinity:  None
Events:            <none>

这是

minikube tunnel
输出:

PS C:\data\code\unleash> minikube tunnel --bind-address=192.168.56.1
W0424 19:34:25.670477   20364 main.go:291] Unable to resolve the current Docker CLI context "default": context "default": context not found: open C:\Users\srhusain\.docker\contexts\meta\37a8eec1ce19687d132fe29051dca629d164e2c4958ba141d5f4133a33f0688f\meta.json: The system cannot find the path specified.
E0424 19:34:29.903003   20364 out.go:453] unable to execute error getting ssh port: get port 22 for "minikube": hyperv container inspect -f "'{{(index (index .NetworkSettings.Ports "22/tcp") 0).HostPort}}'" minikube: exec: "hyperv": executable file not found in %PATH%
stdout:

stderr:
: template: error getting ssh port: get port 22 for "minikube": hyperv container inspect -f "'{{(index (index .NetworkSettings.Ports "22/tcp") 0).HostPort}}'" minikube: exec: "hyperv": executable file not found in %!P(string=index)ATH&{%!
(string=index of untyped nil)}stdout:

stderr:
:1:92: executing "error getting ssh port: get port 22 for \"minikube\": hyperv container inspect -f \"'{{(index (index .NetworkSettings.Ports \"22/tcp\") 0).HostPort}}'\" minikube: exec: \"hyperv\": executable file not found in %PATH%\nstdout:\n\nstderr:\n" at <index .NetworkSettings.Ports "22/tcp">: error calling %!s(MISSING): 
%!w(MISSING) - returning raw string.

❌  Exiting due to DRV_PORT_FORWARD: error getting ssh port: get port 22 for "minikube": hyperv container inspect -f "'{{(index (index .NetworkSettings.Ports "22/tcp"
) 0).HostPort}}'" minikube: exec: "hyperv": executable file not found in %PATH%
stdout:

stderr:


╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                             │
│    😿  If the above advice does not help, please let us know:                                               │
│    👉  https://github.com/kubernetes/minikube/issues/new/choose                                             │
│                                                                                                             │
│    Please run `minikube logs --file=logs.txt` and attach logs.txt to the GitHub issue.                      │
│    Please also attach the following file to the GitHub issue:                                               │
│    - C:\Users\srhusain\AppData\Local\Temp\minikube_tunnel_df9325734b3fbaf9471c9c4a9cc1524d4e32b11a_0.log    │
│                                                                                                             │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

我尝试了

my.web
192.168.56.1

spec:
  type: ExternalName
  externalName: my.web
.
.
.

spec:
  type: ExternalName
  externalName: 192.168.56.1

这是完整的 YAML:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld
  labels:
    app: helloworld
spec:
  replicas: 1
  selector:
    matchLabels:
      app: helloworld
  template:
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: helloworld
        image:  bhargavshah86/kube-test:v0.1
        resources:
          limits:
            memory: 512Mi
            cpu: "1"
          requests:
            memory: 256Mi
            cpu: "0.2"
        ports:
        - containerPort: 8080

---
apiVersion: v1
kind: Service
metadata:
  name: my-web
spec:
  type: ExternalName
  externalName: 192.168.56.1
  ports:
  - port: 8090
    protocol: TCP
    targetPort: 8090

以下是端点:

PS C:\data\code\unleash> kubectl get endpoints
NAME         ENDPOINTS             AGE
helloworld   10.244.0.11:8080      3h4m
kubernetes   172.18.112.240:8443   4h3m

这里是豆荚:

PS C:\data\code\unleash> kubectl get pods -o wide
NAME                          READY   STATUS    RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
helloworld-8654c996c4-mm4m2   1/1     Running   0          20m   10.244.0.11   minikube   <none>           <none>

我期待curl不会超时并且欢迎来到nginx!返回 html。

kubernetes google-kubernetes-engine amazon-eks kubectl azure-aks
1个回答
0
投票

就我而言,问题出在 Windows 防火墙上。通过关闭域、公共和私有的 Windows 防火墙并使用

host.minikube.internal
,我能够访问 nginx 和 postgres。

© www.soinside.com 2019 - 2024. All rights reserved.