较新版本的Minikube不允许Pods使用其自己的服务 [英] Newer versions of Minikube don't allow Pods to use their own Services
问题描述
我有一个Pod,有时需要用它自己的主机名来称呼自己.我设置了一个部署,最终创建了Pod,并准备了一个服务.我可以使用群集中其他Pod上的服务名称,但是Pod无法使用其主机名来调用自身.这适用于带有Kubernetes 1.5.3版的Minikube v0.17.1,但是升级Minikube或Kubernetes版本似乎会破坏事情.这也适用于我们的Kubernetes部署/服务器版本.
I have a Pod that occasionally needs to call itself by its own host-name. I have a Deployment set up that ultimately creates the Pod, and a Service in place. I'm able to use the service name from a different Pod within my cluster, but the Pod cannot call itself using its host-name. This is something that works with Minikube v0.17.1 with Kubernetes version 1.5.3, but upgrading either Minikube or the Kubernetes version seems to break things. This also works on our deployed / server version of Kubernetes.
在Pod/服务设置中我需要考虑一些更改吗?我该如何克服呢?
Did something change that I need to take account of in my Pod / Service setup? How do I go about getting past this?
运行Minikube版本0.17.1:
Running Minikube version 0.17.1:
启动Minikube:
Start Minikube:
$ minikube start
Starting local Kubernetes cluster...
Starting VM...
SSH-ing files into VM...
Setting up certs...
Starting cluster components...
Connecting to cluster...
Setting up kubeconfig...
Kubectl is now configured to use the cluster.
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"08e099554f3c31f6e6f07b448ab3ed78d0520507", GitTreeState:"clean", BuildDate:"2017-01-12T04:57:25Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.3", GitCommit:"029c3a408176b55c30846f0faedf56aae5992e9b", GitTreeState:"clean", BuildDate:"1970-01-01T00:00:00Z", GoVersion:"go1.7.3", Compiler:"gc", Platform:"linux/amd64"}
$ minikube version
minikube version: v0.17.1
部署最少的测试映像(下面的Yaml定义):
Deploy minimal test images (yaml definition below):
kubectl apply -f deploy_python.yaml
执行进入python2映像,并验证与python映像的连接:
Exec into the python2 image, and verify connection to python image:
$ kubectl exec -it python2-1281934109-k015g bash
root@python2-1281934109-k015g:/# curl python:12345 --connect-timeout 10
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /</title>
</head>
<body>
<h1>Directory listing for /</h1>
<hr>
<ul>
<li><a href=".dockerenv">.dockerenv</a></li>
<li><a href="bin/">bin/</a></li>
<li><a href="boot/">boot/</a></li>
<li><a href="dev/">dev/</a></li>
<li><a href="etc/">etc/</a></li>
<li><a href="home/">home/</a></li>
<li><a href="lib/">lib/</a></li>
<li><a href="lib64/">lib64/</a></li>
<li><a href="media/">media/</a></li>
<li><a href="mnt/">mnt/</a></li>
<li><a href="opt/">opt/</a></li>
<li><a href="proc/">proc/</a></li>
<li><a href="root/">root/</a></li>
<li><a href="run/">run/</a></li>
<li><a href="sbin/">sbin/</a></li>
<li><a href="srv/">srv/</a></li>
<li><a href="sys/">sys/</a></li>
<li><a href="tmp/">tmp/</a></li>
<li><a href="usr/">usr/</a></li>
<li><a href="var/">var/</a></li>
</ul>
<hr>
</body>
</html>
执行进入python映像并验证与自身的连接:
Exec into python image and verify connection to self:
$ kubectl exec -it python-2555691705-5j0f9 bash
root@python-2555691705-5j0f9:/# curl python:12345 --connect-timeout 10
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /</title>
</head>
<body>
<h1>Directory listing for /</h1>
<hr>
<ul>
<li><a href=".dockerenv">.dockerenv</a></li>
<li><a href="bin/">bin/</a></li>
<li><a href="boot/">boot/</a></li>
<li><a href="dev/">dev/</a></li>
<li><a href="etc/">etc/</a></li>
<li><a href="home/">home/</a></li>
<li><a href="lib/">lib/</a></li>
<li><a href="lib64/">lib64/</a></li>
<li><a href="media/">media/</a></li>
<li><a href="mnt/">mnt/</a></li>
<li><a href="opt/">opt/</a></li>
<li><a href="proc/">proc/</a></li>
<li><a href="root/">root/</a></li>
<li><a href="run/">run/</a></li>
<li><a href="sbin/">sbin/</a></li>
<li><a href="srv/">srv/</a></li>
<li><a href="sys/">sys/</a></li>
<li><a href="tmp/">tmp/</a></li>
<li><a href="usr/">usr/</a></li>
<li><a href="var/">var/</a></li>
</ul>
<hr>
</body>
</html>
那是成功的.通过创建部署和服务,我可以从集群中的任何其他Pod向所引用的Pod发出请求.
That's a success. By creating a Deployment and a Service, I'm able to make requests to the referenced Pod from any other Pod in the cluster.
(停止并删除正在运行的Minikube.)
启动Minikube,指定Kubernetes版本1.7.0:
(Stop and delete running Minikube.)
Start Minikube, specifying Kubernetes version 1.7.0:
$ minikube start --kubernetes-version=v1.7.0
Starting local Kubernetes cluster...
Starting VM...
SSH-ing files into VM...
Downloading localkube binary
137.48 MB / 137.48 MB [============================================] 100.00% 0s
Setting up certs...
Starting cluster components...
Connecting to cluster...
Setting up kubeconfig...
Kubectl is now configured to use the cluster.
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"08e099554f3c31f6e6f07b448ab3ed78d0520507", GitTreeState:"clean", BuildDate:"2017-01-12T04:57:25Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"7", GitVersion:"v1.7.0", GitCommit:"d3ada0119e776222f11ec7945e6d860061339aad", GitTreeState:"clean", BuildDate:"2017-06-30T10:17:58Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
部署最少的测试映像(下面的Yaml定义):
Deploy minimal test images (yaml definition below):
$ kubectl apply -f deploy_python.yaml
service "python" created
deployment "python" created
deployment "python2" created
执行进入python 2映像,并验证与python映像的连接:
Exec into python 2 image, and verify connection to python image:
$ kubectl exec -it python2-380393367-ztgkq bash
root@python2-380393367-ztgkq:/# curl python:12345 --connect-timeout 10
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /</title>
</head>
<body>
<h1>Directory listing for /</h1>
<hr>
<ul>
<li><a href=".dockerenv">.dockerenv</a></li>
<li><a href="bin/">bin/</a></li>
<li><a href="boot/">boot/</a></li>
<li><a href="dev/">dev/</a></li>
<li><a href="etc/">etc/</a></li>
<li><a href="home/">home/</a></li>
<li><a href="lib/">lib/</a></li>
<li><a href="lib64/">lib64/</a></li>
<li><a href="media/">media/</a></li>
<li><a href="mnt/">mnt/</a></li>
<li><a href="opt/">opt/</a></li>
<li><a href="proc/">proc/</a></li>
<li><a href="root/">root/</a></li>
<li><a href="run/">run/</a></li>
<li><a href="sbin/">sbin/</a></li>
<li><a href="srv/">srv/</a></li>
<li><a href="sys/">sys/</a></li>
<li><a href="tmp/">tmp/</a></li>
<li><a href="usr/">usr/</a></li>
<li><a href="var/">var/</a></li>
</ul>
<hr>
</body>
</html>
执行进入python映像并尝试连接到自身:
Exec into python image and attempt connection to self:
$ kubectl exec -it python-2168884431-gls2j bash
root@python-2168884431-gls2j:/# curl python:12345 --connect-timeout 10
curl: (28) Connection timed out after 10000 milliseconds
Yaml文件,deploy_python.yaml:
Yaml file, deploy_python.yaml:
---
apiVersion: v1
kind: Service
metadata:
name: python
spec:
selector:
app: python
ports:
- port: 12345
targetPort: 12345
name: http
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: python
labels:
app: python
spec:
replicas: 1
template:
metadata:
labels:
app: python
spec:
containers:
- image: python
name: python
command: ["python"]
args: ["-m", "http.server", "12345" ]
ports:
- containerPort: 12345
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: python2
labels:
app: python2
spec:
replicas: 1
template:
metadata:
labels:
app: python2
spec:
containers:
- image: python
name: python2
command: ["python"]
args: ["-m", "http.server", "12345" ]
ports:
- containerPort: 12345
推荐答案
这是kubernetes/minikube较新版本中的一个已知错误,正在此处进行跟踪:
This is a known bug in newer versions of kubernetes / minikube and is being tracked here:
https://github.com/kubernetes/kubernetes/issues/20475
当前接受的解决方法( https://github.com/kubernetes/kubernetes/issues/20475#issuecomment-190995739 )将ssh插入您的minikube虚拟机并运行特定的ip链接命令.
The current accepted workaround (https://github.com/kubernetes/kubernetes/issues/20475#issuecomment-190995739) is to ssh into your minikube vm and run a specific ip link command.
minikube ssh
sudo ip link set docker0 promisc on
我已经测试了此变通办法,它似乎很适合我.
I have tested this workaround and it seems to work for me.
这篇关于较新版本的Minikube不允许Pods使用其自己的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!