Minikube 服务 URL 不起作用 [英] Minikube service URL not working

查看:116
本文介绍了Minikube 服务 URL 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Kubernetes 的新手,我正在学习.我有安装 Vagrant 的 Windows 8 机器.使用 vagrant 我正在运行 ubuntu VM,在该 VM 中我正在运行 3 个 docker 容器.

I'm new to Kubernetes and I'm learning. I have my Windows 8 machine where I installed Vagrant. Using vagrant I'm running ubuntu VM and inside that VM I'm running 3 docker containers.

流浪文件:

Vagrant.configure(2) do |config|
  config.vm.box = "test"
  config.vm.network "public_network"
  config.vm.network "forwarded_port", guest: 8080, host: 8080
  config.vm.network "forwarded_port", guest: 50000, host: 50000
  config.vm.network "forwarded_port", guest: 8081, host: 8089
  config.vm.network "forwarded_port", guest: 9000, host: 9000
  config.vm.network "forwarded_port", guest: 3306, host: 3306
    config.vm.provider "virtualbox" do |v|
        v.memory = 2048
        v.cpus = 2
    end
    config.vm.provider "virtualbox" do |v|
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
end

Ubuntu VM 中的容器:

Container in Ubuntu VM :

root@vagrant-ubuntu-trusty:~/docker-containers# docker images
REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE
dockercontainers_jenkins                               latest              bb1142706601        4 days ago          1.03GB
dockercontainers_sonar                                 latest              3f021a73750c        4 days ago          1.61GB
dockercontainers_nexus                                 latest              ddc31d7ad052        4 days ago          1.06GB
jenkins/jenkins                                        lts                 279f21046a63        4 days ago          813MB
openjdk                                                8                   7c57090325cc        5 weeks ago         737MB

现在我在同一个 VM 中安装了 minikube 和 kubectl,如本链接

In same VM now I installed minikube and kubectl as mentioned in this link

minikube 版本:

minikube version:

minikube version: v0.24.1

kubectl 版本:

kubectl version:

Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.1", GitCommit:"3a1c9449a956b6026f075fa3134ff92f7d55f812", GitTreeState:"clean", BuildDate:"2018-01-04T11:52:23Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0", GitCommit:"0b9efaeb34a2fc51ff8e4d34ad9bc6375459c4a4", GitTreeState:"clean", BuildDate:"2017-11-29T22:43:34Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"linux/amd64"}

Minikube 在我的 ubuntu 虚拟机中成功启动.我已经创建了 pod.yml 文件.

Minikube successfully started in my ubuntu VM. I have created pod.yml file.

apiVersion: v1
kind: Pod
metadata:
  name: testsonaralm
  labels:
    app: sonar_alm
spec:
  containers:
  - name: alm-sonar
    image: dockercontainers_sonar:latest
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 9000

使用这个 yml 文件,我在 minikube 中创建了一个 pod

Using this yml file, I created a pod in minikube

root@vagrant-ubuntu-trusty:~/docker-containers# kubectl create -f test_pod.yml
pod "testsonaralm" created

现在我使用 kubectl 命令创建了一个服务.

Now I created a service using kubectl command.

root@vagrant-ubuntu-trusty:~/docker-containers# kubectl expose pod testsonaralm --port=9000 --target-port=9000 --name almsonar
service "almsonar" exposed

root@vagrant-ubuntu-trusty:~/docker-containers# kubectl get service
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
almsonar     ClusterIP   10.102.86.193   <none>        9000/TCP   10s
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP    3d

当我尝试从我的主机访问 URL 时,我收到网络错误".

When I tried to access the URL from my Host machine, I'm getting "Network Error".

root@vagrant-ubuntu-trusty:~/docker-containers# kubectl describe svc almsonar
Name:              almsonar
Namespace:         default
Labels:            app=sonar_alm
Annotations:       <none>
Selector:          app=sonar_alm
Type:              ClusterIP
IP:                10.101.237.223
Port:              <unset>  9000/TCP
TargetPort:        9000/TCP
Endpoints:         172.17.0.1:9000
Session Affinity:  None
Events:            <none>
root@vagrant-ubuntu-trusty:~/docker-containers# minikube ip
127.0.0.1

当我执行 minikube service almsonar --url 命令时,我得到一个 Empty 响应.所以我删除了该服务并使用修改后的命令创建了一个新服务.

When I execute the minikube service almsonar --url command, I get an Empty response. So I deleted the service and created a new service with modified command.

root@vagrant-ubuntu-trusty:~/docker-containers# kubectl expose pod testsonaralm --type=NodePort --name almsonar
service "almsonar" exposed

现在当我运行 minikube service almsonar --url 命令时,我得到一个 URL 为

Now when I run minikube service almsonar --url command,I got an URL as

root@vagrant-ubuntu-trusty:~/docker-containers# minikube service almsonar --url
http://127.0.0.1:31209

root@vagrant-ubuntu-trusty:~/docker-containers# kubectl describe svc almsonar
Name:                     almsonar
Namespace:                default
Labels:                   app=sonar_alm
Annotations:              <none>
Selector:                 app=sonar_alm
Type:                     NodePort
IP:                       10.101.192.1
Port:                     <unset>  9000/TCP
TargetPort:               9000/TCP
NodePort:                 <unset>  30600/TCP
Endpoints:                172.17.0.1:9000
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
root@vagrant-ubuntu-trusty:~/docker-containers# minikube ip
127.0.0.1

我无法在我的 Ubuntu VM 中访问此 URL,

I'm unable to access this URL in my Ubuntu VM,

root@vagrant-ubuntu-trusty:~/docker-containers# curl http://127.0.0.1:31209
<HTML>
<HEAD><TITLE>Redirection</TITLE></HEAD>
<BODY><H1>Redirect</H1></BODY>

当我阅读 Kubernetes 文档时,minikube 服务 URL 将有一个有效的 IP.但就我而言,URL 包含本地主机 IP 地址.

When I read the Kubernetes document, the minikube service URL will have a vaild IP. But in my case URL contains localhost IP address.

推荐答案

据我所知,您在 Ubuntu VM 中执行了 minikube start.默认情况下,这将尝试下载 minikube ISO 并启动另一个运行 minikube 的 VM(VM 内的 VM).

From what I see, you executed minikube start inside the Ubuntu VM. By default, this would try to download the minikube ISO and launch another VM (VM inside a VM) where minikube would be running.

我认为这种嵌套的虚拟化会导致您的安装出现问题.如果由于某种原因,minikube 以 --vm-driver=none 开头来避开 VM 内部的 VM(我认为是这种情况,看看 127.0.0.1 UP),有一些处于测试阶段的功能(在撰写此答案时),这可以解释奇怪的行为.因此,我的第一个建议是在 Windows 主机内执行 minikube,以便它在 virtualbox 内启动一个 VM.在内部,您可以重现之前拥有的容器环境,并从 Windows 主机执行 kubectl 命令.大多数文档都假设这种设置,因此您不会在 localhost 中看到 127.0.0.1 之类的差异.

I think that this nested virtualization is causing issues with your installation. If, for some reason, minikube started with --vm-driver=none to avoid the VM inside the VM (I think this is the case, looking at the 127.0.0.1 UP), there are some features that are in beta (by the time this answer was written), which could explain the weird behaviour. Because of this, my first advice would be to execute minikube inside the Windows host so it spins up a VM inside virtualbox. Inside you could reproduce the container environment you previously had, and execute the kubectl commands from the Windows host. Most of the documentation assume this setup, so you would not see differences like 127.0.0.1 in localhost.

无论如何,为了进行完全重定向并检查服务是否正在运行,请尝试像这样执行 curl 命令:

In any case, in order to have full redirection and check if the service is running, try executing the curl command like this:

    curl -L http://127.0.0.1:31209

这篇关于Minikube 服务 URL 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆