Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kubernetes服务无法获取外部IP[已解决]_Kubernetes_Virtualbox_Minikube - Fatal编程技术网

Kubernetes服务无法获取外部IP[已解决]

Kubernetes服务无法获取外部IP[已解决],kubernetes,virtualbox,minikube,Kubernetes,Virtualbox,Minikube,该服务是外部ip,无法与外部端口绑定。我已运行命令尝试查找端口 minikube服务mongodb快递服务 终端上没有显示错误。但浏览器表示无法连接到该url 环境 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none>

该服务是外部ip,无法与外部端口绑定。我已运行命令尝试查找端口

minikube服务mongodb快递服务

终端上没有显示错误。但浏览器表示无法连接到该url

环境

NAME                      TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes                ClusterIP      10.96.0.1        <none>        443/TCP          14d
mongodb-express-service   LoadBalancer   10.106.190.5     <pending>     8081:30001/TCP   2d3h
mongodb-service           ClusterIP      10.110.241.194   <none>        27017/TCP        3d23h
mongo-express-85bdd6688f-mhv2x        1/1     Running   2          2d3h
mongodb-deployment-7f79c5f88f-h9dvf   1/1     Running   2          2d3h
  • 米尼库贝
  • Oracle虚拟箱
  • Ubuntu 20.04
mongo express.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-express
  labels:
    app: mongo-express
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo-express
  template:
    metadata:
      labels:
        app: mongo-express
    spec:
      containers:
        - name: mongo-express
          image: mongo-express
          ports:
            - containerPort: 8081
          env:
            - name: ME_CONFIG_MONGODB_ADMINUSERNAME
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret
                  key: username
            - name: ME_CONFIG_MONGODB_ADMINPASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret
                  key: password
            - name: ME_CONFIG_MONGODB_SERVER
              valueFrom:
                configMapKeyRef:
                  name: mongodb-config-map
                  key: database_url
---
apiVersion: v1
kind: Service
metadata:
  name: mongodb-express-service
spec:
  selector:
    app: mongodb-express-service
  type: LoadBalancer
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081
      nodePort: 30001
更新 Kubectl获得服务输出

NAME                      TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes                ClusterIP      10.96.0.1        <none>        443/TCP          14d
mongodb-express-service   LoadBalancer   10.106.190.5     <pending>     8081:30001/TCP   2d3h
mongodb-service           ClusterIP      10.110.241.194   <none>        27017/TCP        3d23h
mongo-express-85bdd6688f-mhv2x        1/1     Running   2          2d3h
mongodb-deployment-7f79c5f88f-h9dvf   1/1     Running   2          2d3h

您的应用程序中缺少一些资源。如果你已经创建了它,那么请与我的验证。否则就创建它

1:创建Configmap资源

2:创建秘密资源

3:在终端上

下面是我的终端输出,您可以更改

|-----------|-------------------------|-------------|---------------------------|
| NAMESPACE |          NAME           | TARGET PORT |            URL            |
|-----------|-------------------------|-------------|---------------------------|
| default   | mongodb-express-service |        8081 | http://192.168.49.2:30001 |
|-----------|-------------------------|-------------|---------------------------|
The reason why it was unable to connect is due to the fact that the service and the deployment had a different selector app name as pointed out by @DawidKruk.

Posting this answer to give more reference on 2 topics:

  • Kubernetes Service not able to get External IP
  • Issue that was present in this question

Kubernetes Service not able to get External IP

Service
of type
LoadBalancer
:

Exposes the Service externally using a cloud provider's load balancer.
NodePort
and
ClusterIP
Services, to which the external load balancer routes, are automatically created.

In a Kubernetes solution like
minikube
you won't get out of the box
External IP
that is associated with
Service
of type
LoadBalancer
. You don't need the
External IP
to connect to your
Services
. You can connect to your
Services
by either:

  • Using a
    NodePort
    (
    $ minikube service xyz
    is using it)
  • Using a
    $ minikube tunnel
    (this would "assign"
    External IP
    's)
  • Virtualbox
    specific:

Issue that was present in this question

The issue that was present in the question was connected with the mismatch between the
Service
.spec.selector
and
Deployment
.spec.selector.matchLabels
.

The easiest way to check if your
selector
is configured correctly (apart from looking at the
YAML
manifest), is by:

  • $ kubectl get endpoints
NAME         ENDPOINTS                AGE
kubernetes   A.B.C.D:443              28m
nginx    --> 10.32.0.13:80 <--        5s 
|-----------|-------------------------|-------------|---------------------------|
|名称空间|名称|目标端口| URL|
|-----------|-------------------------|-------------|---------------------------|
|默认| mongodb express服务| 8081 |http://192.168.49.2:30001 |
|-----------|-------------------------|-------------|---------------------------|

您的应用程序中缺少一些资源。如果你已经创建了它,那么请与我的验证。否则就创建它

1:创建Configmap资源

2:创建秘密资源

3:在终端上

下面是我的终端输出,您可以更改

|-----------|-------------------------|-------------|---------------------------|
| NAMESPACE |          NAME           | TARGET PORT |            URL            |
|-----------|-------------------------|-------------|---------------------------|
| default   | mongodb-express-service |        8081 | http://192.168.49.2:30001 |
|-----------|-------------------------|-------------|---------------------------|
The reason why it was unable to connect is due to the fact that the service and the deployment had a different selector app name as pointed out by @DawidKruk.

Posting this answer to give more reference on 2 topics:

  • Kubernetes Service not able to get External IP
  • Issue that was present in this question

Kubernetes Service not able to get External IP

Service
of type
LoadBalancer
:

Exposes the Service externally using a cloud provider's load balancer.
NodePort
and
ClusterIP
Services, to which the external load balancer routes, are automatically created.

In a Kubernetes solution like
minikube
you won't get out of the box
External IP
that is associated with
Service
of type
LoadBalancer
. You don't need the
External IP
to connect to your
Services
. You can connect to your
Services
by either:

  • Using a
    NodePort
    (
    $ minikube service xyz
    is using it)
  • Using a
    $ minikube tunnel
    (this would "assign"
    External IP
    's)
  • Virtualbox
    specific:

Issue that was present in this question

The issue that was present in the question was connected with the mismatch between the
Service
.spec.selector
and
Deployment
.spec.selector.matchLabels
.

The easiest way to check if your
selector
is configured correctly (apart from looking at the
YAML
manifest), is by:

  • $ kubectl get endpoints
NAME         ENDPOINTS                AGE
kubernetes   A.B.C.D:443              28m
nginx    --> 10.32.0.13:80 <--        5s 
|-----------|-------------------------|-------------|---------------------------|
|名称空间|名称|目标端口| URL|
|-----------|-------------------------|-------------|---------------------------|
|默认| mongodb express服务| 8081 |http://192.168.49.2:30001 |
|-----------|-------------------------|-------------|---------------------------|

无法连接的原因是由于@DawidKruk指出,服务和部署具有不同的选择器应用程序名称。

无法连接的原因是由于@DawidKruk指出,服务和部署具有不同的选择器应用程序名称。

回答提供关于两个主题的更多参考:

  • Kubernetes服务无法获取外部IP
  • 本问题中存在的问题

Kubernetes服务无法获取外部IP
负载平衡器类型的
服务

使用云提供商的负载平衡器在外部公开服务<自动创建外部负载平衡器路由到的代码>节点端口
群集IP
服务

在像
minikube
这样的Kubernetes解决方案中,您将无法获得与
负载平衡器类型的
服务相关联的开箱即用的
外部IP
。您不需要使用
外部IP
连接到
服务
。您可以通过连接到
服务

  • 使用
    节点端口
    $minikube服务xyz
    正在使用它)
  • 使用
    $minikube隧道
    (这将“分配”
    外部IP
  • Virtualbox
    特定:
    • 使用
      metallb
      ()从仅主机网络适配器与
      minikube
      一起使用的子网中分配
      负载平衡器的范围

本问题中存在的问题 问题中出现的问题与
服务
.spec.selector
部署
.spec.selector.matchLabels
之间的不匹配有关

检查
选择器
配置是否正确(除了查看
YAML
清单外)的最简单方法是:

  • $kubectl获取端点
NAME端点年龄
库伯内特斯公元前44328米

nginx-->10.32.0.13:80发布此答案,以提供有关两个主题的更多参考:

  • Kubernetes服务无法获取外部IP
  • 本问题中存在的问题

Kubernetes服务无法获取外部IP
负载平衡器类型的
服务

使用云提供商的负载平衡器在外部公开服务<自动创建外部负载平衡器路由到的代码>节点端口
群集IP
服务

在像
minikube
这样的Kubernetes解决方案中,您将无法获得与
负载平衡器类型的
服务相关联的开箱即用的
外部IP
。您不需要使用
外部IP
连接到
服务
。您可以通过连接到
服务

  • 使用
    节点端口
    $minikube服务xyz
    正在使用它)
  • 使用
    $minikube隧道
    (这将“分配”
    外部IP
  • Virtualbox
    特定:
    • 使用
      metallb
      ()从仅主机网络适配器与
      minikube
      一起使用的子网中分配
      负载平衡器的范围

本问题中存在的问题 问题中出现的问题与
服务
.spec.selector
部署
.spec.selector.matchLabels
之间的不匹配有关

检查
选择器
配置是否正确(除了查看
YAML
清单外)的最简单方法是:

  • $kubectl获取端点
NAME ENDPO