ubuntu – Minikube服务网址无效

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

流浪档案:

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中的容器:

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,如link所述

minikube版本:

minikube version: v0.24.1

kubectl版本:

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 VM中成功启动.我创建了pod.yml文件.

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

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

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

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时,我收到“网络错误”.

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服务almsonar –url命令时,我得到一个空响应.所以我删除了服务并使用修改后的命令创建了一个新服务.

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

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

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,

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包含localhost IP地址.

最佳答案 从我看到的,你在Ubuntu VM中执行minikube启动.默认情况下,这将尝试下载minikube ISO并启动另一个VM(VM内的VM),其中minikube将运行.

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

在任何情况下,为了完全重定向并检查服务是否正在运行,请尝试执行curl命令,如下所示:

    curl -L http://127.0.0.1:31209
点赞