我有一个 Kubernetes 单节点设置(参见 https://coreos.com/kubernetes/docs/latest/kubernetes-on-vagrant-single.html)
我有一个服务和一个创建 pod 的复制 Controller 。这些 pod 需要连接到同一服务中的其他 pod(注意:这最终是为了让 mongo 运行带有副本集(非本地主机),但这个简单的示例演示了 mongo 的问题)。
当我从任何节点连接到服务时,它将(如预期)分发到其中一个 pod。这将一直有效,直到它对自身(我所在的容器)进行负载平衡。然后连接失败。
很抱歉,我很抱歉,但我将附上我的所有文件,以便您可以看到我在这个小示例中所做的事情。
Dockerfile:
FROM ubuntu
MAINTAINER Eric H
RUN apt-get update; apt-get install netcat
EXPOSE 8080
COPY ./entry.sh /
ENTRYPOINT ["/entry.sh"]
这里是入口点
#!/bin/bash
# wait for a connection, then tell them who we are
while : ; do
echo "hello, the date=`date`; my host=`hostname`" | nc -l 8080
sleep .5
done
构建 dockerfile
docker build -t echoserver .
标记并上传到我的 k8s 集群的注册表
docker tag -f echoserver:latest 127.0.0.1:5000/echoserver:latest
docker push 127.0.0.1:5000/echoserver:latest
这是我的复制 Controller
apiVersion: v1
kind: ReplicationController
metadata:
labels:
role: echo-server
app: echo
name: echo-server-1
spec:
replicas: 3
template:
metadata:
labels:
entity: echo-server-1
role: echo-server
app: echo
spec:
containers:
-
image: 127.0.0.1:5000/echoserver:latest
name: echo-server-1
ports:
- containerPort: 8080
最后,这是我的服务
kind: Service
metadata:
labels:
app: echo
role: echo-server
name: echo-server-1
name: echo-server-1
spec:
selector:
entity: echo-server-1
role: echo-server
ports:
- port: 8080
targetPort: 8080
创建我的服务
kubectl create -f echo.service.yaml
创建我的 rc
kubectl create -f echo.controller.yaml
获取我的 POD
kubectl get po
NAME READY STATUS RESTARTS AGE
echo-server-1-jp0aj 1/1 Running 0 39m
echo-server-1-shoz0 1/1 Running 0 39m
echo-server-1-y9bv2 1/1 Running 0 39m
获取服务IP
kubectl get svc
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
echo-server-1 10.3.0.246 <none> 8080/TCP entity=echo-server-1,role=echo-server 39m
执行到其中一个 pod
kubectl exec -t -i echo-server-1-jp0aj/bin/bash
现在多次连接到该服务...它将为我提供所有 pod 的应用程序消息,但当它到达自身时,它会挂起。
root@echo-server-1-jp0aj:/# nc 10.3.0.246 8080
hello, the date=Mon Jan 11 22:02:38 UTC 2016; my host=echo-server-1-y9bv2
root@echo-server-1-jp0aj:/# nc 10.3.0.246 8080
^C
root@echo-server-1-jp0aj:/# nc 10.3.0.246 8080
hello, the date=Mon Jan 11 22:02:43 UTC 2016; my host=echo-server-1-shoz0
root@echo-server-1-jp0aj:/# nc 10.3.0.246 8080
^C
root@echo-server-1-jp0aj:/# nc 10.3.0.246 8080
hello, the date=Mon Jan 11 22:31:19 UTC 2016; my host=echo-server-1-y9bv2
root@echo-server-1-jp0aj:/# nc 10.3.0.246 8080
hello, the date=Mon Jan 11 22:31:23 UTC 2016; my host=echo-server-1-shoz0
root@echo-server-1-jp0aj:/# nc 10.3.0.246 8080
hello, the date=Mon Jan 11 22:31:26 UTC 2016; my host=echo-server-1-y9bv2
root@echo-server-1-jp0aj:/# nc 10.3.0.246 8080
hello, the date=Mon Jan 11 22:31:27 UTC 2016; my host=echo-server-1-shoz0
root@echo-server-1-jp0aj:/# nc 10.3.0.246 8080
我该如何配置,以便服务的所有成员都可以连接到所有其他成员,包括它自己?
最佳答案
感谢所有在 GitHub 上提供帮助的人。
解决方法结果如下:
tanen01 commented on Feb 4 Seeing the same problem here on k8s v1.1.7 stable
Issue occurs with:
kube-proxy --proxy-mode=iptables
Once I changed it to:
--proxy-mode=userspace
(also the default), then it works again.
所以,如果您遇到这种情况,请尝试在启动 kube-proxy 时关闭 --proxy-mode。
关于docker - kubernetes pod 无法(通过服务)连接到自己,只能连接到其他 pod 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34732597/
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在使用puppet为ruby程序提供一组常量。我需要提供一组主机名,我的程序将对其进行迭代。在我之前使用的bash脚本中,我只是将它作为一个puppet变量hosts=>"host1,host2"我将其提供给bash脚本作为HOSTS=显然这对ruby不太适用——我需要它的格式hosts=["host1","host2"]自从phosts和putsmy_array.inspect提供输出["host1","host2"]我希望使用其中之一。不幸的是,我终其一生都无法弄清楚如何让它发挥作用。我尝试了以下各项:我发现某处他们指出我需要在函数调用前放置“function_”……这
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳