gpt4 book ai didi

docker - minikube ip 返回 127.0.0.1 | Kubernetes NodePort 服务无法访问

转载 作者:行者123 更新时间:2023-12-02 11:29:58 34 4
gpt4 key购买 nike

我有两个 kubernetes 对象,

apiVersion: v1
kind: Pod
metadata:
name: client-pod
labels:
component: web
spec:
containers:
- name: client
image: stephengrider/multi-client
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 3000

apiVersion: v1
kind: Service
metadata:
name: client-node-port
spec:
type: NodePort
selector:
component: web
ports:
- port: 3050
targetPort: 3000
nodePort: 31515

我使用 kubectl apply -f <file_name> 申请了两者之后,这是输出
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
client-node-port NodePort 10.100.230.224 <none> 3050:31515/TCP 30m

pod 输出
NAME                                  READY   STATUS    RESTARTS   AGE
client-pod 1/1 Running 0 28m

但是当我运行时 minikube ip它返回 127.0.0.1,
我正在使用带有 docker 驱动程序的 minikube。

关注此问题后 https://github.com/kubernetes/minikube/issues/7344 .
我使用了 node-ip
kubectl get node -o json |
jq --raw-output \
'.items[0].status.addresses[]
| select(.type == "InternalIP")
.address
'

但即便如此,我也无法访问该服务。经过更多的搜索,我发现
minikube service --url client-node-port
🏃 Starting tunnel for service client-node-port.
|-----------|------------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------------|-------------|------------------------|
| default | client-node-port | | http://127.0.0.1:52694 |
|-----------|------------------|-------------|------------------------|
http://127.0.0.1:52694
❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.

我可以使用 minikube 服务访问该服务。

题:
  • 但我想知道为什么暴露的 nodePort 不起作用?
  • 为什么我做这个解决方法来访问应用程序。

  • 更多信息:
    minikube version
    minikube version: v1.10.1
    commit: 63ab801ac27e5742ae442ce36dff7877dcccb278

    docker version
    Client: Docker Engine - Community
    Version: 19.03.8
    API version: 1.40
    Go version: go1.12.17
    Git commit: afacb8b
    Built: Wed Mar 11 01:21:11 2020
    OS/Arch: darwin/amd64
    Experimental: false

    Server: Docker Engine - Community
    Engine:
    Version: 19.03.8
    API version: 1.40 (minimum version 1.12)
    Go version: go1.12.17
    Git commit: afacb8b
    Built: Wed Mar 11 01:29:16 2020
    OS/Arch: linux/amd64
    Experimental: false
    containerd:
    Version: v1.2.13
    GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
    runc:
    Version: 1.0.0-rc10
    GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
    docker-init:
    Version: 0.18.0
    GitCommit: fec3683

    kubectl version
    Client Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.6-beta.0", GitCommit:"e7f962ba86f4ce7033828210ca3556393c377bcc", GitTreeState:"clean", BuildDate:"2020-01-15T08:26:26Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"darwin/amd64"}
    Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-04-16T11:48:36Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

    如果您需要更多信息,我愿意提供。
    minikube ssh
    docker@minikube:~$ ip -4 a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
    4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    inet 172.18.0.1/16 brd 172.18.255.255 scope global docker0
    valid_lft forever preferred_lft forever
    945: eth0@if946: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
    valid_lft forever preferred_lft forever

    最佳答案

    我有同样的问题。问题不在于 IP 127.0.0.1 .问题是我正在调用我在 YAML 中定义的端口文件为 NodePort .它看起来像 minikube将为外部访问分配不同的端口。
    我的做法是:

  • 在一个漂亮的格式化表格中列出所有服务:
    $minikube service list 
  • 显示 IP 和外部端口:
    $minikube service Type-Your-Service-Name

  • 如果你这样做 minikube将打开浏览器并运行您的应用程序。

    关于docker - minikube ip 返回 127.0.0.1 | Kubernetes NodePort 服务无法访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62375642/

    34 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com